generated from TrueCloudLab/basic
26 lines
663 B
Go
26 lines
663 B
Go
package http
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-platform/tracing"
|
|
"github.com/valyala/fasthttp"
|
|
"go.opentelemetry.io/otel/codes"
|
|
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
// SetTraceInfoToResponse saves trace headers to response.
|
|
func SetTraceInfoToResponse(ctx context.Context, span trace.Span, req *fasthttp.RequestCtx) {
|
|
if req == nil {
|
|
return
|
|
}
|
|
if err := req.Err(); err != nil {
|
|
span.SetStatus(codes.Error, err.Error())
|
|
}
|
|
span.SetAttributes(
|
|
semconv.HTTPStatusCode(req.Response.StatusCode()),
|
|
)
|
|
carrier := &httpCarrier{r: req}
|
|
tracing.Propagator.Inject(ctx, carrier)
|
|
}
|