Skip to content

fix(transactions): Defer dynamic sampling until metrics config is valid#6246

Open
jjbayer wants to merge 5 commits into
masterfrom
fix/ds-no-metrics
Open

fix(transactions): Defer dynamic sampling until metrics config is valid#6246
jjbayer wants to merge 5 commits into
masterfrom
fix/ds-no-metrics

Conversation

@jjbayer

@jjbayer jjbayer commented Jul 17, 2026

Copy link
Copy Markdown
Member

If metrics extraction config is invalid, delegate dynamic sampling to the next relay. This prevents dropping transactions for which no metrics were extracted yet.

Fixes RELAY-268

@linear-code

linear-code Bot commented Jul 17, 2026

Copy link
Copy Markdown

RELAY-268

) -> (SamplingOutput, Option<CombinedMetricExtractionConfig<'_>>) {
let metrics_config = get_metrics_config(ctx);

if metrics_config.is_err() && !ctx.is_processing() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra !ctx.is_processing check is here because I assume we still want sampling to happen in the final relay, even if no metrics could be extracted.

let error = Error::from(limits);
let (indexed, metrics) = split_indexed_and_total(self, ctx, SamplingDecision::Keep);
let (indexed, metrics) =
split_indexed_and_total(self, ctx, SamplingDecision::Keep, get_metrics_config(ctx));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit unfortunate: I have to call get_metrics_config again because this is a trait impl. I considered making Context an associated type, and passing in the metrics config via Context. But then again, get_metrics_config is a lightweight operation so maybe recomputation is OK here (ctx cannot change between computations).

@jjbayer
jjbayer marked this pull request as ready for review July 17, 2026 11:51
@jjbayer
jjbayer requested a review from a team as a code owner July 17, 2026 11:51
Comment on lines +224 to +232
if metrics_config.is_err() && !ctx.is_processing() {
// Defer dynamic sampling until the next relay.
return (
SamplingOutput::Keep {
payload,
sample_rate: None,
},
None,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The fix to defer dynamic sampling for invalid metrics configs only applies to non-processing relays. Processing relays will still drop transactions without extracting metrics in this scenario.
Severity: MEDIUM

Suggested Fix

Remove the !ctx.is_processing() condition from the check in run_dynamic_sampling. This will ensure that both processing and non-processing relays defer dynamic sampling when the metrics extraction configuration is invalid, preventing data loss and creating consistent behavior across all relay types. Also, add a test case for processing relays with invalid metric configs to ensure correctness.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: relay-server/src/processing/transactions/process.rs#L224-L232

Potential issue: The change to defer dynamic sampling when `metrics_config` is invalid
is gated by `!ctx.is_processing()`. This means the fix only applies to non-processing
relays. For a processing relay, if the project's metric extraction configuration is
invalid (e.g., an unsupported version), dynamic sampling will still execute. If the
sampling decision is to drop the transaction, it will be dropped without any metrics
being extracted. This is inconsistent with the behavior of non-processing relays and
contrary to the PR's goal of preventing data loss in this scenario. The lack of test
coverage for processing relays suggests this was an oversight.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants