Skip to content

Commit

Permalink
feat: allow to configure baggage span processor
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Sep 21, 2024
1 parent cbe76e9 commit 85f223d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions uptrace/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/uptrace/uptrace-go/internal"

"go.opentelemetry.io/contrib/processors/baggagecopy"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
Expand All @@ -32,6 +33,7 @@ type config struct {
textMapPropagator propagation.TextMapPropagator
tracerProvider *sdktrace.TracerProvider
traceSampler sdktrace.Sampler
spanProcessors []sdktrace.SpanProcessor
prettyPrint bool
bspOptions []sdktrace.BatchSpanProcessorOption

Expand Down Expand Up @@ -219,6 +221,23 @@ func WithTraceSampler(sampler sdktrace.Sampler) TracingOption {
})
}

// WithSpanProcessor configures an additional span processor.
func WithSpanProcessor(sp sdktrace.SpanProcessor) TracingOption {
return tracingOption(func(conf *config) {
conf.spanProcessors = append(conf.spanProcessors, sp)
})
}

// WithBaggageSpanProcessor configures the The Baggage span processor.
//
// The Baggage span processor duplicates onto a span the attributes found in Baggage in the parent context at the moment the span is started. The passed filter determines which baggage members are added to the span.
//
// If filter is nil, all baggage members will be added.
func WithBaggageSpanProcessor(filter baggagecopy.Filter) TracingOption {
sp := baggagecopy.NewSpanProcessor(filter)
return WithSpanProcessor(sp)
}

// WithPropagator sets the global TextMapPropagator used by OpenTelemetry.
// The default is propagation.TraceContext and propagation.Baggage.
func WithPropagator(propagator propagation.TextMapPropagator) TracingOption {
Expand Down
5 changes: 5 additions & 0 deletions uptrace/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func configureTracing(ctx context.Context, client *client, conf *config) {
bsp := sdktrace.NewBatchSpanProcessor(exp, bspOptions...)
provider.RegisterSpanProcessor(bsp)

// Register additional span processors.
for _, sp := range conf.spanProcessors {
provider.RegisterSpanProcessor(sp)
}

if conf.prettyPrint {
exporter, err := stdouttrace.New(stdouttrace.WithPrettyPrint())
if err != nil {
Expand Down

0 comments on commit 85f223d

Please sign in to comment.