Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(metrics): Apply global tags to transaction metrics #3615

Merged
merged 11 commits into from
May 21, 2024

Conversation

jjbayer
Copy link
Member

@jjbayer jjbayer commented May 16, 2024

Prerequisite to getsentry/sentry#71004: Global tag mappings were not yet being applied to transaction metrics.

Beside the bug fix, this PR also bumps the metrics extraction version(s), and attempts to simplify the extraction function for transactions.

@@ -115,7 +115,8 @@ pub struct CustomMeasurementConfig {
/// - Delay metrics extraction for indexed transactions.
/// - 4: Adds support for `RuleConfigs` with string comparisons.
/// - 5: No change, bumped together with [`MetricExtractionConfig::MAX_SUPPORTED_VERSION`].
const TRANSACTION_EXTRACT_MAX_SUPPORTED_VERSION: u16 = 5;
/// - 6: Bugfix to make transaction metrics extraction apply globally defined tag mappings.
const TRANSACTION_EXTRACT_MAX_SUPPORTED_VERSION: u16 = 6;
Copy link
Member Author

Choose a reason for hiding this comment

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

We need to bump this version because old Relays will not apply global tags to legacy transaction metrics.

@@ -324,7 +325,7 @@ impl MetricExtractionConfig {
/// The latest version for this config struct.
///
/// This is the maximum version supported by this Relay instance.
pub const MAX_SUPPORTED_VERSION: u16 = 3;
pub const MAX_SUPPORTED_VERSION: u16 = 4;
Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately both versions need to be bumped in tandem: If I only bump TRANSACTION_EXTRACT_MAX_SUPPORTED_VERSION, old Relays will still set the metrics_extracted flag to true when they extract on-demand metrics, which means the crucial legacy transaction metrics (duration etc.) will not be extracted.

/// transaction events.
fn extract_metrics(
/// Extract transaction metrics.
fn extract_transaction_metrics(
Copy link
Member Author

Choose a reason for hiding this comment

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

Apologies for the large diff. The rewrite of this function is trying to achieve:

  1. Fix the bug referenced in the PR title.
  2. Make tandem version bumps unnecessary in the future.
  3. Simplify: This function was originally written as a general purpose function, but since it's only called from process_transactions we can introduce some early returns.

let generic_config = {
let config = match &state.project_state.config.metric_extraction {
ErrorBoundary::Ok(ref config) if config.is_supported() => config,
_ => return Ok(()),
Copy link
Member Author

Choose a reason for hiding this comment

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

Generic project config is no longer optional. event_metrics_extraced will only be set if both configs are present, allowing us to bump the two extraction versions individually in the future.


let extractor = TransactionExtractor {
config: tx_config,
generic_config: Some(&generic_config),
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the actual bug fix: Tag definitions are applied from both global and project config, not just project config.

"d:transactions/measurements.fcp@millisecond": "outlier",
"d:transactions/duration@millisecond": "inlier",
"d:transactions/measurements.lcp@millisecond": "inlier",
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Without the bug fix, this dict would be empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied this from a snapshot in sentry, so the integration test also verifies that the config that sentry provides is applied correctly.

@jjbayer jjbayer marked this pull request as ready for review May 17, 2024 07:41
@jjbayer jjbayer requested a review from a team as a code owner May 17, 2024 07:41
@jjbayer jjbayer self-assigned this May 17, 2024
@@ -141,5 +141,6 @@ insta = { workspace = true }
relay-event-schema = { workspace = true, features = ["jsonschema"] }
relay-protocol = { workspace = true, features = ["test"] }
relay-test = { workspace = true }
serde_yaml = { workspace = true }
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't seem to be used?

return Ok(());
})
}
let generic_config = {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let generic_config = {
let combined_config = {

Comment on lines 1259 to 1261
let Some(event) = state.event.value() else {
return Ok(());
};
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this to the top after state.event_metrics_extracted?

@Dav1dde
Copy link
Member

Dav1dde commented May 21, 2024

@jjbayer watch out we had a self hosted release and the changelog is messed up

@jjbayer jjbayer enabled auto-merge (squash) May 21, 2024 06:58
@jjbayer jjbayer merged commit 75fc8de into master May 21, 2024
22 checks passed
@jjbayer jjbayer deleted the fix/metrics-apply-generic-tags branch May 21, 2024 10:32
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.

None yet

2 participants