Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump google.golang.org/grpc from 1.45.0 to 1.46.2 in /exporter/lokiexporter #607

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
probabilisticsampler: add filterspan config
  • Loading branch information
tanner-bruce committed May 2, 2022
commit 562bd79b243187367fcba9b0f732269b24fe5f07
4 changes: 4 additions & 0 deletions processor/probabilisticsamplerprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ package probabilisticsamplerprocessor // import "github.com/open-telemetry/opent

import (
"go.opentelemetry.io/collector/config"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterconfig"
)

// Config has the configuration guiding the trace sampler processor.
type Config struct {
config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct

filterconfig.MatchConfig `mapstructure:",squash"`

// SamplingPercentage is the percentage rate at which traces are going to be sampled. Defaults to zero, i.e.: no sample.
// Values greater or equal 100 are treated as "sample all traces".
SamplingPercentage float32 `mapstructure:"sampling_percentage"`
Expand Down
18 changes: 18 additions & 0 deletions processor/probabilisticsamplerprocessor/probabilisticsampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/model/pdata"
"go.opentelemetry.io/collector/processor/processorhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterspan"
)

// samplingPriority has the semantic result of parsing the "sampling.priority"
Expand Down Expand Up @@ -51,15 +53,28 @@ const (
type tracesamplerprocessor struct {
scaledSamplingRate uint32
hashSeed uint32
include filterspan.Matcher
exclude filterspan.Matcher
}

// newTracesProcessor returns a processor.TracesProcessor that will perform head sampling according to the given
// configuration.
func newTracesProcessor(nextConsumer consumer.Traces, cfg *Config) (component.TracesProcessor, error) {
include, err := filterspan.NewMatcher(cfg.Include)
if err != nil {
return nil, err
}
exclude, err := filterspan.NewMatcher(cfg.Exclude)
if err != nil {
return nil, err
}

tsp := &tracesamplerprocessor{
// Adjust sampling percentage on private so recalculations are avoided.
scaledSamplingRate: uint32(cfg.SamplingPercentage * percentageScaleFactor),
hashSeed: cfg.HashSeed,
include: include,
exclude: exclude,
}

return processorhelper.NewTracesProcessor(
Expand All @@ -73,6 +88,9 @@ func (tsp *tracesamplerprocessor) processTraces(_ context.Context, td pdata.Trac
td.ResourceSpans().RemoveIf(func(rs pdata.ResourceSpans) bool {
rs.InstrumentationLibrarySpans().RemoveIf(func(ils pdata.InstrumentationLibrarySpans) bool {
ils.Spans().RemoveIf(func(s pdata.Span) bool {
if filterspan.SkipSpan(tsp.include, tsp.exclude, s, rs.Resource(), ils.InstrumentationLibrary()) {
return false
}
sp := parseSpanSamplingPriority(s)
if sp == doNotSampleSpan {
// The OpenTelemetry mentions this as a "hint" we take a stronger
Expand Down