@@ -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 /**
0 commit comments