Skip to content

Commit 4d96a6a

Browse files
committed
added code snippet for java and kotlin in android onboarding
1 parent 4659691 commit 4d96a6a

File tree

3 files changed

+81
-8
lines changed

3 files changed

+81
-8
lines changed

docs/platforms/android/configuration/options.mdx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ Set this boolean to `false` to disable tracing for `OPTIONS` requests. This opti
305305

306306
<Alert title="Note">
307307

308-
Profiling requires SDK versions 8.7.0 or higher. Lower versions can use the legacy profiling.
308+
Profiling requires SDK versions 8.7.0 or higher. Lower versions can use the <PlatformLink to="/configuration/options/#legacy-profiling-options">legacy profiling</PlatformLink>.
309309

310310
</Alert>
311311

@@ -335,11 +335,7 @@ A boolean value that determines whether the app start process will be profiled.
335335

336336
## Legacy Profiling Options
337337

338-
<Alert title="Note">
339-
340-
SDK versions lower than 8.6.0 may use the legacy profiling using the following options.
341-
342-
</Alert>
338+
SDK versions lower than 8.7.0 may use the legacy profiling through the following options.
343339

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

docs/platforms/android/index.mdx

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,87 @@ Configuration is done via the application `AndroidManifest.xml`. Here's an examp
8686
<meta-data android:name="io.sentry.traces.profiling.lifecycle" android:value="trace" />
8787
<!-- Enable profiling on app start -->
8888
<meta-data android:name="io.sentry.traces.profiling.start-on-app-start" android:value="true" />
89-
<!-- record session replays for 100% of errors and 10% of sessions -->
89+
<!-- Record session replays for 100% of errors and 10% of sessions -->
9090
<meta-data android:name="io.sentry.session-replay.on-error-sample-rate" android:value="1.0" />
9191
<meta-data android:name="io.sentry.session-replay.session-sample-rate" android:value="0.1" />
9292
</application>
9393
```
9494

95+
```java {"onboardingOptions": {"performance": "17-18", "profiling": "19-24, 29-33", "session-replay": "25-27"}}
96+
import io.sentry.ProfileLifecycle;
97+
import io.sentry.Sentry;
98+
import io.sentry.android.core.SentryAndroid;
99+
100+
// App main Application class
101+
public class MyApplication extends Application {
102+
103+
@Override
104+
public void onCreate() {
105+
super.onCreate();
106+
SentryAndroid.init(
107+
this,
108+
options -> {
109+
options.setDsn("___PUBLIC_DSN___");
110+
// 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
111+
options.setSendDefaultPii(true);
112+
// Enable the performance API by setting a sample-rate, adjust in production env
113+
options.setTracesSampleRate(1.0);
114+
// Enable profiling, adjust in production env. This is evaluated only once per session
115+
options.setProfileSessionSampleRate(1.0);
116+
// 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)
117+
options.setProfileLifecycle(ProfileLifecycle.TRACE);
118+
// Enable profiling on app start. The app start profile has to be stopped through Sentry.stopProfiler() if lifecycle is set to `manual`
119+
options.setStartProfilerOnAppStart(true);
120+
// Record session replays for 100% of errors and 10% of sessions
121+
options.getSessionReplay().setOnErrorSampleRate(1.0);
122+
options.getSessionReplay().setSessionSampleRate(0.1);
123+
});
124+
// Start profiling, if lifecycle is set to `manual` and startProfilerOnAppStart is set to `true`
125+
Sentry.startProfiler();
126+
// Stop profiling, if lifecycle is set to `manual` and startProfilerOnAppStart is set to `true`.
127+
// This call is optional. If you don't stop the profiler, it will keep profiling your application until the process exits.
128+
Sentry.stopProfiler();
129+
}
130+
}
131+
```
132+
133+
```kotlin {"onboardingOptions": {"performance": "16-17", "profiling": "18-23, 28-32", "session-replay": "24-26"}}
134+
import io.sentry.ProfileLifecycle;
135+
import io.sentry.Sentry;
136+
import io.sentry.android.core.SentryAndroid;
137+
138+
// App main Application class
139+
class MyApplication : Application() {
140+
141+
override fun onCreate() {
142+
super.onCreate();
143+
SentryAndroid.init(
144+
this,
145+
{ options ->
146+
options.setDsn("___PUBLIC_DSN___")
147+
// 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
148+
options.isSendDefaultPii = true
149+
// Enable the performance API by setting a sample-rate, adjust in production env
150+
options.tracesSampleRate = 1.0
151+
// Enable profiling, adjust in production env. This is evaluated only once per session
152+
options.profileSessionSampleRate = 1.0
153+
// 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)
154+
options.profileLifecycle = ProfileLifecycle.TRACE
155+
// Enable profiling on app start. The app start profile has to be stopped through Sentry.stopProfiler() if lifecycle is set to `manual`
156+
options.isStartProfilerOnAppStart = true
157+
// Record session replays for 100% of errors and 10% of sessions
158+
options.sessionReplay.onErrorSampleRate = 1.0
159+
options.sessionReplay.sessionSampleRate = 0.1
160+
})
161+
// Start profiling, if lifecycle is set to `manual` and startProfilerOnAppStart is set to `true`
162+
Sentry.startProfiler()
163+
// Stop profiling, if lifecycle is set to `manual` and startProfilerOnAppStart is set to `true`.
164+
// This call is optional. If you don't stop the profiler, it will keep profiling your application until the process exits.
165+
Sentry.stopProfiler()
166+
}
167+
}
168+
```
169+
95170
## Verify
96171

97172
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.

docs/platforms/android/profiling/index.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ sidebar_order: 5000
1414
## Installation
1515

1616
Android profiling is available starting in SDK version `8.7.0`.
17-
The legacy profiler is available on SDK versions '6.16.0' and higher through <PlatformLink to="/configuration/options/#legacy-profiling-options">its options</PlatformLink>.
17+
The legacy profiler is available on SDK versions `6.16.0` and higher through <PlatformLink to="/configuration/options/#legacy-profiling-options">its options</PlatformLink>.
1818

1919
## Enabling Profiling
2020

@@ -86,6 +86,7 @@ import io.sentry.android.core.SentryAndroid
8686

8787
// App main Application class
8888
class MyApplication : Application() {
89+
8990
override fun onCreate() {
9091
super.onCreate()
9192
SentryAndroid.init(
@@ -156,6 +157,7 @@ import io.sentry.android.core.SentryAndroid
156157

157158
// App main Application class
158159
class MyApplication : Application() {
160+
159161
override fun onCreate() {
160162
super.onCreate()
161163
SentryAndroid.init(

0 commit comments

Comments
 (0)