fix(middleware/tracing): check attribute types before setting them

Co-authored-by: sindrerh2 <sindre.rodseth.hansen@nav.no>
This commit is contained in:
Trong Huu Nguyen
2025-01-29 09:24:21 +01:00
parent 1ed1b611af
commit 05c5da6bf6

View File

@@ -19,7 +19,12 @@ func Tracing(next http.Handler) http.Handler {
attrs := httpinternal.Attributes(r)
for k, v := range attrs {
attrKey := "wonderwall." + k
span.SetAttributes(attribute.String(attrKey, fmt.Sprint(v)))
switch v := v.(type) {
case bool:
span.SetAttributes(attribute.Bool(attrKey, v))
default:
span.SetAttributes(attribute.String(attrKey, fmt.Sprint(v)))
}
}
// Override request ID with trace ID if available.