From 3bbfcc593e4cfbf4895b328255e4e029c1401401 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Mon, 9 Oct 2023 14:05:10 -0500 Subject: [PATCH] feat: add `request_id` to HTTP trace spans (#10145) --- coderd/httpmw/requestid.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/coderd/httpmw/requestid.go b/coderd/httpmw/requestid.go index bd232c75a4..e1014a089c 100644 --- a/coderd/httpmw/requestid.go +++ b/coderd/httpmw/requestid.go @@ -5,6 +5,8 @@ import ( "net/http" "github.com/google/uuid" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "cdr.dev/slog" ) @@ -29,6 +31,9 @@ func AttachRequestID(next http.Handler) http.Handler { ctx := context.WithValue(r.Context(), requestIDContextKey{}, rid) ctx = slog.With(ctx, slog.F("request_id", rid)) + trace.SpanFromContext(ctx). + SetAttributes(attribute.String("request_id", rid.String())) + rw.Header().Set("X-Coder-Request-Id", ridString) next.ServeHTTP(rw, r.WithContext(ctx)) })