Skip to content

Commit

Permalink
Add TraceId
Browse files Browse the repository at this point in the history
  • Loading branch information
c2h5oh committed Dec 5, 2024
1 parent c506cab commit 31751f4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions middleware/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ import (
var (
TracingCtxKey = &contextKey{"TracingHeaders"}
defaultTraceHeaders = []string{
"X-Cloud-Trace-Context", // GCP load balancer
"X-Amzn-Trace-Id", // AWS X-ray
"CF-ray", // Cloudflare ray id
http.CanonicalHeaderKey("X-Cloud-Trace-Context"), // GCP load balancer trace id
http.CanonicalHeaderKey("X-Amzn-Trace-Id"), // AWS X-ray
http.CanonicalHeaderKey("CF-ray"), // Cloudflare ray id
http.CanonicalHeaderKey("TraceId"), // https://github.com/go-chi/traceid
}
)

func Tracing(traceHeaders ...string) func(next http.Handler) http.Handler {
if len(traceHeaders) == 0 {
traceHeaders = defaultTraceHeaders
}

return func(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
headerValues := map[string]string{}
Expand Down

0 comments on commit 31751f4

Please sign in to comment.