Metrics shipped with http client cannot be augmented with custom attributes #5084
Labels
area: instrumentation
Related to an instrumentation package
bug
Something isn't working
instrumentation: otelhttp
Milestone
Description
At the moment it seems there's no way to add custom attributes to the provided metrics within instrumented http client. In the current implementation the metric attributes are added through a
Labeler
component which is designed to live within context objects tree.However, looking at the current implementation I'm spotting two issues:
opentelemetry-go-contrib/instrumentation/net/http/otelhttp/transport.go
Lines 146 to 156 in ee76330
Line 151
- a new Labeler is created instead of getting from context object (in order not to lose the potential attributes previously created and carried through the context)Line 152
- theinjectLabeler
method cannot be used outside theotelhttp
module so actually this makes impossbile the adding of theLabeler
component in the high levels of context object.Environment
otelhttp
version: latestExpected behavior
This seems like an easy fix:
Labeler
viaLabelerFromContext
method:opentelemetry-go-contrib/instrumentation/net/http/otelhttp/labeler.go
Lines 55 to 65 in ee76330
injectLabeler
public to be invokable outsideotelhttp
moduleAfter the changes above will be made the following code sample it will be possible:
The text was updated successfully, but these errors were encountered: