tracing baggage

This commit is contained in:
jianchenma
2021-01-28 13:51:23 +08:00
parent 2451b40d3e
commit 2734903886
3 changed files with 5 additions and 0 deletions

View File

@ -26,6 +26,7 @@ const (
tracingMaxContentLogSize = 512 * 1024 // Max log size for request and response body.
tracingEventHttpRequest = "http.request"
tracingEventHttpRequestHeaders = "http.request.headers"
tracingEventHttpRequestBaggage = "http.request.baggage"
tracingEventHttpRequestBody = "http.request.body"
tracingEventHttpResponse = "http.response"
tracingEventHttpResponseHeaders = "http.response.headers"
@ -71,6 +72,7 @@ func MiddlewareServerTracing(r *Request) {
}
span.AddEvent(tracingEventHttpRequest, trace.WithAttributes(
label.Any(tracingEventHttpRequestHeaders, httputil.HeaderToMap(r.Header)),
label.Any(tracingEventHttpRequestBaggage, gtrace.GetBaggageMap(ctx).Map()),
label.String(tracingEventHttpRequestBody, reqBodyContent),
))

View File

@ -32,6 +32,7 @@ const (
tracingAttrHttpConnectDone = "http.connect.done"
tracingEventHttpRequest = "http.request"
tracingEventHttpRequestHeaders = "http.request.headers"
tracingEventHttpRequestBaggage = "http.request.baggage"
tracingEventHttpRequestBody = "http.request.body"
tracingEventHttpResponse = "http.response"
tracingEventHttpResponseHeaders = "http.response.headers"

View File

@ -11,6 +11,7 @@ import (
"crypto/tls"
"fmt"
"github.com/gogf/gf/internal/utils"
"github.com/gogf/gf/net/gtrace"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/trace"
@ -154,6 +155,7 @@ func (ct *clientTracer) wroteRequest(info httptrace.WroteRequestInfo) {
}
ct.span.AddEvent(tracingEventHttpRequest, trace.WithAttributes(
label.Any(tracingEventHttpRequestHeaders, ct.headers),
label.Any(tracingEventHttpRequestBaggage, gtrace.GetBaggageMap(ct.Context).Map()),
label.String(tracingEventHttpRequestBody, bodyContent),
))
}