Skip to content

Commit 5fa7b8e

Browse files
authored
fix(spansv2): Add DSC transaction name to count per root metric (#5278)
The tag was missing for spans v2, there is still a bug in span v1 processing where the local instead of DSC transaction name is added, which I will fix in a follow-up. Currently the implementation looks up the DSC multiple times, even in places where it was already validated to be present, this is not a big deal, but I plan to look into this in INGEST-609, if we can more strictly type the DSC (and the presence of the DSC).
1 parent 549cdd4 commit 5fa7b8e

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

relay-server/src/processing/spans/dynamic_sampling.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use chrono::Utc;
55
use relay_dynamic_config::ErrorBoundary;
66
use relay_metrics::{Bucket, BucketMetadata, BucketValue, UnixTimestamp};
77
use relay_quotas::{DataCategory, Scoping};
8-
use relay_sampling::SamplingConfig;
98
use relay_sampling::config::RuleType;
109
use relay_sampling::evaluation::{SamplingDecision, SamplingEvaluator};
10+
use relay_sampling::{DynamicSamplingContext, SamplingConfig};
1111

1212
use crate::envelope::Item;
1313
use crate::managed::{Counted, Managed, Quantities};
@@ -74,7 +74,12 @@ pub async fn run(
7474

7575
// At this point the decision is to drop the spans.
7676
let span_count = outcome_count(&spans.spans);
77-
let metrics = create_metrics(spans.scoping(), span_count, SamplingDecision::Drop);
77+
let metrics = create_metrics(
78+
spans.scoping(),
79+
span_count,
80+
spans.headers.dsc(),
81+
SamplingDecision::Drop,
82+
);
7883
let (spans, metrics) = spans.split_once(|spans| (UnsampledSpans::from(spans), metrics));
7984

8085
let outcome = Outcome::FilteredSampling(sampling_match.into_matched_rules().into());
@@ -98,6 +103,7 @@ pub fn create_indexed_metrics(
98103
let metrics = create_metrics(
99104
spans.scoping(),
100105
spans.spans.len() as u32,
106+
spans.headers.dsc(),
101107
SamplingDecision::Keep,
102108
);
103109

@@ -174,6 +180,7 @@ fn is_sampling_config_supported(project_info: &ProjectInfo) -> bool {
174180
fn create_metrics(
175181
scoping: Scoping,
176182
span_count: u32,
183+
dsc: Option<&DynamicSamplingContext>,
177184
sampling_decision: SamplingDecision,
178185
) -> ExtractedMetrics {
179186
let mut metrics = ExtractedMetrics::default();
@@ -195,13 +202,18 @@ fn create_metrics(
195202
width: 0,
196203
name: "c:spans/count_per_root_project@none".into(),
197204
value: BucketValue::counter(span_count.into()),
198-
tags: BTreeMap::from([
199-
("decision".to_owned(), sampling_decision.to_string()),
200-
(
205+
tags: {
206+
let mut tags = BTreeMap::new();
207+
tags.insert("decision".to_owned(), sampling_decision.to_string());
208+
tags.insert(
201209
"target_project_id".to_owned(),
202210
scoping.project_id.to_string(),
203-
),
204-
]),
211+
);
212+
if let Some(tx) = dsc.and_then(|dsc| dsc.transaction.clone()) {
213+
tags.insert("transaction".to_owned(), tx);
214+
}
215+
tags
216+
},
205217
metadata,
206218
});
207219
metrics.project_metrics.push(Bucket {

tests/integration/test_spansv2.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def test_spansv2_ds_drop(mini_sentry, relay, rule_type):
177177
trace_info={
178178
"trace_id": "5b8efff798038103d269b633813fc60c",
179179
"public_key": project_config["publicKeys"][0]["publicKey"],
180+
"transaction": "tx_from_root",
180181
},
181182
)
182183

@@ -199,7 +200,11 @@ def test_spansv2_ds_drop(mini_sentry, relay, rule_type):
199200
{
200201
"metadata": mock.ANY,
201202
"name": "c:spans/count_per_root_project@none",
202-
"tags": {"decision": "drop", "target_project_id": "42"},
203+
"tags": {
204+
"decision": "drop",
205+
"target_project_id": "42",
206+
"transaction": "tx_from_root",
207+
},
203208
"timestamp": time_within_delta(),
204209
"type": "c",
205210
"value": 1.0,
@@ -265,6 +270,7 @@ def test_spansv2_ds_sampled(
265270
trace_info={
266271
"trace_id": "5b8efff798038103d269b633813fc60c",
267272
"public_key": sampling_config["publicKeys"][0]["publicKey"],
273+
"transaction": "tx_from_root",
268274
},
269275
)
270276

@@ -281,7 +287,11 @@ def test_spansv2_ds_sampled(
281287
"project_id": 43,
282288
"received_at": time_within_delta(),
283289
"retention_days": 90,
284-
"tags": {"decision": "keep", "target_project_id": "42"},
290+
"tags": {
291+
"decision": "keep",
292+
"target_project_id": "42",
293+
"transaction": "tx_from_root",
294+
},
285295
"timestamp": time_within_delta(),
286296
"type": "c",
287297
"value": 1.0,

0 commit comments

Comments
 (0)