Skip to content

Commit

Permalink
[processor/tailsamplingprocessor] add global traces sampled metric
Browse files Browse the repository at this point in the history
- captures the global count of traces sampled by at least one policy
- trying to capture the count in the existing `statCountTracesSampled` would have resulted in either an empty policy key or have a placeholder value (causing potential collision with user named policies from the configuration)
  • Loading branch information
James Neill committed Sep 18, 2023
1 parent 38a61c4 commit 7311b19
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
12 changes: 11 additions & 1 deletion processor/tailsamplingprocessor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ var (

statPolicyEvaluationErrorCount = stats.Int64("sampling_policy_evaluation_error", "Count of sampling policy evaluation errors", stats.UnitDimensionless)

statCountTracesSampled = stats.Int64("count_traces_sampled", "Count of traces that were sampled or not", stats.UnitDimensionless)
statCountTracesSampled = stats.Int64("count_traces_sampled", "Count of traces that were sampled or not per sampling policy", stats.UnitDimensionless)
statCountGlobalTracesSampled = stats.Int64("global_count_traces_sampled", "Global count of traces that were sampled or not by at least one policy", stats.UnitDimensionless)

statDroppedTooEarlyCount = stats.Int64("sampling_trace_dropped_too_early", "Count of traces that needed to be dropped the configured wait time", stats.UnitDimensionless)
statNewTraceIDReceivedCount = stats.Int64("new_trace_id_received", "Counts the arrival of new traces", stats.UnitDimensionless)
Expand Down Expand Up @@ -88,6 +89,14 @@ func SamplingProcessorMetricViews(level configtelemetry.Level) []*view.View {
Aggregation: view.Sum(),
}

countGlobalTracesSampledView := &view.View{
Name: obsreport.BuildProcessorCustomMetricName(metadata.Type, statCountGlobalTracesSampled.Name()),
Measure: statCountGlobalTracesSampled,
Description: statCountGlobalTracesSampled.Description(),
TagKeys: []tag.Key{tagSampledKey},
Aggregation: view.Sum(),
}

countTraceDroppedTooEarlyView := &view.View{
Name: obsreport.BuildProcessorCustomMetricName(metadata.Type, statDroppedTooEarlyCount.Name()),
Measure: statDroppedTooEarlyCount,
Expand Down Expand Up @@ -117,6 +126,7 @@ func SamplingProcessorMetricViews(level configtelemetry.Level) []*view.View {
countPolicyEvaluationErrorView,

countTracesSampledView,
countGlobalTracesSampledView,

countTraceDroppedTooEarlyView,
countTraceIDArrivalView,
Expand Down
15 changes: 15 additions & 0 deletions processor/tailsamplingprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,21 @@ func (tsp *tailSamplingSpanProcessor) makeDecision(id pcommon.TraceID, trace *sa
}
}

switch finalDecision {
case sampling.Sampled:
_ = stats.RecordWithTags(
tsp.ctx,
[]tag.Mutator{tag.Upsert(tagSampledKey, "true")},
statCountGlobalTracesSampled.M(int64(1)),
)
case sampling.NotSampled:
_ = stats.RecordWithTags(
tsp.ctx,
[]tag.Mutator{tag.Upsert(tagSampledKey, "false")},
statCountGlobalTracesSampled.M(int64(1)),
)
}

return finalDecision, matchingPolicy
}

Expand Down

0 comments on commit 7311b19

Please sign in to comment.