otelext

Extensions for OpenTelemetry Go SDK — reusable filters and samplers for fine-grained telemetry control.
Features
- Filter registry — global, thread-safe registry of attribute-based filters (
signal.Filter interface)
- FilterBasedSampler — trace sampler that drops spans based on registered filters
- CompositeSampler — combines multiple
sdktrace.Sampler instances with a restrict-only strategy (any sampler can restrict the decision, but never upgrade it)
Installation
go get github.com/thumbrise/otelext
Requires Go 1.25+ and OpenTelemetry SDK v1.42+.
Quick Start
Register a filter and use FilterBasedSampler
package main
import (
"github.com/thumbrise/otelext/signal"
"github.com/thumbrise/otelext/signal/trace"
)
func main() {
// Register your custom filter (must implement signal.Filter)
signal.RegisterFilter(myFilter)
// Create a sampler that drops spans matched by registered filters
sampler := trace.NewFilterBasedSampler()
// Use sampler in your TracerProvider setup
// sdktrace.NewTracerProvider(sdktrace.WithSampler(sampler))
}
Compose multiple samplers
sampler := trace.NewCompositeSampler(
trace.NewFilterBasedSampler(),
sdktrace.TraceIDRatioBased(0.5),
)
// The strictest decision wins: if any sampler returns Drop, the span is dropped.
API
signal.Filter interface
type Filter interface {
ShouldDrop(ctx context.Context, attrs attribute.Set) bool
Key(ctx context.Context) string
Description(ctx context.Context) string
}
signal package
| Function |
Description |
RegisterFilter(f) |
Add a filter to the global registry |
RegisteredFilters() |
Get a copy of all registered filters |
ClearFilters() |
Remove all registered filters |
signal/trace package
| Type |
Description |
FilterBasedSampler |
Sampler that drops spans when any registered filter matches |
CompositeSampler |
Combines samplers; strictest decision wins (restrict-only strategy) |
TODO
Documentation
Functionality
Tests
CI/CD
Infrastructure
Development
Prerequisites
Commands
task lint # Run golangci-lint + license header checks
task test # Run tests + benchmarks
task license # Auto-fix missing license headers
License
Apache License 2.0 — Copyright 2026 thumbrise
评论