Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit 79237de

Browse files
author
Steven Karis
authored
Add sampled / not sampled metrics per policy (#396)
* Add sampled / not sampled metrics per policy
1 parent 749cd7a commit 79237de

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

internal/collector/processor/tail_sampling/metrics.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import (
2424

2525
// Variables related to metrics specific to tail sampling.
2626
var (
27-
tagPolicyKey, _ = tag.NewKey("policy")
27+
tagPolicyKey, _ = tag.NewKey("policy")
28+
tagSampledKey, _ = tag.NewKey("sampled")
2829

2930
statDecisionLatencyMicroSec = stats.Int64("sampling_decision_latency", "Latency (in microseconds) of a given sampling policy", "µs")
3031
statOverallDecisionLatencyµs = stats.Int64("sampling_decision_timer_latency", "Latency (in microseconds) of each run of the sampling decision timer", "µs")
@@ -34,6 +35,8 @@ var (
3435

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

38+
statCountTracesSampled = stats.Int64("count_traces_sampled", "Count of traces that were sampled or not", stats.UnitDimensionless)
39+
3740
statDroppedTooEarlyCount = stats.Int64("sampling_trace_dropped_too_early", "Count of traces that needed to be dropped the configured wait time", stats.UnitDimensionless)
3841
statNewTraceIDReceivedCount = stats.Int64("new_trace_id_received", "Counts the arrival of new traces", stats.UnitDimensionless)
3942
statTracesOnMemoryGauge = stats.Int64("sampling_traces_on_memory", "Tracks the number of traces current on memory", stats.UnitDimensionless)
@@ -63,6 +66,7 @@ func SamplingProcessorMetricViews(level telemetry.Level) []*view.View {
6366
Description: statOverallDecisionLatencyµs.Description(),
6467
Aggregation: latencyDistributionAggregation,
6568
}
69+
6670
traceRemovalAgeView := &view.View{
6771
Name: statTraceRemovalAgeSec.Name(),
6872
Measure: statTraceRemovalAgeSec,
@@ -75,12 +79,23 @@ func SamplingProcessorMetricViews(level telemetry.Level) []*view.View {
7579
Description: statLateSpanArrivalAfterDecision.Description(),
7680
Aggregation: ageDistributionAggregation,
7781
}
82+
7883
countPolicyEvaluationErrorView := &view.View{
7984
Name: statPolicyEvaluationErrorCount.Name(),
8085
Measure: statPolicyEvaluationErrorCount,
8186
Description: statPolicyEvaluationErrorCount.Description(),
8287
Aggregation: view.Sum(),
8388
}
89+
90+
sampledTagKeys := []tag.Key{tagPolicyKey, tagSampledKey}
91+
countTracesSampledView := &view.View{
92+
Name: statCountTracesSampled.Name(),
93+
Measure: statCountTracesSampled,
94+
Description: statCountTracesSampled.Description(),
95+
TagKeys: sampledTagKeys,
96+
Aggregation: view.Sum(),
97+
}
98+
8499
countTraceDroppedTooEarlyView := &view.View{
85100
Name: statDroppedTooEarlyCount.Name(),
86101
Measure: statDroppedTooEarlyCount,
@@ -103,10 +118,16 @@ func SamplingProcessorMetricViews(level telemetry.Level) []*view.View {
103118
return []*view.View{
104119
decisionLatencyView,
105120
overallDecisionLatencyView,
121+
106122
traceRemovalAgeView,
107123
lateSpanArrivalView,
124+
108125
countPolicyEvaluationErrorView,
126+
127+
countTracesSampledView,
128+
109129
countTraceDroppedTooEarlyView,
110130
countTraceIDArrivalView,
111-
trackTracesOnMemorylView}
131+
trackTracesOnMemorylView,
132+
}
112133
}

internal/collector/processor/tail_sampling/processor.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ func (tsp *tailSamplingSpanProcessor) samplingPolicyOnTick() {
133133

134134
switch decision {
135135
case sampling.Sampled:
136+
stats.RecordWithTags(
137+
policy.ctx,
138+
[]tag.Mutator{tag.Insert(tagSampledKey, "true")},
139+
statCountTracesSampled.M(int64(1)),
140+
)
136141
decisionSampled++
137142

138143
trace.Lock()
@@ -143,6 +148,11 @@ func (tsp *tailSamplingSpanProcessor) samplingPolicyOnTick() {
143148
policy.Destination.ProcessSpans(traceBatches[j], "tail-sampling")
144149
}
145150
case sampling.NotSampled:
151+
stats.RecordWithTags(
152+
policy.ctx,
153+
[]tag.Mutator{tag.Insert(tagSampledKey, "false")},
154+
statCountTracesSampled.M(int64(1)),
155+
)
146156
decisionNotSampled++
147157
}
148158
}

0 commit comments

Comments
 (0)