Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

feat(profiling): add profilesSampler #109

Merged
merged 4 commits into from
Mar 10, 2023
Merged

Conversation

JonasBa
Copy link
Member

@JonasBa JonasBa commented Mar 9, 2023

Add profilesSampler method with similar functionality as tracesSampler. If profilesSampler is set, prefer it's outcome vs profilingSampleRate

@JonasBa JonasBa requested a review from Zylphrex March 9, 2023 15:21
}

// if the function returned 0 (or false), or if `profileSampleRate` is 0, it's a sign the profile should be dropped
if (!profilesSampleRate) {
Copy link
Member

Choose a reason for hiding this comment

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

Does this case need to exist? It gets handled by the if (!sampled) check below 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.

I think so, at least the tracing SDK seems to do this + the reasons are subtly different. The first check checks if profilesSampleRate was 0 or inherited 0 and second check checks if we are discarding as a consequence of the dice roll.

Comment on lines 64 to 65
} else if (customSamplingContext && customSamplingContext['parentSampled'] !== undefined) {
profilesSampleRate = customSamplingContext['parentSampled'];
Copy link
Member

Choose a reason for hiding this comment

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

Is this the sampling decision on the parent transaction? If that is the case, you're effectively saying sample all transactions which I don't think is the intention here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes correct, I took this logic off tracing, but I could not find the actual reasoning for inheriting this from getsentry/sentry-javascript#3068

Copy link
Member

Choose a reason for hiding this comment

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

So if I'm correct, then the reason for this is because for distributed tracing, when the initial transaction is sampled, we would want the entire trace to be sampled. i.e. the browser page load transaction is sampled, so we want to propagate that sampling decision to all the API calls so that those transactions are also sampled.

I don't think this is what we want to do in profiling, at least not right now. Because it's effectively ignoring the profile samples rate and saying profile 100% of transactions. Now, this may be something we want but it's definitely not something we've discussed since we've been focused on profiling individual platforms not if we want to profile the entire trace.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahhhhh, ok. I was not sure what the use case was, thanks for explaining! I will remove it for now, but like you mentioned, this may be something we want to actually support and is worth bringing up to the team.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, if we are to implement this inheriting, we should not inherit the trace's sampling decision. We would want to do something like pass a profiling sampling decision from the root transaction alongside the transaction's sampling decision so that the whole trace is profile but only when the root transaction is profiled.

But again, this is something we should discuss before moving forwards.

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, we would need to mark the profile sample decision and inherit that - I just commented out the code and the skipped the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Zylphrex I just remove the code, no reason to keep it as it's easy to add back whenever.

@JonasBa JonasBa merged commit 8d93776 into main Mar 10, 2023
@JonasBa JonasBa deleted the jb/feat/add-profiles-sampler branch March 10, 2023 16:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants