mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
feat(tracing) custom tracer name (#2310)
* feat(log): add tencent cls fix update * refactor(log) use the same interface name * fix(log) tencent toString * feat(tracing) custom tracer name
This commit is contained in:
parent
0ce9e8d069
commit
cb6176dbbb
@ -24,6 +24,7 @@ type Tracer struct {
|
||||
func NewTracer(kind trace.SpanKind, opts ...Option) *Tracer {
|
||||
op := options{
|
||||
propagator: propagation.NewCompositeTextMapPropagator(Metadata{}, propagation.Baggage{}, propagation.TraceContext{}),
|
||||
tracerName: "kratos",
|
||||
}
|
||||
for _, o := range opts {
|
||||
o(&op)
|
||||
@ -34,9 +35,9 @@ func NewTracer(kind trace.SpanKind, opts ...Option) *Tracer {
|
||||
|
||||
switch kind {
|
||||
case trace.SpanKindClient:
|
||||
return &Tracer{tracer: otel.Tracer("kratos"), kind: kind, opt: &op}
|
||||
return &Tracer{tracer: otel.Tracer(op.tracerName), kind: kind, opt: &op}
|
||||
case trace.SpanKindServer:
|
||||
return &Tracer{tracer: otel.Tracer("kratos"), kind: kind, opt: &op}
|
||||
return &Tracer{tracer: otel.Tracer(op.tracerName), kind: kind, opt: &op}
|
||||
default:
|
||||
panic(fmt.Sprintf("unsupported span kind: %v", kind))
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
type Option func(*options)
|
||||
|
||||
type options struct {
|
||||
tracerName string
|
||||
tracerProvider trace.TracerProvider
|
||||
propagator propagation.TextMapPropagator
|
||||
}
|
||||
@ -34,6 +35,13 @@ func WithTracerProvider(provider trace.TracerProvider) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithTracerName with tracer name
|
||||
func WithTracerName(tracerName string) Option {
|
||||
return func(opts *options) {
|
||||
opts.tracerName = tracerName
|
||||
}
|
||||
}
|
||||
|
||||
// Server returns a new server middleware for OpenTelemetry.
|
||||
func Server(opts ...Option) middleware.Middleware {
|
||||
tracer := NewTracer(trace.SpanKindServer, opts...)
|
||||
|
Loading…
x
Reference in New Issue
Block a user