diff --git a/coderd/tracing/util.go b/coderd/tracing/util.go index cfa7c901601c5..f65e6e784cf90 100644 --- a/coderd/tracing/util.go +++ b/coderd/tracing/util.go @@ -1,10 +1,20 @@ package tracing import ( + "context" "runtime" "strings" + + "go.opentelemetry.io/otel/trace" ) +var NoopSpan trace.Span + +func init() { + tracer := trace.NewNoopTracerProvider().Tracer("") + _, NoopSpan = tracer.Start(context.Background(), "") +} + const TracerName = "coderd" func FuncName() string { diff --git a/coderd/workspaceagents.go b/coderd/workspaceagents.go index 4fe083a8b7578..3e5c245f32398 100644 --- a/coderd/workspaceagents.go +++ b/coderd/workspaceagents.go @@ -351,8 +351,11 @@ func (api *API) workspaceAgentCoordinate(rw http.ResponseWriter, r *http.Request return } - // end span so we don't get long lived trace data + // End span so we don't get long lived trace data. tracing.EndHTTPSpan(r, http.StatusOK, trace.SpanFromContext(ctx)) + // Ignore all trace spans after this. + ctx = trace.ContextWithSpan(ctx, tracing.NoopSpan) + api.Logger.Info(ctx, "accepting agent", slog.F("resource", resource), slog.F("agent", workspaceAgent)) defer conn.Close(websocket.StatusNormalClosure, "")