Skip to content

Commit f44cfb7

Browse files
authored
Continuous Profiling - Out of Experimental (#4310)
* moved continuous profiling out of ExperimentalOptions back into SentryOptions
1 parent 6f23a76 commit f44cfb7

File tree

13 files changed

+121
-143
lines changed

13 files changed

+121
-143
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Continuous Profiling - Out of Experimental ([#4310](https://github.com/getsentry/sentry-java/pull/4310))
8+
39
## 8.6.0
410

511
### Behavioral Changes

sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static void applyMetadata(
335335
final double profileSessionSampleRate =
336336
readDouble(metadata, logger, PROFILE_SESSION_SAMPLE_RATE);
337337
if (profileSessionSampleRate != -1) {
338-
options.getExperimental().setProfileSessionSampleRate(profileSessionSampleRate);
338+
options.setProfileSessionSampleRate(profileSessionSampleRate);
339339
}
340340
}
341341

@@ -346,20 +346,16 @@ static void applyMetadata(
346346
PROFILE_LIFECYCLE,
347347
options.getProfileLifecycle().name().toLowerCase(Locale.ROOT));
348348
if (profileLifecycle != null) {
349-
options
350-
.getExperimental()
351-
.setProfileLifecycle(
352-
ProfileLifecycle.valueOf(profileLifecycle.toUpperCase(Locale.ROOT)));
349+
options.setProfileLifecycle(
350+
ProfileLifecycle.valueOf(profileLifecycle.toUpperCase(Locale.ROOT)));
353351
}
354352

355-
options
356-
.getExperimental()
357-
.setStartProfilerOnAppStart(
358-
readBool(
359-
metadata,
360-
logger,
361-
PROFILER_START_ON_APP_START,
362-
options.isStartProfilerOnAppStart()));
353+
options.setStartProfilerOnAppStart(
354+
readBool(
355+
metadata,
356+
logger,
357+
PROFILER_START_ON_APP_START,
358+
options.isStartProfilerOnAppStart()));
363359

364360
options.setEnableUserInteractionTracing(
365361
readBool(metadata, logger, TRACES_UI_ENABLE, options.isEnableUserInteractionTracing()));

sentry-android-core/src/main/java/io/sentry/android/core/SentryPerformanceProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ private void createAndStartContinuousProfiler(
175175
logger.log(SentryLevel.DEBUG, "App start continuous profiling started.");
176176
SentryOptions sentryOptions = SentryOptions.empty();
177177
// Let's fake a sampler to accept the sampling decision that was calculated on last run
178-
sentryOptions
179-
.getExperimental()
180-
.setProfileSessionSampleRate(profilingOptions.isContinuousProfileSampled() ? 1.0 : 0.0);
178+
sentryOptions.setProfileSessionSampleRate(
179+
profilingOptions.isContinuousProfileSampled() ? 1.0 : 0.0);
181180
appStartContinuousProfiler.startProfiler(
182181
profilingOptions.getProfileLifecycle(), new TracesSampler(sentryOptions));
183182
}

sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ class ManifestMetadataReaderTest {
826826
fun `applyMetadata does not override profileSessionSampleRate from options`() {
827827
// Arrange
828828
val expectedSampleRate = 0.99f
829-
fixture.options.experimental.profileSessionSampleRate = expectedSampleRate.toDouble()
829+
fixture.options.profileSessionSampleRate = expectedSampleRate.toDouble()
830830
val bundle = bundleOf(ManifestMetadataReader.PROFILE_SESSION_SAMPLE_RATE to 0.1f)
831831
val context = fixture.getContext(metaData = bundle)
832832

sentry/api/sentry.api

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,6 @@ public abstract interface class io/sentry/EventProcessor {
458458

459459
public final class io/sentry/ExperimentalOptions {
460460
public fun <init> (ZLio/sentry/protocol/SdkVersion;)V
461-
public fun getProfileLifecycle ()Lio/sentry/ProfileLifecycle;
462-
public fun getProfileSessionSampleRate ()Ljava/lang/Double;
463-
public fun isStartProfilerOnAppStart ()Z
464-
public fun setProfileLifecycle (Lio/sentry/ProfileLifecycle;)V
465-
public fun setProfileSessionSampleRate (Ljava/lang/Double;)V
466-
public fun setStartProfilerOnAppStart (Z)V
467461
}
468462

469463
public final class io/sentry/ExternalOptions {
@@ -3222,6 +3216,8 @@ public class io/sentry/SentryOptions {
32223216
public fun setModulesLoader (Lio/sentry/internal/modules/IModulesLoader;)V
32233217
public fun setOpenTelemetryMode (Lio/sentry/SentryOpenTelemetryMode;)V
32243218
public fun setPrintUncaughtStackTrace (Z)V
3219+
public fun setProfileLifecycle (Lio/sentry/ProfileLifecycle;)V
3220+
public fun setProfileSessionSampleRate (Ljava/lang/Double;)V
32253221
public fun setProfilesSampleRate (Ljava/lang/Double;)V
32263222
public fun setProfilesSampler (Lio/sentry/SentryOptions$ProfilesSamplerCallback;)V
32273223
public fun setProfilingTracesHz (I)V
@@ -3245,6 +3241,7 @@ public class io/sentry/SentryOptions {
32453241
public fun setSpanFactory (Lio/sentry/ISpanFactory;)V
32463242
public fun setSpotlightConnectionUrl (Ljava/lang/String;)V
32473243
public fun setSslSocketFactory (Ljavax/net/ssl/SSLSocketFactory;)V
3244+
public fun setStartProfilerOnAppStart (Z)V
32483245
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
32493246
public fun setThreadChecker (Lio/sentry/util/thread/IThreadChecker;)V
32503247
public fun setTraceOptionsRequests (Z)V
Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package io.sentry;
22

33
import io.sentry.protocol.SdkVersion;
4-
import io.sentry.util.SampleRateUtils;
5-
import org.jetbrains.annotations.ApiStatus;
6-
import org.jetbrains.annotations.NotNull;
74
import org.jetbrains.annotations.Nullable;
85

96
/**
@@ -14,74 +11,5 @@
1411
*/
1512
public final class ExperimentalOptions {
1613

17-
/**
18-
* Indicates the percentage in which the profiles for the session will be created. Specifying 0
19-
* means never, 1.0 means always. The value needs to be >= 0.0 and <= 1.0 The default is null
20-
* (disabled).
21-
*/
22-
private @Nullable Double profileSessionSampleRate;
23-
24-
/**
25-
* Whether the profiling lifecycle is controlled manually or based on the trace lifecycle.
26-
* Defaults to {@link ProfileLifecycle#MANUAL}.
27-
*/
28-
private @NotNull ProfileLifecycle profileLifecycle = ProfileLifecycle.MANUAL;
29-
30-
/**
31-
* Whether profiling can automatically be started as early as possible during the app lifecycle,
32-
* to capture more of app startup. If {@link ExperimentalOptions#profileLifecycle} is {@link
33-
* ProfileLifecycle#MANUAL} Profiling is started automatically on startup and stopProfiler must be
34-
* called manually whenever the app startup is completed If {@link
35-
* ExperimentalOptions#profileLifecycle} is {@link ProfileLifecycle#TRACE} Profiling is started
36-
* automatically on startup, and will automatically be stopped when the root span that is
37-
* associated with app startup ends
38-
*/
39-
private boolean startProfilerOnAppStart = false;
40-
4114
public ExperimentalOptions(final boolean empty, final @Nullable SdkVersion sdkVersion) {}
42-
43-
/**
44-
* Returns whether the profiling cycle is controlled manually or based on the trace lifecycle.
45-
* Defaults to {@link ProfileLifecycle#MANUAL}.
46-
*
47-
* @return the profile lifecycle
48-
*/
49-
@ApiStatus.Experimental
50-
public @NotNull ProfileLifecycle getProfileLifecycle() {
51-
return profileLifecycle;
52-
}
53-
54-
/** Sets the profiling lifecycle. */
55-
@ApiStatus.Experimental
56-
public void setProfileLifecycle(final @NotNull ProfileLifecycle profileLifecycle) {
57-
// TODO (when moved to SentryOptions): we should log a message if the user sets this to TRACE
58-
// and tracing is disabled
59-
this.profileLifecycle = profileLifecycle;
60-
}
61-
62-
@ApiStatus.Experimental
63-
public @Nullable Double getProfileSessionSampleRate() {
64-
return profileSessionSampleRate;
65-
}
66-
67-
@ApiStatus.Experimental
68-
public void setProfileSessionSampleRate(final @Nullable Double profileSessionSampleRate) {
69-
if (!SampleRateUtils.isValidContinuousProfilesSampleRate(profileSessionSampleRate)) {
70-
throw new IllegalArgumentException(
71-
"The value "
72-
+ profileSessionSampleRate
73-
+ " is not valid. Use values between 0.0 and 1.0.");
74-
}
75-
this.profileSessionSampleRate = profileSessionSampleRate;
76-
}
77-
78-
@ApiStatus.Experimental
79-
public boolean isStartProfilerOnAppStart() {
80-
return startProfilerOnAppStart;
81-
}
82-
83-
@ApiStatus.Experimental
84-
public void setStartProfilerOnAppStart(boolean startProfilerOnAppStart) {
85-
this.startProfilerOnAppStart = startProfilerOnAppStart;
86-
}
8715
}

sentry/src/main/java/io/sentry/SentryOptions.java

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,30 @@ public class SentryOptions {
542542
@ApiStatus.Experimental private boolean captureOpenTelemetryEvents = false;
543543

544544
private @NotNull IVersionDetector versionDetector = NoopVersionDetector.getInstance();
545+
546+
/**
547+
* Indicates the percentage in which the profiles for the session will be created. Specifying 0
548+
* means never, 1.0 means always. The value needs to be >= 0.0 and <= 1.0 The default is null
549+
* (disabled).
550+
*/
551+
private @Nullable Double profileSessionSampleRate;
552+
553+
/**
554+
* Whether the profiling lifecycle is controlled manually or based on the trace lifecycle.
555+
* Defaults to {@link ProfileLifecycle#MANUAL}.
556+
*/
557+
private @NotNull ProfileLifecycle profileLifecycle = ProfileLifecycle.MANUAL;
558+
559+
/**
560+
* Whether profiling can automatically be started as early as possible during the app lifecycle,
561+
* to capture more of app startup. If {@link SentryOptions#profileLifecycle} is {@link
562+
* ProfileLifecycle#MANUAL} Profiling is started automatically on startup and stopProfiler must be
563+
* called manually whenever the app startup is completed If {@link SentryOptions#profileLifecycle}
564+
* is {@link ProfileLifecycle#TRACE} Profiling is started automatically on startup, and will
565+
* automatically be stopped when the root span that is associated with app startup ends
566+
*/
567+
private boolean startProfilerOnAppStart = false;
568+
545569
/**
546570
* Adds an event processor
547571
*
@@ -1821,7 +1845,6 @@ public void setTransactionProfiler(final @Nullable ITransactionProfiler transact
18211845
*
18221846
* @return the continuous profiler.
18231847
*/
1824-
@ApiStatus.Experimental
18251848
public @NotNull IContinuousProfiler getContinuousProfiler() {
18261849
return continuousProfiler;
18271850
}
@@ -1831,7 +1854,6 @@ public void setTransactionProfiler(final @Nullable ITransactionProfiler transact
18311854
*
18321855
* @param continuousProfiler - the continuous profiler
18331856
*/
1834-
@ApiStatus.Experimental
18351857
public void setContinuousProfiler(final @Nullable IContinuousProfiler continuousProfiler) {
18361858
// We allow to set the profiler only if it was not set before, and we don't allow to unset it.
18371859
if (this.continuousProfiler == NoOpContinuousProfiler.getInstance()
@@ -1859,8 +1881,8 @@ public boolean isProfilingEnabled() {
18591881
public boolean isContinuousProfilingEnabled() {
18601882
return profilesSampleRate == null
18611883
&& profilesSampler == null
1862-
&& experimental.getProfileSessionSampleRate() != null
1863-
&& experimental.getProfileSessionSampleRate() > 0;
1884+
&& profileSessionSampleRate != null
1885+
&& profileSessionSampleRate > 0;
18641886
}
18651887

18661888
/**
@@ -1914,9 +1936,23 @@ public void setProfilesSampleRate(final @Nullable Double profilesSampleRate) {
19141936
*
19151937
* @return the sample rate
19161938
*/
1917-
@ApiStatus.Experimental
19181939
public @Nullable Double getProfileSessionSampleRate() {
1919-
return experimental.getProfileSessionSampleRate();
1940+
return profileSessionSampleRate;
1941+
}
1942+
1943+
/**
1944+
* Set the session sample rate. Default is null (disabled). ProfilesSampleRate takes precedence
1945+
* over this. To enable continuous profiling, don't set profilesSampleRate or profilesSampler, or
1946+
* set them to null.
1947+
*/
1948+
public void setProfileSessionSampleRate(final @Nullable Double profileSessionSampleRate) {
1949+
if (!SampleRateUtils.isValidContinuousProfilesSampleRate(profileSessionSampleRate)) {
1950+
throw new IllegalArgumentException(
1951+
"The value "
1952+
+ profileSessionSampleRate
1953+
+ " is not valid. Use values between 0.0 and 1.0.");
1954+
}
1955+
this.profileSessionSampleRate = profileSessionSampleRate;
19201956
}
19211957

19221958
/**
@@ -1925,17 +1961,33 @@ public void setProfilesSampleRate(final @Nullable Double profilesSampleRate) {
19251961
*
19261962
* @return the profile lifecycle
19271963
*/
1928-
@ApiStatus.Experimental
19291964
public @NotNull ProfileLifecycle getProfileLifecycle() {
1930-
return experimental.getProfileLifecycle();
1965+
return profileLifecycle;
1966+
}
1967+
1968+
/** Sets the profiling lifecycle. */
1969+
public void setProfileLifecycle(final @NotNull ProfileLifecycle profileLifecycle) {
1970+
this.profileLifecycle = profileLifecycle;
1971+
if (profileLifecycle == ProfileLifecycle.TRACE && !isTracingEnabled()) {
1972+
logger.log(
1973+
SentryLevel.WARNING,
1974+
"Profiling lifecycle is set to TRACE but tracing is disabled. "
1975+
+ "Profiling will not be started automatically.");
1976+
}
19311977
}
19321978

19331979
/**
19341980
* Whether profiling can automatically be started as early as possible during the app lifecycle.
19351981
*/
1936-
@ApiStatus.Experimental
19371982
public boolean isStartProfilerOnAppStart() {
1938-
return experimental.isStartProfilerOnAppStart();
1983+
return startProfilerOnAppStart;
1984+
}
1985+
1986+
/**
1987+
* Set if profiling can automatically be started as early as possible during the app lifecycle.
1988+
*/
1989+
public void setStartProfilerOnAppStart(final boolean startProfilerOnAppStart) {
1990+
this.startProfilerOnAppStart = startProfilerOnAppStart;
19391991
}
19401992

19411993
/**

sentry/src/test/java/io/sentry/ScopeTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class ScopeTest {
398398
val options = SentryOptions().apply {
399399
release = "0.0.1"
400400
setContinuousProfiler(profiler)
401-
experimental.profileSessionSampleRate = 1.0
401+
profileSessionSampleRate = 1.0
402402
}
403403

404404
val scope = Scope(options)
@@ -419,7 +419,7 @@ class ScopeTest {
419419
val options = SentryOptions().apply {
420420
release = "0.0.1"
421421
setContinuousProfiler(profiler)
422-
experimental.profileSessionSampleRate = 1.0
422+
profileSessionSampleRate = 1.0
423423
}
424424

425425
val scope = Scope(options)
@@ -435,7 +435,7 @@ class ScopeTest {
435435
val options = SentryOptions().apply {
436436
release = "0.0.1"
437437
setContinuousProfiler(profiler)
438-
experimental.profileSessionSampleRate = 1.0
438+
profileSessionSampleRate = 1.0
439439
}
440440

441441
val scope = Scope(options)

0 commit comments

Comments
 (0)