frostfs-observability/tracing/http/response.go

27 lines
663 B
Go
Raw Normal View History

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)
}