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

Add profilesSampleRate and profileSampler for Android sdk #2184

Merged
merged 8 commits into from Aug 5, 2022

Conversation

stefanosiano
Copy link
Member

@stefanosiano stefanosiano commented Jul 25, 2022

📜 Description

I added the profilesSampleRate and profileSampler options for the Android sdk.
The profilingEnabled options has been deprecated, and its usage changed to "setProfilesSampleRate(1.0 or null)". Also, it is overridden by the profilesSampleRate option.

💡 Motivation and Context

We are reaching the profiling open beta stage.
We want to provide users a way to reduce the number of profiles sent to Sentry, in the same way we do with transactions.
To be consistent with transactions, we will provide the profilesSampleRate and profileSampler options.

💚 How did you test it?

I added some unit tests

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • No breaking changes

🔮 Next steps

…to decide sampling)

deprecated SentryOptions.setProfilingEnabled()
updated internal code and unit tests to change from SentryOptions.setProfilingEnabled() to SentryOptions.setProfilesSampleRate()
updated tests to use setProfilesSampleRate instead of setProfilingEnabled
TracesSamplingDecision now includes profiles sampling decision
@codecov-commenter
Copy link

codecov-commenter commented Jul 25, 2022

Codecov Report

Merging #2184 (88ceb6d) into main (eba572a) will increase coverage by 0.00%.
The diff coverage is 87.30%.

@@            Coverage Diff            @@
##               main    #2184   +/-   ##
=========================================
  Coverage     80.90%   80.90%           
- Complexity     3313     3343   +30     
=========================================
  Files           236      236           
  Lines         12155    12200   +45     
  Branches       1616     1624    +8     
=========================================
+ Hits           9834     9871   +37     
- Misses         1725     1729    +4     
- Partials        596      600    +4     
Impacted Files Coverage Δ
...ry/src/main/java/io/sentry/TransactionContext.java 76.47% <33.33%> (-9.25%) ⬇️
sentry/src/main/java/io/sentry/SpanContext.java 82.19% <55.55%> (-1.75%) ⬇️
...entry/src/main/java/io/sentry/ExternalOptions.java 100.00% <100.00%> (ø)
sentry/src/main/java/io/sentry/Hub.java 76.41% <100.00%> (ø)
...entry/src/main/java/io/sentry/NoOpTransaction.java 27.27% <100.00%> (+2.27%) ⬆️
sentry/src/main/java/io/sentry/SentryOptions.java 83.07% <100.00%> (+0.49%) ⬆️
sentry/src/main/java/io/sentry/SentryTracer.java 91.28% <100.00%> (-0.08%) ⬇️
sentry/src/main/java/io/sentry/Span.java 100.00% <100.00%> (ø)
sentry/src/main/java/io/sentry/TracesSampler.java 100.00% <100.00%> (ø)
...rc/main/java/io/sentry/TracesSamplingDecision.java 100.00% <100.00%> (ø)
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

stefanosiano and others added 2 commits July 25, 2022 13:31
updated tests to use setProfilesSampleRate instead of setProfilingEnabled
TracesSamplingDecision now includes profiles sampling decision
@stefanosiano stefanosiano marked this pull request as ready for review July 25, 2022 11:33
@@ -1500,16 +1511,65 @@ public void setTransactionProfiler(final @Nullable ITransactionProfiler transact
* @return if profiling is enabled for transactions.
*/
public boolean isProfilingEnabled() {
return profilingEnabled;
return (getProfilesSampleRate() != null && getProfilesSampleRate() > 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't check > 0 for isTracingEnabled at least.
Do we need it 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.

well, if the sample rate is 0 and there's no sampler set, we'd still initialize the profile, even if in reality it will never be used

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah for profiling maybe it's better to keep with this check.
For transactions, we actually need it, because 0 is enabled and it propagates transactions that come from the backend and inherits the sampling decision from the parent.
If sampling should be the case, then removing the > 0 check makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

the logic of profiles sampling mimics the transaction sampling, including the parent decision. But we don't get profiles from the backend. Should we consider the case for consistency? Initializing the profiler is quick anyway, and the option already says that null should be used to disable it

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a business decision, so I can't tell you what makes more sense for profiling.

@@ -15,7 +15,7 @@ public static boolean isValidSampleRate(@Nullable Double sampleRate, boolean all
return allowNull;
}

return !(sampleRate.isNaN() || (sampleRate > 1.0 || sampleRate <= 0.0));
return !(sampleRate.isNaN() || sampleRate > 1.0 || sampleRate <= 0.0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently a new private method that takes a Double and do this check would avoid code duplication, See this method and isValidTracesSampleRate.

Copy link
Member Author

Choose a reason for hiding this comment

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

may i rename isValidTracesSampleRate to isValidTracesOrProfilesSampleRate and use just one function, as they do basically the same thing?

Copy link
Contributor

Choose a reason for hiding this comment

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

isValidSampleRate should be enough IMO, as long as both functions do the same.

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, but isValidSampleRate already exists and does the same check, expect the rate cannot be 0.0

Copy link
Contributor

Choose a reason for hiding this comment

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

Then your call.

stefanosiano and others added 3 commits August 3, 2022 18:28
added profiling activity to the sample app, with possibility to set time and number of background threads to get an idea of size of: profiling trace file, envelope item and compressed envelope item
enabled profiling in the sample app
@stefanosiano stefanosiano merged commit 24d5c4f into main Aug 5, 2022
@stefanosiano stefanosiano deleted the feat/profiling-sample-rate branch August 5, 2022 14:34
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

4 participants