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
feat/remove-config-debugf
Germiniku 2 years ago committed by GitHub
parent 0ce9e8d069
commit cb6176dbbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      middleware/tracing/tracer.go
  2. 8
      middleware/tracing/tracing.go

@ -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…
Cancel
Save