Skip to content

Commit ed3874e

Browse files
committed
fix: Everything
1 parent 781834e commit ed3874e

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

relay-server/src/actors/processor.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use relay_log::LogError;
3232
use relay_metrics::{Bucket, Metric};
3333
use relay_quotas::{DataCategory, RateLimits, ReasonCode};
3434
use relay_redis::RedisPool;
35-
use relay_sampling::RuleId;
35+
use relay_sampling::{DynamicSamplingContext, RuleId};
3636
use relay_statsd::metric;
3737

3838
use crate::actors::envelopes::{EnvelopeManager, SendEnvelope, SendEnvelopeError, SubmitEnvelope};
@@ -344,6 +344,30 @@ fn outcome_from_profile_error(err: relay_profiling::ProfileError) -> Outcome {
344344
Outcome::Invalid(discard_reason)
345345
}
346346

347+
fn track_sampling_metrics(
348+
project_state: &ProjectState,
349+
context: &DynamicSamplingContext,
350+
event: &Event,
351+
) {
352+
// We only collect this metric for the root transaction event, so ignore secondary projects.
353+
if !project_state.is_matching_key(context.public_key) {
354+
return;
355+
}
356+
357+
let is_unstable = event.transaction.value() != context.transaction.as_ref();
358+
let in_dsc = context.transaction.is_some();
359+
let in_payload = event.transaction.value().is_some();
360+
361+
metric!(
362+
counter(RelayCounters::DynamicSamplingRootTransaction) += 1,
363+
match = if is_unstable { "mismatch" } else { "match" },
364+
dsc = if in_dsc { "some" } else { "none" },
365+
payload = if in_payload { "some" } else { "none" },
366+
source = &event.get_transaction_source().to_string(),
367+
platform = event.platform.as_str().unwrap_or("other"),
368+
);
369+
}
370+
347371
/// Synchronous service for processing envelopes.
348372
pub struct EnvelopeProcessor {
349373
config: Arc<Config>,
@@ -1599,6 +1623,10 @@ impl EnvelopeProcessor {
15991623
}
16001624
);
16011625
state.transaction_metrics_extracted = true;
1626+
1627+
if let Some(context) = state.envelope.sampling_context() {
1628+
track_sampling_metrics(&state.project_state, context, event);
1629+
}
16021630
}
16031631
Ok(())
16041632
}

relay-server/src/utils/dynamic_sampling.rs

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,19 @@ use relay_general::protocol::Event;
77
use relay_sampling::{
88
pseudo_random_from_uuid, DynamicSamplingContext, RuleId, SamplingConfig, SamplingRule,
99
};
10-
use relay_statsd::metric;
1110

1211
use crate::actors::project::ProjectState;
1312
use crate::envelope::{Envelope, ItemType};
14-
use crate::statsd::{RelayCounters, RelayTimers};
1513

16-
macro_rules! some_or {
17-
($e:expr, $fallback:expr) => {
14+
macro_rules! or_ok_none {
15+
($e:expr) => {
1816
match $e {
1917
Some(x) => x,
20-
None => $fallback,
18+
None => return Ok(None),
2119
}
2220
};
2321
}
2422

25-
macro_rules! or_ok_none {
26-
($e:expr) => {
27-
some_or!($e, return Ok(None))
28-
};
29-
}
30-
3123
/// The result of a sampling operation.
3224
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3325
pub enum SamplingResult {
@@ -133,32 +125,6 @@ pub fn should_keep_event(
133125
SamplingResult::Keep
134126
}
135127

136-
fn track_sampling_metrics(
137-
sampling_context: Option<&DynamicSamplingContext>,
138-
event: Option<&Event>,
139-
project_state: &ProjectState,
140-
sampling_project_state: Option<&ProjectState>,
141-
) {
142-
let sampling_context = some_or!(sampling_context, return);
143-
let event = some_or!(event, return);
144-
let sampling_project_state = some_or!(sampling_project_state, return);
145-
146-
if sampling_project_state.project_id != project_state.project_id {
147-
return;
148-
}
149-
150-
let is_unstable_transaction_name = event.transaction.value() != sampling_context.transaction;
151-
let dsc_has_transaction_name = sampling_context.transaction.is_some();
152-
let event_has_transaction_name = event.transaction.value().is_some();
153-
154-
metric!(
155-
counter(RelayCounters::DynamicSamplingRootTransaction) += 1,
156-
is_unstable_transaction_name = is_unstable_transaction_name,
157-
dsc_has_transaction_name = dsc_has_transaction_name,
158-
event_has_transaction_name = event_has_transaction_name,
159-
);
160-
}
161-
162128
/// Returns the project key defined in the `trace` header of the envelope, if defined.
163129
/// If there are no transactions in the envelope, we return None here, because there is nothing
164130
/// to sample by trace.

0 commit comments

Comments
 (0)