mirror of https://github.com/go-redis/redis.git
tracing option to customize span name
This commit is contained in:
parent
3532f2a414
commit
095fb1c110
|
@ -12,8 +12,9 @@ import (
|
||||||
type config struct {
|
type config struct {
|
||||||
// Common options.
|
// Common options.
|
||||||
|
|
||||||
dbSystem string
|
dbSystem string
|
||||||
attrs []attribute.KeyValue
|
attrs []attribute.KeyValue
|
||||||
|
spanNameFn func(hook TracingHook, defaultName string) string
|
||||||
|
|
||||||
// Tracing options.
|
// Tracing options.
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ func WithAttributes(attrs ...attribute.KeyValue) Option {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
|
|
||||||
type TracingOption interface {
|
type TracingOption interface {
|
||||||
baseOption
|
baseOption
|
||||||
|
@ -114,7 +115,22 @@ func WithDBStatement(on bool) TracingOption {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
type TracingHook int
|
||||||
|
|
||||||
|
const (
|
||||||
|
TracingHookDial TracingHook = iota
|
||||||
|
TracingHookProcess
|
||||||
|
TracingHookProcessPipeline
|
||||||
|
)
|
||||||
|
|
||||||
|
// WithSpanName provides a function to customize the span names.
|
||||||
|
func WithSpanName(f func(hook TracingHook, defaultName string) string) TracingOption {
|
||||||
|
return tracingOption(func(conf *config) {
|
||||||
|
conf.spanNameFn = f
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------
|
||||||
|
|
||||||
type MetricsOption interface {
|
type MetricsOption interface {
|
||||||
baseOption
|
baseOption
|
||||||
|
|
|
@ -91,7 +91,12 @@ func (th *tracingHook) DialHook(hook redis.DialHook) redis.DialHook {
|
||||||
return hook(ctx, network, addr)
|
return hook(ctx, network, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, span := th.conf.tracer.Start(ctx, "redis.dial", th.spanOpts...)
|
spanName := "redis.dial"
|
||||||
|
if th.conf.spanNameFn != nil {
|
||||||
|
spanName = th.conf.spanNameFn(TracingHookDial, spanName)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, span := th.conf.tracer.Start(ctx, spanName, th.spanOpts...)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
conn, err := hook(ctx, network, addr)
|
conn, err := hook(ctx, network, addr)
|
||||||
|
@ -126,7 +131,12 @@ func (th *tracingHook) ProcessHook(hook redis.ProcessHook) redis.ProcessHook {
|
||||||
opts := th.spanOpts
|
opts := th.spanOpts
|
||||||
opts = append(opts, trace.WithAttributes(attrs...))
|
opts = append(opts, trace.WithAttributes(attrs...))
|
||||||
|
|
||||||
ctx, span := th.conf.tracer.Start(ctx, cmd.FullName(), opts...)
|
spanName := cmd.FullName()
|
||||||
|
if th.conf.spanNameFn != nil {
|
||||||
|
spanName = th.conf.spanNameFn(TracingHookProcess, spanName)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, span := th.conf.tracer.Start(ctx, spanName, opts...)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
if err := hook(ctx, cmd); err != nil {
|
if err := hook(ctx, cmd); err != nil {
|
||||||
|
@ -163,7 +173,12 @@ func (th *tracingHook) ProcessPipelineHook(
|
||||||
opts := th.spanOpts
|
opts := th.spanOpts
|
||||||
opts = append(opts, trace.WithAttributes(attrs...))
|
opts = append(opts, trace.WithAttributes(attrs...))
|
||||||
|
|
||||||
ctx, span := th.conf.tracer.Start(ctx, "redis.pipeline "+summary, opts...)
|
spanName := "redis.pipeline " + summary
|
||||||
|
if th.conf.spanNameFn != nil {
|
||||||
|
spanName = th.conf.spanNameFn(TracingHookProcessPipeline, spanName)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, span := th.conf.tracer.Start(ctx, spanName, opts...)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
if err := hook(ctx, cmds); err != nil {
|
if err := hook(ctx, cmds); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue