add internal logging for package gtrace

This commit is contained in:
John Guo
2021-12-10 23:26:53 +08:00
parent e10ba4cf67
commit 34e7913268
3 changed files with 7 additions and 2 deletions

View File

@ -51,7 +51,8 @@ func MiddlewareTracing(c *Client, r *http.Request) (response *Response, err erro
var (
ctx = r.Context()
)
// Mark this request is handled by server tracing middleware.
// Mark this request is handled by server tracing middleware,
// to avoid repeated handling by the same middleware.
if ctx.Value(tracingMiddlewareHandled) != nil {
return c.Next(r)
}

View File

@ -43,7 +43,8 @@ func MiddlewareServerTracing(r *Request) {
var (
ctx = r.Context()
)
// Mark this request is handled by server tracing middleware.
// Mark this request is handled by server tracing middleware,
// to avoid repeated handling by the same middleware.
if ctx.Value(tracingMiddlewareHandled) != nil {
r.Middleware.Next()
return

View File

@ -12,6 +12,7 @@ import (
"os"
"strings"
"github.com/gogf/gf/v2/internal/intlog"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
@ -54,11 +55,13 @@ func init() {
tracingMaxContentLogSize = maxContentLogSize
}
CheckSetDefaultTextMapPropagator()
intlog.Printf(context.TODO(), `traceEnabled initialized as: %v`, traceEnabled)
}
// SetEnabled enables or disables the tracing feature.
func SetEnabled(enabled bool) {
traceEnabled = enabled
intlog.Printf(context.TODO(), `traceEnabled SetEnabled: %v`, enabled)
}
// IsEnabled checks and returns if tracing feature is configured enabled.