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

fix: make possible adding custom attributes to the shipped otelhttp client metrics - #5084 #5086

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions instrumentation/net/http/otelhttp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,10 @@ func (h *middleware) serveHTTP(w http.ResponseWriter, r *http.Request, next http
},
})

labeler := &Labeler{}
ctx = injectLabeler(ctx, labeler)
labeler, found := LabelerFromContext(ctx)
if !found {
ctx = InjectLabeler(ctx, labeler)
}

next.ServeHTTP(w, r.WithContext(ctx))

Expand Down
2 changes: 1 addition & 1 deletion instrumentation/net/http/otelhttp/labeler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type labelerContextKeyType int

const lablelerContextKey labelerContextKeyType = 0

func injectLabeler(ctx context.Context, l *Labeler) context.Context {
func InjectLabeler(ctx context.Context, l *Labeler) context.Context {
Copy link
Member

Choose a reason for hiding this comment

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

Why does this need to become public?

Choose a reason for hiding this comment

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

Otherwise you cannot inject a Labeler component outside the otelhttp module.(as labelerContextKey is private as well). The given details on #5084 aren't clear enough?

return context.WithValue(ctx, lablelerContextKey, l)
}

Expand Down
6 changes: 4 additions & 2 deletions instrumentation/net/http/otelhttp/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) {
ctx = httptrace.WithClientTrace(ctx, t.clientTrace(ctx))
}

labeler := &Labeler{}
ctx = injectLabeler(ctx, labeler)
labeler, found := LabelerFromContext(ctx)
if !found {
ctx = InjectLabeler(ctx, labeler)
}

r = r.Clone(ctx) // According to RoundTripper spec, we shouldn't modify the origin request.

Expand Down