Skip to content

Commit

Permalink
Rename BaggageKeyPredicate to Filter (#5809)
Browse files Browse the repository at this point in the history
`baggagetrace.BaggageKeyPredicate` is overly verbose. Given this type is
used as a filter, rename it to match its functionality.
  • Loading branch information
MrAlias authored Jun 27, 2024
1 parent 9f2491a commit e891fb8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Improve performance of `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` with the usage of `WithAttributeSet()` instead of `WithAttribute()`. (#5664)
- Improve performance of `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` with the usage of `WithAttributeSet()` instead of `WithAttribute()`. (#5664)
- Update `go.opentelemetry.io/contrib/config` to latest released configuration schema which introduces breaking changes where `Attributes` is now a `map[string]interface{}`. (#5758)
- Rename `BaggageKeyPredicate` to `Filter` in `go.opentelemetry.io/contrib/processors/baggage/baggagetrace`. (#5809)

## [1.27.0/0.52.0/0.21.0/0.7.0/0.2.0] - 2024-05-21

Expand Down
19 changes: 10 additions & 9 deletions processors/baggage/baggagetrace/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import (
"go.opentelemetry.io/otel/sdk/trace"
)

// BaggageKeyPredicate is a function that returns true if the baggage key should be added to the span.
type BaggageKeyPredicate func(baggageKey string) bool
// Filter returns true if the baggage member with key should be added to a
// span.
type Filter func(key string) bool

// AllowAllBaggageKeys is a BaggageKeyPredicate that allows all baggage keys.
var AllowAllBaggageKeys = func(string) bool { return true }
// AllowAllBaggageKeys allows all baggage members to be added to a span.
var AllowAllBaggageKeys Filter = func(string) bool { return true }

// SpanProcessor is a processing pipeline for spans in the trace signal.
type SpanProcessor struct {
baggageKeyPredicate BaggageKeyPredicate
filter Filter
}

var _ trace.SpanProcessor = (*SpanProcessor)(nil)
Expand All @@ -28,17 +29,17 @@ var _ trace.SpanProcessor = (*SpanProcessor)(nil)
//
// 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 predicate function is used to filter which baggage keys are added to the span.
func New(baggageKeyPredicate BaggageKeyPredicate) trace.SpanProcessor {
// The passed filter determines which baggage members are added to the span.
func New(filter Filter) trace.SpanProcessor {
return &SpanProcessor{
baggageKeyPredicate: baggageKeyPredicate,
filter: filter,
}
}

// OnStart is called when a span is started and adds span attributes for baggage contents.
func (processor SpanProcessor) OnStart(ctx context.Context, span trace.ReadWriteSpan) {
for _, entry := range otelbaggage.FromContext(ctx).Members() {
if processor.baggageKeyPredicate(entry.Key()) {
if processor.filter(entry.Key()) {
span.SetAttributes(attribute.String(entry.Key(), entry.Value()))
}
}
Expand Down

0 comments on commit e891fb8

Please sign in to comment.