-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Trace Response Handler To Server
Signed-off-by: Mahad Zaryab <[email protected]>
- Loading branch information
1 parent
946bdbc
commit 2a686c0
Showing
3 changed files
with
26 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package app | ||
|
||
import ( | ||
"net/http" | ||
|
||
"go.opentelemetry.io/otel/propagation" | ||
) | ||
|
||
// Returns a handler that generates a traceresponse header. | ||
// https://github.com/w3c/trace-context/blob/main/spec/21-http_response_header_format.md | ||
func traceResponseHandler(handler http.Handler) http.Handler { | ||
// We use the standard TraceContext propagator, since the formats are identical. | ||
// But the propagator uses "traceparent" header name, so we inject it into a map | ||
// `carrier` and then use the result to set the "tracereponse" header. | ||
var prop propagation.TraceContext | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
carrier := make(map[string]string) | ||
prop.Inject(r.Context(), propagation.MapCarrier(carrier)) | ||
w.Header().Add("traceresponse", carrier["traceparent"]) | ||
handler.ServeHTTP(w, r) | ||
}) | ||
} |