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

feat(dynamic-sampling): Track metric every time a DSC is built #3575

Merged
merged 13 commits into from
May 21, 2024

Conversation

iambriccardo
Copy link
Member

@iambriccardo iambriccardo commented May 10, 2024

This PR adds a new metric that collects the number of times the DSC is built by Relay when it was not found on a transaction that should contain the DSC.

The logic in this PR performs a semantic versioning comparison between the minimum version of an SDK that should support a DSC and the current SDK version of the SDK that sent the event.

Closes: #3570

#skip-changelog

@iambriccardo iambriccardo requested a review from jjbayer May 10, 2024 08:43
@iambriccardo iambriccardo marked this pull request as ready for review May 10, 2024 08:43
@iambriccardo iambriccardo requested a review from a team as a code owner May 10, 2024 08:43
Ordering::Greater | Ordering::Equal => {
relay_statsd::metric!(
counter(RelayCounters::MissingDynamicSamplingContext) += 1,
sdk_name = sdk_name.as_str()
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 tag has technically unbounded cardinality but we know that the SDK names are not many.

Copy link
Member

Choose a reason for hiding this comment

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

You know that sdk_name is in SUPPORTED_SDK_VERSIONS, so it is bounded, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah in this case this is a good point, I forgot I was checking the presence in the map.

// The list is defined here:
// https://docs.sentry.io/product/performance/performance-at-scale/getting-started
static SUPPORTED_SDK_VERSIONS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
let mut supported_sdk_versions = HashMap::new();
Copy link
Member

Choose a reason for hiding this comment

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

HashMap::from([("key", "value"), ...])

///
/// This function is just temporary since it's used to compare SDK versions when an [`Event`] is
/// received.
fn compare_versions(version1: &str, version2: &str) -> std::cmp::Ordering {
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 use the https://docs.rs/semver/latest/semver/ crate for this? It's already part of our dependency tree.

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 imagined there was something, will use that, thanks!

Ordering::Greater | Ordering::Equal => {
relay_statsd::metric!(
counter(RelayCounters::MissingDynamicSamplingContext) += 1,
sdk_name = sdk_name.as_str()
Copy link
Member

Choose a reason for hiding this comment

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

You know that sdk_name is in SUPPORTED_SDK_VERSIONS, so it is bounded, right?

@iambriccardo iambriccardo requested a review from jjbayer May 10, 2024 09:14
Copy link
Member

@Dav1dde Dav1dde left a comment

Choose a reason for hiding this comment

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

Can't we just emit a sentry error whenever we have a missing dsc at a certain sample rate, instead of doing this semver dance with a hardocded list of SDKs then just to have a metric which doesn't even include the SDK version?

/// Emits a metric when an [`Event`] is inside an [`Envelope`] without [`DynamicSamplingContext`].
///
/// This function is a temporary function which has been added mainly for debugging purposes. Our
/// goal with this function is to validate how many times the DSC is not
Copy link
Member

Choose a reason for hiding this comment

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

The end of the sentence is missing.

@iambriccardo
Copy link
Member Author

Can't we just emit a sentry error whenever we have a missing dsc at a certain sample rate, instead of doing this semver dance with a hardocded list of SDKs?

We could, no strong opinions here. I didn't want to pollute our issues stream with this, since it might be very noisy. @jjbayer what do you think?

@iambriccardo iambriccardo requested a review from Dav1dde May 10, 2024 10:05
return true;
}

false
Copy link
Member Author

Choose a reason for hiding this comment

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

Since I wanted easier testability of the function, I returned a bool here.

Copy link
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

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

This is intended as a temporary metric right?

..Default::default()
});

let Some(sdk_name) = should_have_dsc(&event) else {
Copy link
Member

Choose a reason for hiding this comment

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

nit: just use unwrap here

should_have_dsc = "true"
);
}
_ => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: use None

@iambriccardo iambriccardo merged commit badf2eb into master May 21, 2024
22 checks passed
@iambriccardo iambriccardo deleted the riccardo/feat/track-dsc-creation branch May 21, 2024 09:13
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.

Investigate how many envelopes have no DSC
4 participants