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

Custom Metric Attributes #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rassmate
Copy link

@rassmate rassmate commented May 6, 2024

If applied, plugins can use the LabelExtractor to get the Labeler from the context and use the returned Labeler to add custom metric labels to the server and client metrics generated.

With this in place, a server plugin could easily add custom metrics to the standard ones to customize the metrics. We could for example write a simple plugin that decodes a JWT Bearer Token and adds a claim value to the server and client metrics.

The auth validator could then with some small adjustments allow for this to be configured since it already reads the JWT and the claims.

rassmate added 2 commits May 6, 2024 12:23
If applied, plugins can use the LabelExtractor to get the Labeler from the context and use the returned Labeler to add custom metric labels to the server and client metrics generated.
1. removed unused variable
2. refactoring test method to reduce complexity
Copy link
Contributor

@dhontecillas dhontecillas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need to think about this. For now, it looks it serves a very specific use case, but, in order to be flexible for other situations, we might need a different approach.

semconv.HTTPRequestMethodKey.String(r.Method),
semconv.HTTPResponseStatusCode(t.responseStatus),
append(
otelhttp.CustomMetricAttributes(r),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the problem of having the custom attributes in the contexts is that you cannot select to what layer you want them to be applied.

So, if you set one key=val at the http.server.* global layer, that attribute will be set in each other layer, in to the backend. Or the other way around, since you report the metric once the request is alredy served, if you set an attribute with a plugin at the http.client.* backend layer, it would be set up to the http.sever.* .

Also, you could set the var in a plugin that is executed only in one of the backends, when some other request is already made, so one backend would have the attribute, and another one not.

I am not sure, if we want a way to "extend the labels", we should go with this approach.

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

Successfully merging this pull request may close these issues.

2 participants