mirror of
https://gitee.com/johng/gf.git
synced 2024-12-03 04:37:49 +08:00
add common tracing labels
This commit is contained in:
parent
152c472bc2
commit
2c15aad0e7
@ -20,14 +20,14 @@ import (
|
||||
|
||||
// addSqlToTracing adds sql information to tracer if it's enabled.
|
||||
func (c *Core) addSqlToTracing(ctx context.Context, sql *Sql) {
|
||||
if gtrace.IsActivated(ctx) {
|
||||
if !gtrace.IsActivated(ctx) {
|
||||
return
|
||||
}
|
||||
tr := otel.GetTracerProvider().Tracer(
|
||||
"github.com/gogf/gf/database/gdb",
|
||||
trace.WithInstrumentationVersion(fmt.Sprintf(`%s`, gf.VERSION)),
|
||||
)
|
||||
ctx, span := tr.Start(ctx, sql.Type)
|
||||
ctx, span := tr.Start(ctx, sql.Type, trace.WithSpanKind(trace.SpanKindInternal))
|
||||
defer span.End()
|
||||
|
||||
if sql.Error != nil {
|
||||
|
@ -66,7 +66,7 @@ func (c *Conn) do(timeout time.Duration, commandName string, args ...interface{}
|
||||
timestampMilli2 := gtime.TimestampMilli()
|
||||
|
||||
// Tracing.
|
||||
if gtrace.IsActivated(c.ctx) {
|
||||
if !gtrace.IsActivated(c.ctx) {
|
||||
return
|
||||
}
|
||||
tr := otel.GetTracerProvider().Tracer(
|
||||
@ -77,7 +77,7 @@ func (c *Conn) do(timeout time.Duration, commandName string, args ...interface{}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
_, span := tr.Start(ctx, "Redis."+commandName)
|
||||
_, span := tr.Start(ctx, "Redis."+commandName, trace.WithSpanKind(trace.SpanKindInternal))
|
||||
defer span.End()
|
||||
if err != nil {
|
||||
span.SetStatus(codes.Error, fmt.Sprintf(`%+v`, err))
|
||||
|
@ -43,7 +43,7 @@ func MiddlewareServerTracing(r *Request) {
|
||||
propagation.Baggage{},
|
||||
)
|
||||
ctx := propagator.Extract(r.Context(), r.Header)
|
||||
ctx, span := tr.Start(ctx, r.URL.String())
|
||||
ctx, span := tr.Start(ctx, r.URL.String(), trace.WithSpanKind(trace.SpanKindServer))
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(gtrace.CommonLabels()...)
|
||||
@ -59,7 +59,7 @@ func MiddlewareServerTracing(r *Request) {
|
||||
reqBodyContent = string(reqBodyContentBytes)
|
||||
} else {
|
||||
reqBodyContent = fmt.Sprintf(
|
||||
"[Request Body Too Large For Logging, Max: %d bytes]",
|
||||
"[Request Body Too Large For Tracing, Max: %d bytes]",
|
||||
tracingMaxContentLogSize,
|
||||
)
|
||||
}
|
||||
@ -80,7 +80,10 @@ func MiddlewareServerTracing(r *Request) {
|
||||
if r.Response.BufferLength() <= tracingMaxContentLogSize {
|
||||
resBodyContent = r.Response.BufferString()
|
||||
} else {
|
||||
resBodyContent = fmt.Sprintf("[Response Body Too Large For Logging, Max: %d bytes]", tracingMaxContentLogSize)
|
||||
resBodyContent = fmt.Sprintf(
|
||||
"[Response Body Too Large For Tracing, Max: %d bytes]",
|
||||
tracingMaxContentLogSize,
|
||||
)
|
||||
}
|
||||
span.AddEvent("http.response", trace.WithAttributes(
|
||||
label.Any(`http.response.headers`, httputil.HeaderToMap(r.Response.Header())),
|
||||
|
@ -32,7 +32,7 @@ func MiddlewareTracing(c *Client, r *http.Request) (response *Response, err erro
|
||||
"github.com/gogf/gf/net/ghttp.Client",
|
||||
trace.WithInstrumentationVersion(fmt.Sprintf(`%s`, gf.VERSION)),
|
||||
)
|
||||
ctx, span := tr.Start(r.Context(), r.URL.String())
|
||||
ctx, span := tr.Start(r.Context(), r.URL.String(), trace.WithSpanKind(trace.SpanKindClient))
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(gtrace.CommonLabels()...)
|
||||
@ -64,7 +64,10 @@ func MiddlewareTracing(c *Client, r *http.Request) (response *Response, err erro
|
||||
resBodyContent = string(reqBodyContentBytes)
|
||||
response.Body = utils.NewReadCloser(reqBodyContentBytes, false)
|
||||
} else {
|
||||
resBodyContent = fmt.Sprintf("[Response Body Too Large For Logging, Max: %d bytes]", tracingMaxContentLogSize)
|
||||
resBodyContent = fmt.Sprintf(
|
||||
"[Response Body Too Large For Tracing, Max: %d bytes]",
|
||||
tracingMaxContentLogSize,
|
||||
)
|
||||
}
|
||||
|
||||
span.AddEvent("http.response", trace.WithAttributes(
|
||||
|
Loading…
Reference in New Issue
Block a user