Skip to content

Commit

Permalink
Remove makeSamplingDecision func (#1711)
Browse files Browse the repository at this point in the history
The makeSamplingDecision function is a wrapper around the provider
sampler calling ShouldSample with a duplicate configuration struct. That
duplication and need for translation as well as the addition function
call is unnecessary, this function is called in only one place.

Resolves #1706
  • Loading branch information
MrAlias authored Mar 20, 2021
1 parent e24702d commit 5d559b4
Showing 1 changed file with 9 additions and 36 deletions.
45 changes: 9 additions & 36 deletions sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,18 +548,15 @@ func startSpanInternal(ctx context.Context, tr *tracer, name string, parent trac
span.links = newEvictedQueue(spanLimits.LinkCountLimit)
span.spanLimits = spanLimits

data := samplingData{
noParent: hasEmptySpanContext(parent),
remoteParent: remoteParent,
parent: parent,
name: name,
sampler: provider.sampler,
span: span,
attributes: o.Attributes,
links: o.Links,
kind: o.SpanKind,
}
samplingResult := makeSamplingDecision(data)
samplingResult := provider.sampler.ShouldSample(SamplingParameters{
ParentContext: parent,
TraceID: span.spanContext.TraceID(),
Name: name,
HasRemoteParent: remoteParent,
Kind: o.SpanKind,
Attributes: o.Attributes,
Links: o.Links,
})
if isSampled(samplingResult) {
span.spanContext = span.spanContext.WithTraceFlags(span.spanContext.TraceFlags() | trace.FlagsSampled)
} else {
Expand Down Expand Up @@ -594,30 +591,6 @@ func hasEmptySpanContext(parent trace.SpanContext) bool {
return parent.Equal(emptySpanContext)
}

type samplingData struct {
noParent bool
remoteParent bool
parent trace.SpanContext
name string
sampler Sampler
span *span
attributes []attribute.KeyValue
links []trace.Link
kind trace.SpanKind
}

func makeSamplingDecision(data samplingData) SamplingResult {
return data.sampler.ShouldSample(SamplingParameters{
ParentContext: data.parent,
TraceID: data.span.spanContext.TraceID(),
Name: data.name,
HasRemoteParent: data.remoteParent,
Kind: data.kind,
Attributes: data.attributes,
Links: data.links,
})
}

func isRecording(s SamplingResult) bool {
return s.Decision == RecordOnly || s.Decision == RecordAndSample
}
Expand Down

0 comments on commit 5d559b4

Please sign in to comment.