You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I am using standard java.net.http.HttpClient to send a request and my application is instrumented by OpenTelemetry Java Agent with Prometheus metrics exporter.
I can see client's metrics (e.g. request duration)
I want to add attributed with name of the customer, for whom this request was executed.
I've created custom implementation of ResourceProvider, which created a Resource with custom implementation of Attributes based on this example.
Unfortunately attributes are read only once, when the agent boots up (and MDC is empty at this point, so it does not work).
I'm pasting parts of implementation just to show what it looked like:
Another try was to follow AutoConfigurationCustomizer example and adding the attributes through SdkMeterProvider::addResource, since Resouce::merge should add all Attributes, but this is also done once during startup.
Resource is immutable and constructed when the agent starts, it can't be use that way.
The way I see it your best option is to use manual instrumentation to gather the metric you need. Another options would be to customize the existing metric. For this I guess you'd need to copy the existing jdk http client instrumentation, somehow make the value from MDC available to that instrumentation (as these are in different class loader it is going to be a bit of a challenge), add the client id attribute in http client instrumentation, modify the metrics view to somehow include that attribute etc. Imo not worth the effort.
Is your feature request related to a problem? Please describe.
I am using standard
java.net.http.HttpClient
to send a request and my application is instrumented by OpenTelemetry Java Agent with Prometheus metrics exporter.I can see client's metrics (e.g. request duration)
I want to add attributed with name of the customer, for whom this request was executed.
Current:
Desired:
In my case this value is stored in
org.slf4j.MDC
.Agent properties:
Describe the solution you'd like
Extension for metrics, which would allow a 'hook' for adding dynamic attributes.
It seems to be possible for spans
Describe alternatives you've considered
For manual instrumentation I'm using custom implementation of Metrics, here is the example of LongCounter:
I've created custom implementation of ResourceProvider, which created a
Resource
with custom implementation ofAttributes
based on this example.Unfortunately attributes are read only once, when the agent boots up (and MDC is empty at this point, so it does not work).
I'm pasting parts of implementation just to show what it looked like:
Creating resource:
MDCAttributes.fromMDC
MDCAttributes::forEach
Another try was to follow AutoConfigurationCustomizer example and adding the attributes through
SdkMeterProvider::addResource
, sinceResouce::merge
should add all Attributes, but this is also done once during startup.Additional context
I know it is also possible to Create an extension with new instrumentation which injects its own advice into the same method as the original one, but I believe such use case should be supported through the SPI.
Since the examples were implemented by @iNikem, I hope you'll know whether achieving this functionality is possible in current state of the SPI :)
Many thanks for astonishing amount of work on the Agent. The amount of data it can gather 'for free' is really mind blowing 🔥
The text was updated successfully, but these errors were encountered: