Skip to content

Commit 84bf981

Browse files
authored
Add Continuous Profiling support (v8) (#3710)
* added IContinuousProfiler and implementations * made AndroidProfiler's executor nullable, as timeout will be handled differently for continuous profiling Change payload for Continuous Profiling v8 (p2) (#3711) * added profile_chunk envelope create * added IHub.captureProfileChunk and ISentryClient.captureProfileChunk * added profilerId and chunkId reset logic to AndroidContinuousProfiler * added absolute timestamps to ProfileMeasurementValue * added ProfileContext to Contexts * removed timestampMillis from MemoryCollectionData and CpuCollectionData, now it uses timestamp.nanotime() to achieve same result * continuous profiler doesn't stop anymore when an error occurs, but continue scheduling restart Instantiate continuous profiling v8 (p3) (#3725) * added profile context to SentryTracer * removed isProfilingEnabled from AndroidContinuousProfiler, as it's useless * added continuous profiler to SentryOptions * added DefaultTransactionPerformanceCollector to AndroidContinuousProfiler * updated DefaultTransactionPerformanceCollector to work with string ids other than transactions * fixed ProfileChunk measurements being modifiable from other code * added thread id and name to SpanContext.data * added profiler_id to span data * close continuous profiler on scopes close * renamed TransactionPerformanceCollector to CompositePerformanceCollector * added SpanContext.data ser/deser Handle App Start Continuous Profiling v8 (p4) (#3730) * create app start continuous profiler instead of transaction profiler, based on config * updated SentryAppStartProfilingOptions with isContinuousProfilingEnabled flag * updated SentryOptions with isContinuousProfilingEnabled() method * cut profiler setup out in a specific function to improve readability of AndroidOptionsInitializer Add new APIs for Continuous Profiling v8 (p5) (#3844) * AndroidContinuousProfiler now retrieve the scopes on start() * removed profilesSampleRate from sample app to enable continuous profiling * added Sentry.startProfiler and Sentry.stopProfiler APIs Add rate limit for Continuous Profiling v8 (p6) (#3926) * continuous profiler now doesn't start if offline or rate limited * continuous profiler stops when rate limited * continuous profiler prevents sending chunks after being closed * added profile_chunk rate limit * continuous profiler now reset its id when rate limited or offline Add continuousProfilesSampleRate (#4013) * added SentryOptions.continuousProfilesSampleRate * now continuous profiling is disabled if continuousProfilesSampleRate is 0 * profiles directory is created when continuous profiling is enabled, too * continuous profiling decision is passed to SentryAppStartProfilingOptions * app start continuous profiling is sampled, too Wrap up continuous profiling (#4069) * Set continuousProfilesSampleRate and startProfiler() and stopProfiler() as experimental * Added chunk start timestamp to ProfileChunk * increased continuous profiling chunk duration to 1 minute Change continuous profiling to session sample rate (#4180) * Moved setContinuousProfilesSampleRate into ExperimentalOptions * increased chunk duration to 1 minute * replaced continuousProfilesSampleRate with profileSessionSampleRate (Default null) * sample rate is now evaluated inside AndroidContinuousProfiler and every time a session finishes Rename continuous profiling APIs (#4182) * renamed Sentry.startProfiler with Sentry.startProfileSession and Sentry.stopProfiler with Sentry.stopProfileSession Add continuous profiling ProfileLifecycle (#4202) * Added ProfileLifecycle * Sentry.startProfileSession() will work only in MANUAL mode * Tracer start will start profiler only in TRACE mode * Tracer and spans now attach profilerId only when sampled Add Continuous Profiling isStartProfilerOnAppStart option (#4226) * added isStartProfilerOnAppStart experimental option
1 parent 64d302b commit 84bf981

File tree

117 files changed

+4630
-351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+4630
-351
lines changed

CHANGELOG.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,50 @@
55
### Features
66

77
- Add native stack frame address information and debug image metadata to ANR events ([#4061](https://github.com/getsentry/sentry-java/pull/4061))
8-
- This enables symbolication for stripped native code in ANRs
8+
- This enables symbolication for stripped native code in ANRs
9+
- Add Continuous Profiling Support ([#3710](https://github.com/getsentry/sentry-java/pull/3710))
10+
11+
To enable Continuous Profiling use the `Sentry.startProfileSession` and `Sentry.stopProfileSession` experimental APIs. Sampling rate can be set through `options.profileSessionSampleRate`, which defaults to null (disabled).
12+
Note: Both `options.profilesSampler` and `options.profilesSampleRate` must **not** be set to enable Continuous Profiling.
13+
14+
```java
15+
import io.sentry.ProfileLifecycle;
16+
import io.sentry.android.core.SentryAndroid;
17+
18+
SentryAndroid.init(context) { options ->
19+
20+
// Currently under experimental options:
21+
options.getExperimental().setProfileSessionSampleRate(1.0);
22+
// In manual mode, you need to start and stop the profiler manually using Sentry.startProfileSession and Sentry.stopProfileSession
23+
// In trace mode, the profiler will start and stop automatically whenever a sampled trace starts and finishes
24+
options.getExperimental().setProfileLifecycle(ProfileLifecycle.MANUAL);
25+
}
26+
// Start profiling
27+
Sentry.startProfileSession();
28+
29+
// After all profiling is done, stop the profiler. Profiles can last indefinitely if not stopped.
30+
Sentry.stopProfileSession();
31+
```
32+
```kotlin
33+
import io.sentry.ProfileLifecycle
34+
import io.sentry.android.core.SentryAndroid
35+
36+
SentryAndroid.init(context) { options ->
37+
38+
// Currently under experimental options:
39+
options.experimental.profileSessionSampleRate = 1.0
40+
// In manual mode, you need to start and stop the profiler manually using Sentry.startProfileSession and Sentry.stopProfileSession
41+
// In trace mode, the profiler will start and stop automatically whenever a sampled trace starts and finishes
42+
options.experimental.profileLifecycle = ProfileLifecycle.MANUAL
43+
}
44+
// Start profiling
45+
Sentry.startProfileSession()
46+
47+
// After all profiling is done, stop the profiler. Profiles can last indefinitely if not stopped.
48+
Sentry.stopProfileSession()
49+
```
50+
51+
To learn more visit [Sentry's Continuous Profiling](https://docs.sentry.io/product/explore/profiling/transaction-vs-continuous-profiling/#continuous-profiling-mode) documentation page.
952

1053
### Fixes
1154

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Mon Mar 17 13:40:54 CET 2025
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
34
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip

sentry-android-core/api/sentry-android-core.api

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ public final class io/sentry/android/core/ActivityLifecycleIntegration : android
4040
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
4141
}
4242

43+
public class io/sentry/android/core/AndroidContinuousProfiler : io/sentry/IContinuousProfiler, io/sentry/transport/RateLimiter$IRateLimitObserver {
44+
public fun <init> (Lio/sentry/android/core/BuildInfoProvider;Lio/sentry/android/core/internal/util/SentryFrameMetricsCollector;Lio/sentry/ILogger;Ljava/lang/String;ILio/sentry/ISentryExecutorService;)V
45+
public fun close ()V
46+
public fun getProfilerId ()Lio/sentry/protocol/SentryId;
47+
public fun getRootSpanCounter ()I
48+
public fun isRunning ()Z
49+
public fun onRateLimitChanged (Lio/sentry/transport/RateLimiter;)V
50+
public fun reevaluateSampling ()V
51+
public fun startProfileSession (Lio/sentry/ProfileLifecycle;Lio/sentry/TracesSampler;)V
52+
public fun stopProfileSession (Lio/sentry/ProfileLifecycle;)V
53+
}
54+
4355
public final class io/sentry/android/core/AndroidCpuCollector : io/sentry/IPerformanceSnapshotCollector {
4456
public fun <init> (Lio/sentry/ILogger;)V
4557
public fun collect (Lio/sentry/PerformanceCollectionData;)V
@@ -460,6 +472,7 @@ public class io/sentry/android/core/performance/AppStartMetrics : io/sentry/andr
460472
public fun clear ()V
461473
public fun createProcessInitSpan ()Lio/sentry/android/core/performance/TimeSpan;
462474
public fun getActivityLifecycleTimeSpans ()Ljava/util/List;
475+
public fun getAppStartContinuousProfiler ()Lio/sentry/IContinuousProfiler;
463476
public fun getAppStartProfiler ()Lio/sentry/ITransactionProfiler;
464477
public fun getAppStartSamplingDecision ()Lio/sentry/TracesSamplingDecision;
465478
public fun getAppStartTimeSpan ()Lio/sentry/android/core/performance/TimeSpan;
@@ -481,6 +494,7 @@ public class io/sentry/android/core/performance/AppStartMetrics : io/sentry/andr
481494
public static fun onContentProviderPostCreate (Landroid/content/ContentProvider;)V
482495
public fun registerLifecycleCallbacks (Landroid/app/Application;)V
483496
public fun setAppLaunchedInForeground (Z)V
497+
public fun setAppStartContinuousProfiler (Lio/sentry/IContinuousProfiler;)V
484498
public fun setAppStartProfiler (Lio/sentry/ITransactionProfiler;)V
485499
public fun setAppStartSamplingDecision (Lio/sentry/TracesSamplingDecision;)V
486500
public fun setAppStartType (Lio/sentry/android/core/performance/AppStartMetrics$AppStartType;)V

0 commit comments

Comments
 (0)