Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

- Add Continuous Profiling Support ([#3710](https://github.com/getsentry/sentry-java/pull/3710))

To enable Continuous Profiling use the `Sentry.startProfiler` and `Sentry.stopProfiler` experimental APIs. Sampling rate can be set through `options.continuousProfilesSampleRate`, which defaults to null (disabled).
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).
Note: Both `options.profilesSampler` and `options.profilesSampleRate` must **not** be set to enable Continuous Profiling.

```java
Expand All @@ -18,10 +18,10 @@
options.getExperimental().setProfileSessionSampleRate(1.0);
}
// Start profiling
Sentry.startProfiler();
Sentry.startProfileSession();

// After all profiling is done, stop the profiler. Profiles can last indefinitely if not stopped.
Sentry.stopProfiler();
Sentry.stopProfileSession();
```
```kotlin
import io.sentry.android.core.SentryAndroid
Expand All @@ -32,10 +32,10 @@
options.experimental.profileSessionSampleRate = 1.0
}
// Start profiling
Sentry.startProfiler()
Sentry.startProfileSession()

// After all profiling is done, stop the profiler. Profiles can last indefinitely if not stopped.
Sentry.stopProfiler()
Sentry.stopProfileSession()
```

To learn more visit [Sentry's Continuous Profiling](https://docs.sentry.io/product/explore/profiling/transaction-vs-continuous-profiling/#continuous-profiling-mode) documentation page.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class MyApplication extends Application {

@Override
public void onCreate() {
Sentry.startProfiler();
Sentry.startProfileSession();
strictMode();
super.onCreate();

Expand Down
32 changes: 16 additions & 16 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,10 @@ public final class io/sentry/HubAdapter : io/sentry/IHub {
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setTransaction (Ljava/lang/String;)V
public fun setUser (Lio/sentry/protocol/User;)V
public fun startProfiler ()V
public fun startProfileSession ()V
public fun startSession ()V
public fun startTransaction (Lio/sentry/TransactionContext;Lio/sentry/TransactionOptions;)Lio/sentry/ITransaction;
public fun stopProfiler ()V
public fun stopProfileSession ()V
public fun withIsolationScope (Lio/sentry/ScopeCallback;)V
public fun withScope (Lio/sentry/ScopeCallback;)V
}
Expand Down Expand Up @@ -692,10 +692,10 @@ public final class io/sentry/HubScopesWrapper : io/sentry/IHub {
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setTransaction (Ljava/lang/String;)V
public fun setUser (Lio/sentry/protocol/User;)V
public fun startProfiler ()V
public fun startProfileSession ()V
public fun startSession ()V
public fun startTransaction (Lio/sentry/TransactionContext;Lio/sentry/TransactionOptions;)Lio/sentry/ITransaction;
public fun stopProfiler ()V
public fun stopProfileSession ()V
public fun withIsolationScope (Lio/sentry/ScopeCallback;)V
public fun withScope (Lio/sentry/ScopeCallback;)V
}
Expand Down Expand Up @@ -931,13 +931,13 @@ public abstract interface class io/sentry/IScopes {
public abstract fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public abstract fun setTransaction (Ljava/lang/String;)V
public abstract fun setUser (Lio/sentry/protocol/User;)V
public abstract fun startProfiler ()V
public abstract fun startProfileSession ()V
public abstract fun startSession ()V
public fun startTransaction (Lio/sentry/TransactionContext;)Lio/sentry/ITransaction;
public abstract fun startTransaction (Lio/sentry/TransactionContext;Lio/sentry/TransactionOptions;)Lio/sentry/ITransaction;
public fun startTransaction (Ljava/lang/String;Ljava/lang/String;)Lio/sentry/ITransaction;
public fun startTransaction (Ljava/lang/String;Ljava/lang/String;Lio/sentry/TransactionOptions;)Lio/sentry/ITransaction;
public abstract fun stopProfiler ()V
public abstract fun stopProfileSession ()V
public abstract fun withIsolationScope (Lio/sentry/ScopeCallback;)V
public abstract fun withScope (Lio/sentry/ScopeCallback;)V
}
Expand Down Expand Up @@ -1478,10 +1478,10 @@ public final class io/sentry/NoOpHub : io/sentry/IHub {
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setTransaction (Ljava/lang/String;)V
public fun setUser (Lio/sentry/protocol/User;)V
public fun startProfiler ()V
public fun startProfileSession ()V
public fun startSession ()V
public fun startTransaction (Lio/sentry/TransactionContext;Lio/sentry/TransactionOptions;)Lio/sentry/ITransaction;
public fun stopProfiler ()V
public fun stopProfileSession ()V
public fun withIsolationScope (Lio/sentry/ScopeCallback;)V
public fun withScope (Lio/sentry/ScopeCallback;)V
}
Expand Down Expand Up @@ -1640,10 +1640,10 @@ public final class io/sentry/NoOpScopes : io/sentry/IScopes {
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setTransaction (Ljava/lang/String;)V
public fun setUser (Lio/sentry/protocol/User;)V
public fun startProfiler ()V
public fun startProfileSession ()V
public fun startSession ()V
public fun startTransaction (Lio/sentry/TransactionContext;Lio/sentry/TransactionOptions;)Lio/sentry/ITransaction;
public fun stopProfiler ()V
public fun stopProfileSession ()V
public fun withIsolationScope (Lio/sentry/ScopeCallback;)V
public fun withScope (Lio/sentry/ScopeCallback;)V
}
Expand Down Expand Up @@ -2298,10 +2298,10 @@ public final class io/sentry/Scopes : io/sentry/IScopes {
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setTransaction (Ljava/lang/String;)V
public fun setUser (Lio/sentry/protocol/User;)V
public fun startProfiler ()V
public fun startProfileSession ()V
public fun startSession ()V
public fun startTransaction (Lio/sentry/TransactionContext;Lio/sentry/TransactionOptions;)Lio/sentry/ITransaction;
public fun stopProfiler ()V
public fun stopProfileSession ()V
public fun withIsolationScope (Lio/sentry/ScopeCallback;)V
public fun withScope (Lio/sentry/ScopeCallback;)V
}
Expand Down Expand Up @@ -2365,10 +2365,10 @@ public final class io/sentry/ScopesAdapter : io/sentry/IScopes {
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setTransaction (Ljava/lang/String;)V
public fun setUser (Lio/sentry/protocol/User;)V
public fun startProfiler ()V
public fun startProfileSession ()V
public fun startSession ()V
public fun startTransaction (Lio/sentry/TransactionContext;Lio/sentry/TransactionOptions;)Lio/sentry/ITransaction;
public fun stopProfiler ()V
public fun stopProfileSession ()V
public fun withIsolationScope (Lio/sentry/ScopeCallback;)V
public fun withScope (Lio/sentry/ScopeCallback;)V
}
Expand Down Expand Up @@ -2471,14 +2471,14 @@ public final class io/sentry/Sentry {
public static fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public static fun setTransaction (Ljava/lang/String;)V
public static fun setUser (Lio/sentry/protocol/User;)V
public static fun startProfiler ()V
public static fun startProfileSession ()V
public static fun startSession ()V
public static fun startTransaction (Lio/sentry/TransactionContext;)Lio/sentry/ITransaction;
public static fun startTransaction (Lio/sentry/TransactionContext;Lio/sentry/TransactionOptions;)Lio/sentry/ITransaction;
public static fun startTransaction (Ljava/lang/String;Ljava/lang/String;)Lio/sentry/ITransaction;
public static fun startTransaction (Ljava/lang/String;Ljava/lang/String;Lio/sentry/TransactionOptions;)Lio/sentry/ITransaction;
public static fun startTransaction (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/sentry/TransactionOptions;)Lio/sentry/ITransaction;
public static fun stopProfiler ()V
public static fun stopProfileSession ()V
public static fun withIsolationScope (Lio/sentry/ScopeCallback;)V
public static fun withScope (Lio/sentry/ScopeCallback;)V
}
Expand Down
8 changes: 4 additions & 4 deletions sentry/src/main/java/io/sentry/HubAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ public boolean isAncestorOf(final @Nullable IScopes otherScopes) {
}

@Override
public void startProfiler() {
Sentry.startProfiler();
public void startProfileSession() {
Sentry.startProfileSession();
}

@Override
public void stopProfiler() {
Sentry.stopProfiler();
public void stopProfileSession() {
Sentry.stopProfileSession();
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions sentry/src/main/java/io/sentry/HubScopesWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ public boolean isAncestorOf(final @Nullable IScopes otherScopes) {
}

@Override
public void startProfiler() {
scopes.startProfiler();
public void startProfileSession() {
scopes.startProfileSession();
}

@Override
public void stopProfiler() {
scopes.stopProfiler();
public void stopProfileSession() {
scopes.stopProfileSession();
}

@ApiStatus.Internal
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/IScopes.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,9 @@ ITransaction startTransaction(
final @NotNull TransactionContext transactionContext,
final @NotNull TransactionOptions transactionOptions);

void startProfiler();
void startProfileSession();

void stopProfiler();
void stopProfileSession();

/**
* Associates {@link ISpan} and the transaction name with the {@link Throwable}. Used to determine
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/NoOpHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ public boolean isAncestorOf(@Nullable IScopes otherScopes) {
}

@Override
public void startProfiler() {}
public void startProfileSession() {}

@Override
public void stopProfiler() {}
public void stopProfileSession() {}

@Override
public void setSpanContext(
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/NoOpScopes.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ public boolean isAncestorOf(@Nullable IScopes otherScopes) {
}

@Override
public void startProfiler() {}
public void startProfileSession() {}

@Override
public void stopProfiler() {}
public void stopProfileSession() {}

@Override
public void setSpanContext(
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/Scopes.java
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ public void flush(long timeoutMillis) {
}

@Override
public void startProfiler() {
public void startProfileSession() {
if (getOptions().isContinuousProfilingEnabled()) {
getOptions().getContinuousProfiler().start(getOptions().getInternalTracesSampler());
} else if (getOptions().isProfilingEnabled()) {
Expand All @@ -937,7 +937,7 @@ public void startProfiler() {
}

@Override
public void stopProfiler() {
public void stopProfileSession() {
if (getOptions().isContinuousProfilingEnabled()) {
getOptions().getLogger().log(SentryLevel.DEBUG, "Stopped continuous Profiling.");
getOptions().getContinuousProfiler().stop();
Expand Down
8 changes: 4 additions & 4 deletions sentry/src/main/java/io/sentry/ScopesAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ public boolean isAncestorOf(final @Nullable IScopes otherScopes) {
}

@Override
public void startProfiler() {
Sentry.startProfiler();
public void startProfileSession() {
Sentry.startProfileSession();
}

@Override
public void stopProfiler() {
Sentry.stopProfiler();
public void stopProfileSession() {
Sentry.stopProfileSession();
}

@ApiStatus.Internal
Expand Down
8 changes: 4 additions & 4 deletions sentry/src/main/java/io/sentry/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -1052,14 +1052,14 @@ public static void endSession() {

/** Starts the continuous profiler, if enabled. */
@ApiStatus.Experimental
public static void startProfiler() {
getCurrentScopes().startProfiler();
public static void startProfileSession() {
getCurrentScopes().startProfileSession();
}

/** Stops the continuous profiler, if enabled. */
@ApiStatus.Experimental
public static void stopProfiler() {
getCurrentScopes().stopProfiler();
public static void stopProfileSession() {
getCurrentScopes().stopProfileSession();
}

/**
Expand Down
12 changes: 6 additions & 6 deletions sentry/src/test/java/io/sentry/HubAdapterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ class HubAdapterTest {
verify(scopes).reportFullyDisplayed()
}

@Test fun `startProfiler calls Hub`() {
HubAdapter.getInstance().startProfiler()
verify(scopes).startProfiler()
@Test fun `startProfileSession calls Hub`() {
HubAdapter.getInstance().startProfileSession()
verify(scopes).startProfileSession()
}

@Test fun `stopProfiler calls Hub`() {
HubAdapter.getInstance().stopProfiler()
verify(scopes).stopProfiler()
@Test fun `stopProfileSession calls Hub`() {
HubAdapter.getInstance().stopProfileSession()
verify(scopes).stopProfileSession()
}
}
4 changes: 2 additions & 2 deletions sentry/src/test/java/io/sentry/NoOpHubTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class NoOpHubTest {
}

@Test
fun `startProfiler doesnt throw`() = sut.startProfiler()
fun `startProfileSession doesnt throw`() = sut.startProfileSession()

@Test
fun `stopProfiler doesnt throw`() = sut.stopProfiler()
fun `stopProfileSession doesnt throw`() = sut.stopProfileSession()
}
12 changes: 6 additions & 6 deletions sentry/src/test/java/io/sentry/ScopesAdapterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ class ScopesAdapterTest {
verify(scopes).reportFullyDisplayed()
}

@Test fun `startProfiler calls Scopes`() {
ScopesAdapter.getInstance().startProfiler()
verify(scopes).startProfiler()
@Test fun `startProfileSession calls Scopes`() {
ScopesAdapter.getInstance().startProfileSession()
verify(scopes).startProfileSession()
}

@Test fun `stopProfiler calls Scopes`() {
ScopesAdapter.getInstance().stopProfiler()
verify(scopes).stopProfiler()
@Test fun `stopProfileSession calls Scopes`() {
ScopesAdapter.getInstance().stopProfileSession()
verify(scopes).stopProfileSession()
}
}
16 changes: 8 additions & 8 deletions sentry/src/test/java/io/sentry/ScopesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2162,18 +2162,18 @@ class ScopesTest {
}

@Test
fun `startProfiler starts the continuous profiler`() {
fun `startProfileSession starts the continuous profiler`() {
val profiler = mock<IContinuousProfiler>()
val scopes = generateScopes {
it.setContinuousProfiler(profiler)
it.experimental.profileSessionSampleRate = 1.0
}
scopes.startProfiler()
scopes.startProfileSession()
verify(profiler).start(any())
}

@Test
fun `startProfiler logs instructions if continuous profiling is disabled`() {
fun `startProfileSession logs instructions if continuous profiling is disabled`() {
val profiler = mock<IContinuousProfiler>()
val logger = mock<ILogger>()
val scopes = generateScopes {
Expand All @@ -2183,24 +2183,24 @@ class ScopesTest {
it.setLogger(logger)
it.isDebug = true
}
scopes.startProfiler()
scopes.startProfileSession()
verify(profiler, never()).start(any())
verify(logger).log(eq(SentryLevel.WARNING), eq("Continuous Profiling is not enabled. Set profilesSampleRate and profilesSampler to null to enable it."))
}

@Test
fun `stopProfiler stops the continuous profiler`() {
fun `stopProfileSession stops the continuous profiler`() {
val profiler = mock<IContinuousProfiler>()
val scopes = generateScopes {
it.setContinuousProfiler(profiler)
it.experimental.profileSessionSampleRate = 1.0
}
scopes.stopProfiler()
scopes.stopProfileSession()
verify(profiler).stop()
}

@Test
fun `stopProfiler logs instructions if continuous profiling is disabled`() {
fun `stopProfileSession logs instructions if continuous profiling is disabled`() {
val profiler = mock<IContinuousProfiler>()
val logger = mock<ILogger>()
val scopes = generateScopes {
Expand All @@ -2210,7 +2210,7 @@ class ScopesTest {
it.setLogger(logger)
it.isDebug = true
}
scopes.stopProfiler()
scopes.stopProfileSession()
verify(profiler, never()).stop()
verify(logger).log(eq(SentryLevel.WARNING), eq("Continuous Profiling is not enabled. Set profilesSampleRate and profilesSampler to null to enable it."))
}
Expand Down
Loading
Loading