mirror of
https://gitee.com/johng/gf.git
synced 2024-12-04 21:28:22 +08:00
add switch variable for internal type tracing components
This commit is contained in:
parent
a3fa10d820
commit
5adde275fc
@ -12,6 +12,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gogf/gf"
|
"github.com/gogf/gf"
|
||||||
"github.com/gogf/gf/net/gtrace"
|
"github.com/gogf/gf/net/gtrace"
|
||||||
|
"github.com/gogf/gf/os/gcmd"
|
||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
"go.opentelemetry.io/otel/label"
|
"go.opentelemetry.io/otel/label"
|
||||||
@ -33,9 +34,19 @@ const (
|
|||||||
tracingEventDbExecutionType = "db.execution.type"
|
tracingEventDbExecutionType = "db.execution.type"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// tracingInternal enables tracing for internal type spans.
|
||||||
|
// It's true in default.
|
||||||
|
tracingInternal = true
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
tracingInternal = gcmd.GetOptWithEnv("gf.tracing.internal", true).Bool()
|
||||||
|
}
|
||||||
|
|
||||||
// addSqlToTracing adds sql information to tracer if it's enabled.
|
// addSqlToTracing adds sql information to tracer if it's enabled.
|
||||||
func (c *Core) addSqlToTracing(ctx context.Context, sql *Sql) {
|
func (c *Core) addSqlToTracing(ctx context.Context, sql *Sql) {
|
||||||
if !gtrace.IsActivated(ctx) {
|
if !tracingInternal || !gtrace.IsActivated(ctx) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tr := otel.GetTracerProvider().Tracer(
|
tr := otel.GetTracerProvider().Tracer(
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"github.com/gogf/gf/container/gvar"
|
"github.com/gogf/gf/container/gvar"
|
||||||
"github.com/gogf/gf/internal/json"
|
"github.com/gogf/gf/internal/json"
|
||||||
"github.com/gogf/gf/net/gtrace"
|
|
||||||
"github.com/gogf/gf/os/gtime"
|
"github.com/gogf/gf/os/gtime"
|
||||||
"github.com/gogf/gf/util/gconv"
|
"github.com/gogf/gf/util/gconv"
|
||||||
"github.com/gomodule/redigo/redis"
|
"github.com/gomodule/redigo/redis"
|
||||||
@ -60,14 +59,12 @@ func (c *Conn) do(timeout time.Duration, commandName string, args ...interface{}
|
|||||||
timestampMilli2 := gtime.TimestampMilli()
|
timestampMilli2 := gtime.TimestampMilli()
|
||||||
|
|
||||||
// Tracing.
|
// Tracing.
|
||||||
if gtrace.IsActivated(c.ctx) {
|
|
||||||
c.addTracingItem(&tracingItem{
|
c.addTracingItem(&tracingItem{
|
||||||
err: err,
|
err: err,
|
||||||
commandName: commandName,
|
commandName: commandName,
|
||||||
arguments: args,
|
arguments: args,
|
||||||
costMilli: timestampMilli2 - timestampMilli1,
|
costMilli: timestampMilli2 - timestampMilli1,
|
||||||
})
|
})
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/gogf/gf"
|
"github.com/gogf/gf"
|
||||||
"github.com/gogf/gf/internal/json"
|
"github.com/gogf/gf/internal/json"
|
||||||
"github.com/gogf/gf/net/gtrace"
|
"github.com/gogf/gf/net/gtrace"
|
||||||
|
"github.com/gogf/gf/os/gcmd"
|
||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
"go.opentelemetry.io/otel/label"
|
"go.opentelemetry.io/otel/label"
|
||||||
@ -37,9 +38,25 @@ const (
|
|||||||
tracingEventRedisExecutionArguments = "redis.execution.arguments"
|
tracingEventRedisExecutionArguments = "redis.execution.arguments"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// tracingInternal enables tracing for internal type spans.
|
||||||
|
// It's true in default.
|
||||||
|
tracingInternal = true
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
tracingInternal = gcmd.GetOptWithEnv("gf.tracing.internal", true).Bool()
|
||||||
|
}
|
||||||
|
|
||||||
// addTracingItem checks and adds redis tracing information to OpenTelemetry.
|
// addTracingItem checks and adds redis tracing information to OpenTelemetry.
|
||||||
func (c *Conn) addTracingItem(item *tracingItem) {
|
func (c *Conn) addTracingItem(item *tracingItem) {
|
||||||
tr := otel.GetTracerProvider().Tracer(tracingInstrumentName, trace.WithInstrumentationVersion(gf.VERSION))
|
if !tracingInternal || !gtrace.IsActivated(c.ctx) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tr := otel.GetTracerProvider().Tracer(
|
||||||
|
tracingInstrumentName,
|
||||||
|
trace.WithInstrumentationVersion(gf.VERSION),
|
||||||
|
)
|
||||||
ctx := c.ctx
|
ctx := c.ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
|
Loading…
Reference in New Issue
Block a user