frostfs-observability/tracing/http/response.go
Dmitrii Stepanov 7b123d020c [#2] tracing: Add HTTP tracing module
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-05-29 12:00:29 +03:00

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