Skip to content
Merged
48 changes: 25 additions & 23 deletions docs/platforms/android/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -303,35 +303,15 @@ Set this boolean to `false` to disable tracing for `OPTIONS` requests. This opti

## Profiling Options

<ConfigKey name="profiles-sample-rate">

A number between `0` and `1`, controlling the percentage chance a given profile will be sent to Sentry. (`0` represents 0% while `1` represents 100%.) Applies only to sampled transactions created in the app. Either this or <PlatformIdentifier name="profiles-sampler" /> must be defined to enable transaction profiling. Don't set it if you want to use <PlatformLink to="/profiling/#continuous-profiling">Continuous Profiling</PlatformLink>.

</ConfigKey>

<ConfigKey name="profiles-sampler">

A function responsible for determining the percentage chance a given profile will be sent to Sentry. It will automatically be passed information about the transaction and the context in which it's being created, and must return a number between `0` (0% chance of being sent) and `1` (100% chance of being sent). Can also be used for filtering profiles, by returning 0 for those that are unwanted. Either this or <PlatformIdentifier name="profiles-sample-rate" /> must be defined to enable transaction profiling. Don't set it if you want to use <PlatformLink to="/profiling/#continuous-profiling">Continuous Profiling</PlatformLink>.

</ConfigKey>

<ConfigKey name="enable-app-start-profiling">

A boolean value that determines whether the app start process will be profiled. When true, the startup process, including ContentProviders, Application and first Activity creation, will be profiled. Note that <PlatformIdentifier name="profiles-sample-rate" /> or <PlatformIdentifier name="profiles-sampler" /> must be defined.

</ConfigKey>

## Continuous Profiling Options

<Alert>
<Alert title="Note">

This feature is experimental and may have bugs.
Profiling requires SDK versions 8.7.0 or higher. Lower versions can use the <PlatformLink to="/configuration/options/#legacy-profiling-options">legacy profiling</PlatformLink>.

</Alert>

<ConfigKey name="profile-session-sample-rate">

A number between `0` and `1`, controlling the percentage chance the session will be profiled. `0` represents 0% while `1` represents 100%. The default is null (disabled). <PlatformIdentifier name="profiles-sampler" /> and <PlatformIdentifier name="profiles-sample-rate" /> must not be set to enable <PlatformLink to="/profiling/#continuous-profiling">Continuous Profiling</PlatformLink>.
A number between `0` and `1`, controlling the percentage chance the session will be profiled. `0` represents 0% while `1` represents 100%. The default is null (disabled).

</ConfigKey>

Expand All @@ -352,3 +332,25 @@ A boolean value that determines whether the app start process will be profiled.
- If profileLifecycle is set to `trace`: profiling is started automatically on startup, and will automatically be stopped when the root span that is associated with app startup ends

</ConfigKey>

## Legacy Profiling Options

SDK versions lower than 8.7.0 may use the legacy profiling through the following options.

<ConfigKey name="profiles-sample-rate">

A number between `0` and `1`, controlling the percentage chance a given profile will be sent to Sentry. (`0` represents 0% while `1` represents 100%.) Applies only to sampled transactions created in the app. Setting this option will enable the legacy profiler.

</ConfigKey>

<ConfigKey name="profiles-sampler">

A function responsible for determining the percentage chance a given profile will be sent to Sentry. It will automatically be passed information about the transaction and the context in which it's being created, and must return a number between `0` (0% chance of being sent) and `1` (100% chance of being sent). Can also be used for filtering profiles, by returning 0 for those that are unwanted. Either this or <PlatformIdentifier name="profiles-sample-rate" /> must be defined to enable transaction profiling. Setting this option will enable the legacy profiler.

</ConfigKey>

<ConfigKey name="enable-app-start-profiling">

A boolean value that determines whether the app start process will be profiled. When true, the startup process, including ContentProviders, Application and first Activity creation, will be profiled.

</ConfigKey>
100 changes: 86 additions & 14 deletions docs/platforms/android/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ Select which Sentry features you'd like to install in addition to Error Monitori
options={[
'error-monitoring',
'performance',
{
id: 'profiling',
checked: false
},
'profiling',
'session-replay'
]}
/>
Expand Down Expand Up @@ -83,23 +80,98 @@ Configuration is done via the application `AndroidManifest.xml`. Here's an examp
<meta-data android:name="io.sentry.send-default-pii" android:value="true" />
<!-- Enable the performance API by setting a sample-rate, adjust in production env -->
<meta-data android:name="io.sentry.traces.sample-rate" android:value="1.0" />
<!-- Enable profiling, adjust in production env. See https://docs.sentry.io/platforms/android/profiling for more info -->
<!-- Enable profiling, adjust in production env. This is evaluated only once per session -->
<meta-data android:name="io.sentry.traces.profiling.session-sample-rate" android:value="1.0" />
<!-- Set profiling lifecycle, can be `manual` or `trace` -->
<meta-data android:name="io.sentry.traces.profiling.lifecycle" android:value="manual" />
<!-- Set profiling lifecycle, can be `manual` (controlled through `Sentry.startProfiler()` and `Sentry.stopProfiler()`) or `trace` (automatically starts and stop a profile whenever a sampled trace starts and finishes) -->
<meta-data android:name="io.sentry.traces.profiling.lifecycle" android:value="trace" />
<!-- Enable profiling on app start -->
<meta-data android:name="io.sentry.traces.profiling.start-on-app-start" android:value="true" />
<!-- record session replays for 100% of errors and 10% of sessions -->
<!-- Record session replays for 100% of errors and 10% of sessions -->
<meta-data android:name="io.sentry.session-replay.on-error-sample-rate" android:value="1.0" />
<meta-data android:name="io.sentry.session-replay.session-sample-rate" android:value="0.1" />
</application>
```

```java {"onboardingOptions": {"performance": "17-18", "profiling": "19-24, 29-33", "session-replay": "25-27"}}
import io.sentry.ProfileLifecycle;
import io.sentry.Sentry;
import io.sentry.android.core.SentryAndroid;

