diff options
author | David Frickert <david.frickert@protonmail.com> | 2023-01-25 07:26:44 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 02:26:44 -0500 |
commit | 962310204f088a74719a48fa2dc76e76934dfa09 (patch) | |
tree | c21afae2445a95949bb81bef5335137983740965 /modules/caddyhttp/tracing/tracer.go | |
parent | 98867ac3468b33c012ae75a14c8d923117629dc2 (diff) |
tracing: Support placeholders in span name (#5329)
Fixes https://github.com/caddyserver/caddy/issues/5171
Diffstat (limited to 'modules/caddyhttp/tracing/tracer.go')
-rw-r--r-- | modules/caddyhttp/tracing/tracer.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/modules/caddyhttp/tracing/tracer.go b/modules/caddyhttp/tracing/tracer.go index ddb01e8..e5c5107 100644 --- a/modules/caddyhttp/tracing/tracer.go +++ b/modules/caddyhttp/tracing/tracer.go @@ -69,7 +69,13 @@ func newOpenTelemetryWrapper( sdktrace.WithResource(res), ) - ot.handler = otelhttp.NewHandler(http.HandlerFunc(ot.serveHTTP), ot.spanName, otelhttp.WithTracerProvider(tracerProvider), otelhttp.WithPropagators(ot.propagators)) + ot.handler = otelhttp.NewHandler(http.HandlerFunc(ot.serveHTTP), + ot.spanName, + otelhttp.WithTracerProvider(tracerProvider), + otelhttp.WithPropagators(ot.propagators), + otelhttp.WithSpanNameFormatter(ot.spanNameFormatter), + ) + return ot, nil } @@ -106,3 +112,8 @@ func (ot *openTelemetryWrapper) newResource( semconv.WebEngineVersionKey.String(webEngineVersion), )) } + +// spanNameFormatter performs the replacement of placeholders in the span name +func (ot *openTelemetryWrapper) spanNameFormatter(operation string, r *http.Request) string { + return r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer).ReplaceAll(operation, "") +} |