Skip to content

Commit

Permalink
Merge pull request #232 from simonswine/20211104_add-user-agent-to-span
Browse files Browse the repository at this point in the history
Add a tag with the user-agent to traces
  • Loading branch information
bboreham authored Nov 9, 2021
2 parents d2e57b1 + b92d9aa commit a3bc5dd
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions middleware/http_tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ func (t Tracer) Wrap(next http.Handler) http.Handler {

return fmt.Sprintf("HTTP %s - %s", r.Method, op)
}),
}
if t.SourceIPs != nil {
options = append(options, nethttp.MWSpanObserver(func(sp opentracing.Span, r *http.Request) {
sp.SetTag("sourceIPs", t.SourceIPs.Get(r))
}))
nethttp.MWSpanObserver(func(sp opentracing.Span, r *http.Request) {
// add a tag with the client's user agent to the span
userAgent := r.Header.Get("User-Agent")
if userAgent != "" {
sp.SetTag("http.user_agent", userAgent)
}

// add a tag with the client's sourceIPs to the span, if a
// SourceIPExtractor is given.
if t.SourceIPs != nil {
sp.SetTag("sourceIPs", t.SourceIPs.Get(r))
}
}),
}

return nethttp.Middleware(opentracing.GlobalTracer(), next, options...)
Expand Down

0 comments on commit a3bc5dd

Please sign in to comment.