Skip to content

Commit

Permalink
tracing: add http.request.header.referer (#1336)
Browse files Browse the repository at this point in the history
towards NSL-4308
  • Loading branch information
tomasz-sodzawiczny authored Oct 7, 2024
1 parent 0662d80 commit f82e1bc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion std/monitoring/tracing/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,17 @@ func Prepare(ctx context.Context, deps ExtensionDeps) error {
)

deps.Middleware.Add(func(h http.Handler) http.Handler {
return otelhttp.NewHandler(h, "",
return otelhttp.NewHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// add referer
span := t.SpanFromContext(r.Context())
if span.IsRecording() {
if referer := r.Header.Get("Referer"); referer != "" {
span.SetAttributes(attribute.String("http.request.header.referer", referer))
}
}

h.ServeHTTP(w, r)
}), "",
otelhttp.WithTracerProvider(provider),
otelhttp.WithSpanNameFormatter(func(_ string, r *http.Request) string {
return fmt.Sprintf("%s %s", r.Method, r.URL.Path)
Expand Down

0 comments on commit f82e1bc

Please sign in to comment.