improve trace span generating for package gctx and http tracing content for package ghttp (#2937)

This commit is contained in:
will0306
2023-09-11 02:14:00 +00:00
committed by GitHub
parent 7e16d9b63e
commit 7391a4d45a

View File

@ -36,6 +36,7 @@ const (
tracingEventHttpResponse = "http.response"
tracingEventHttpResponseHeaders = "http.response.headers"
tracingEventHttpResponseBody = "http.response.body"
tracingEventHttpRequestUrl = "http.request.url"
tracingMiddlewareHandled gctx.StrKey = `MiddlewareServerTracingHandled`
)
@ -64,7 +65,7 @@ func internalMiddlewareServerTracing(r *Request) {
ctx,
propagation.HeaderCarrier(r.Header),
),
r.URL.String(),
r.URL.Path,
trace.WithSpanKind(trace.SpanKindServer),
)
defer span.End()
@ -90,6 +91,7 @@ func internalMiddlewareServerTracing(r *Request) {
r.Body = utils.NewReadCloser(reqBodyContentBytes, false)
span.AddEvent(tracingEventHttpRequest, trace.WithAttributes(
attribute.String(tracingEventHttpRequestUrl, r.URL.String()),
attribute.String(tracingEventHttpRequestHeaders, gconv.String(httputil.HeaderToMap(r.Header))),
attribute.String(tracingEventHttpRequestBaggage, gtrace.GetBaggageMap(ctx).String()),
attribute.String(tracingEventHttpRequestBody, gstr.StrLimit(