Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MetricsLayer — Add additional event fields as KeyValue pairs to a recorded metric #32

Closed
jnicholls opened this issue Jul 22, 2023 · 3 comments

Comments

@jnicholls
Copy link

jnicholls commented Jul 22, 2023

Feature Request

MetricsLayer — Add additional event fields as KeyValue pairs to a recorded metric.

Motivation

MetricsLayer is a great idea, to have events be able to be captured and exported as metrics. Brilliant. But, the current implementation only submits the metric name and value, and no associated KeyValue pairs to add context to the metric.

Proposal

It would be fantastic if other fields of the event were added as associated KeyValue pairs to the metric. Or, another specially named field specifically for MetricsLayer to inspect for optional KeyValue pairs.

@jtescher
Copy link
Collaborator

jtescher commented Aug 2, 2023

@jnicholls This sounds good! are you able to submit a PR to this effect?

@ymgyt
Copy link
Contributor

ymgyt commented Aug 2, 2023

If @jnicholls doesn't mind, I'd like to try this feature.

My understanding is that in the Metric api's Counter add operation spec says

This API MUST accept the following parameter:

  • A numeric increment value.
  • Attributes to associate with the increment value.

This feature allows you to associate the attributes with the metrics.

For example

tracing::info!(
  monotonic_counter.foo = 1,
  key_1 = val_1,
  "foo",
);

would export metrics with the attributes of key_1 = val_1.

jtescher pushed a commit that referenced this issue Aug 8, 2023
## Motivation

Support #32
This change will allow user to associate Attributes with metrics from
tracing.

## Solution

1. MetricsLayer is only interested in events that contain fields with
metrics prefixes such as `counter`, so I have utilized the
[tracing_subscriber Filter
trait](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/layer/#per-layer-filtering).
2. Since it's necessary to pass Attributes when outputting Measurements,
it's required to complete the visit for all fields first before invoking
the Metrics API(`Counter:add()`).
`SmallVec` is used to hold Attribute KeyValues, Metrics names, and
Instruments for invocation, aiming to avoid allocations in typical use
cases.
@jtescher
Copy link
Collaborator

jtescher commented Aug 8, 2023

Resolved in #43

@jtescher jtescher closed this as completed Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants