mirror of
https://github.com/gomods/athens
synced 2026-02-03 09:50:31 +00:00
Save http status in the outermost span (#694)
* Save http status in the outermost span Co-authored-by: Federico Paolinelli <fedepaol@gmail.com> * Use ochttp to use span status and store http status code as a tag * Make the conditional oneliner
This commit is contained in:
committed by
Marwan Sulaiman
parent
83281a80fb
commit
2c3d72d52e
+11
-1
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/gobuffalo/buffalo"
|
||||
"github.com/gomods/athens/pkg/errors"
|
||||
"go.opencensus.io/exporter/jaeger"
|
||||
"go.opencensus.io/plugin/ochttp"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
@@ -61,11 +62,20 @@ func Tracer(service string) buffalo.MiddlewareFunc {
|
||||
trace.WithSpanKind(trace.SpanKindClient))
|
||||
defer span.End()
|
||||
|
||||
handler := next(&observabilityContext{Context: ctx, spanCtx: spanCtx})
|
||||
|
||||
// Add request attributes
|
||||
span.AddAttributes(
|
||||
requestAttrs(ctx.Request())...,
|
||||
)
|
||||
|
||||
return next(&observabilityContext{Context: ctx, spanCtx: spanCtx})
|
||||
// SetSpan Status from response
|
||||
if resp, ok := ctx.Response().(*buffalo.Response); ok {
|
||||
span.SetStatus(ochttp.TraceStatus(resp.Status, ""))
|
||||
span.AddAttributes(trace.Int64Attribute("http.status_code", int64(resp.Status)))
|
||||
}
|
||||
|
||||
return handler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user