@@ -41,6 +41,17 @@ type policy struct {
4141 attribute metric.MeasurementOption
4242}
4343
44+ // traceData is a wrapper around the publically used samplingpolicy.TraceData
45+ // that tracks information related to the decision making process but not
46+ // needed by any sampler implementations.
47+ type traceData struct {
48+ samplingpolicy.TraceData
49+
50+ arrivalTime time.Time
51+ decisionTime time.Time
52+ finalDecision samplingpolicy.Decision
53+ }
54+
4455type tailSamplingSpanProcessor struct {
4556 ctx context.Context
4657
@@ -51,7 +62,7 @@ type tailSamplingSpanProcessor struct {
5162 deleteTraceQueue * list.List
5263 nextConsumer consumer.Traces
5364 policies []* policy
54- idToTrace map [pcommon.TraceID ]* samplingpolicy. TraceData
65+ idToTrace map [pcommon.TraceID ]* traceData
5566 tickerFrequency time.Duration
5667 decisionBatcher idbatcher.Batcher
5768 sampledIDCache cache.Cache [bool ]
@@ -103,7 +114,7 @@ func newTracesProcessor(ctx context.Context, set processor.Settings, nextConsume
103114 sampledIDCache : sampledDecisions ,
104115 nonSampledIDCache : nonSampledDecisions ,
105116 logger : set .Logger ,
106- idToTrace : make (map [pcommon.TraceID ]* samplingpolicy. TraceData ),
117+ idToTrace : make (map [pcommon.TraceID ]* traceData ),
107118 deleteTraceQueue : list .New (),
108119 sampleOnFirstMatch : cfg .SampleOnFirstMatch ,
109120 blockOnOverflow : cfg .BlockOnOverflow ,
@@ -536,14 +547,14 @@ func (tsp *tailSamplingSpanProcessor) samplingPolicyOnTick() bool {
536547 metrics .idNotFoundOnMapCount ++
537548 continue
538549 }
539- trace .DecisionTime = time .Now ()
550+ trace .decisionTime = time .Now ()
540551
541- decision := tsp .makeDecision (id , trace , metrics )
552+ decision := tsp .makeDecision (id , & trace . TraceData , metrics )
542553 globalTracesSampledByDecision [decision ]++
543554
544555 // Sampled or not, remove the batches
545556 allSpans := trace .ReceivedBatches
546- trace .FinalDecision = decision
557+ trace .finalDecision = decision
547558 trace .ReceivedBatches = ptrace .NewTraces ()
548559
549560 if decision == samplingpolicy .Sampled {
@@ -691,10 +702,12 @@ func (tsp *tailSamplingSpanProcessor) processTrace(id pcommon.TraceID, rss ptrac
691702
692703 actualData , ok := tsp .idToTrace [id ]
693704 if ! ok {
694- actualData = & samplingpolicy.TraceData {
695- ArrivalTime : currTime ,
696- SpanCount : spanCount ,
697- ReceivedBatches : ptrace .NewTraces (),
705+ actualData = & traceData {
706+ arrivalTime : currTime ,
707+ TraceData : samplingpolicy.TraceData {
708+ SpanCount : spanCount ,
709+ ReceivedBatches : ptrace .NewTraces (),
710+ },
698711 }
699712
700713 tsp .idToTrace [id ] = actualData
@@ -709,7 +722,7 @@ func (tsp *tailSamplingSpanProcessor) processTrace(id pcommon.TraceID, rss ptrac
709722 actualData .SpanCount += spanCount
710723 }
711724
712- finalDecision := actualData .FinalDecision
725+ finalDecision := actualData .finalDecision
713726
714727 if finalDecision == samplingpolicy .Unspecified {
715728 // If the final decision hasn't been made, add the new spans to the
@@ -729,8 +742,8 @@ func (tsp *tailSamplingSpanProcessor) processTrace(id pcommon.TraceID, rss ptrac
729742 tsp .logger .Warn ("Unexpected sampling decision" , zap .Int ("decision" , int (finalDecision )))
730743 }
731744
732- if ! actualData .DecisionTime .IsZero () {
733- tsp .telemetry .ProcessorTailSamplingSamplingLateSpanAge .Record (tsp .ctx , int64 (time .Since (actualData .DecisionTime )/ time .Second ))
745+ if ! actualData .decisionTime .IsZero () {
746+ tsp .telemetry .ProcessorTailSamplingSamplingLateSpanAge .Record (tsp .ctx , int64 (time .Since (actualData .decisionTime )/ time .Second ))
734747 }
735748}
736749
@@ -767,7 +780,7 @@ func (tsp *tailSamplingSpanProcessor) dropTrace(traceID pcommon.TraceID, deletio
767780 }
768781
769782 delete (tsp .idToTrace , traceID )
770- tsp .telemetry .ProcessorTailSamplingSamplingTraceRemovalAge .Record (tsp .ctx , int64 (deletionTime .Sub (trace .ArrivalTime )/ time .Second ))
783+ tsp .telemetry .ProcessorTailSamplingSamplingTraceRemovalAge .Record (tsp .ctx , int64 (deletionTime .Sub (trace .arrivalTime )/ time .Second ))
771784}
772785
773786// forwardSpans sends the trace data to the next consumer. it is different from
0 commit comments