// App main Application class
public class MyApplication extends Application {

@Override
public void onCreate() {
super.onCreate();
SentryAndroid.init(
this,
options -> {
options.setDsn("___PUBLIC_DSN___");
// Add data like request headers, user ip address and device name, see https://docs.sentry.io/platforms/android/data-management/data-collected/ for more info
options.setSendDefaultPii(true);
// Enable the performance API by setting a sample-rate, adjust in production env
options.setTracesSampleRate(1.0);
// Enable profiling, adjust in production env. This is evaluated only once per session
options.setProfileSessionSampleRate(1.0);
// Set profiling lifecycle, can be `manual` (controlled through `Sentry.startProfiler()` and `Sentry.stopProfiler()`) or `trace` (automatically starts and stop a profile whenever a sampled trace starts and finishes)
options.setProfileLifecycle(ProfileLifecycle.TRACE);
// Enable profiling on app start. The app start profile has to be stopped through Sentry.stopProfiler() if lifecycle is set to `manual`
options.setStartProfilerOnAppStart(true);
// Record session replays for 100% of errors and 10% of sessions
options.getSessionReplay().setOnErrorSampleRate(1.0);
options.getSessionReplay().setSessionSampleRate(0.1);
});
// Start profiling, if lifecycle is set to `manual` and startProfilerOnAppStart is set to `true`
Sentry.startProfiler();
// Stop profiling, if lifecycle is set to `manual` and startProfilerOnAppStart is set to `true`.
// This call is optional. If you don't stop the profiler, it will keep profiling your application until the process exits.
Sentry.stopProfiler();
}
}
```

```kotlin {"onboardingOptions": {"performance": "16-17", "profiling": "18-23, 28-32", "session-replay": "24-26"}}
import io.sentry.ProfileLifecycle;
import io.sentry.Sentry;
import io.sentry.android.core.SentryAndroid;

// App main Application class
class MyApplication : Application() {

override fun onCreate() {
super.onCreate();
SentryAndroid.init(
this,
{ options ->
options.dsn = "___PUBLIC_DSN___"
// Add data like request headers, user ip address and device name, see https://docs.sentry.io/platforms/android/data-management/data-collected/ for more info
options.isSendDefaultPii = true
// Enable the performance API by setting a sample-rate, adjust in production env
options.tracesSampleRate = 1.0
// Enable profiling, adjust in production env. This is evaluated only once per session
options.profileSessionSampleRate = 1.0
// Set profiling lifecycle, can be `manual` (controlled through `Sentry.startProfiler()` and `Sentry.stopProfiler()`) or `trace` (automatically starts and stop a profile whenever a sampled trace starts and finishes)
options.profileLifecycle = ProfileLifecycle.TRACE
// Enable profiling on app start. The app start profile has to be stopped through Sentry.stopProfiler() if lifecycle is set to `manual`
options.isStartProfilerOnAppStart = true
// Record session replays for 100% of errors and 10% of sessions
options.sessionReplay.onErrorSampleRate = 1.0
options.sessionReplay.sessionSampleRate = 0.1
})
// Start profiling, if lifecycle is set to `manual` and startProfilerOnAppStart is set to `true`
Sentry.startProfiler()
// Stop profiling, if lifecycle is set to `manual` and startProfilerOnAppStart is set to `true`.
// This call is optional. If you don't stop the profiler, it will keep profiling your application until the process exits.
Sentry.stopProfiler()
}
}
```

## Verify

Verify that your app is sending events to Sentry by adding the following snippet, which includes an intentional error. You should see the error reported in Sentry within a few minutes.

```java
```java {"onboardingOptions": {"profiling": "9-10, 16-17"}}
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import java.lang.Exception;
Expand All @@ -108,35 +180,35 @@ import io.sentry.Sentry;
public class MyActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Any code running after this line will be
//profiled until Sentry.stopProfiler() is called.
// Any code running after this line will be profiled, if lifecycle is set to `manual`.
Sentry.startProfiler();
try {
throw new Exception("This is a test.");
} catch (Exception e) {
Sentry.captureException(e);
}
// Stop profiling, if lifecycle is set to `manual`. This call is optional. If you don't stop the profiler, it will keep profiling your application until the process exits or `Sentry.stopProfiler()` is called.
Sentry.stopProfiler();
}
}
```

```kotlin
```kotlin {"onboardingOptions": {"profiling": "8-9, 15-16"}}
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import io.sentry.Sentry

class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Any code running after this line will be
//profiled until Sentry.stopProfiler() is called.
// Any code running after this line will be profiled, if lifecycle is set to `manual`.
Sentry.startProfiler()
try {
throw Exception("This is a test.")
} catch (e: Exception) {
Sentry.captureException(e)
}
// Stop profiling, if lifecycle is set to `manual`. This call is optional. If you don't stop the profiler, it will keep profiling your application until the process exits or `Sentry.stopProfiler()` is called.
Sentry.stopProfiler()
}
}
Expand Down
Loading