Skip to content

Commit add167e

Browse files
authored
feat(android): Add autoinstallation sections for okhttp, fragment and timber (#4834)
1 parent 719ca3a commit add167e

File tree

3 files changed

+155
-6
lines changed

3 files changed

+155
-6
lines changed

src/platforms/android/configuration/integrations/fragment.mdx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,47 @@ The `sentry-android-fragment` library provides [Fragment](https://developer.andr
1212

1313
On this page, we get you up and running with Sentry's Fragment Integration, so that it will automatically add a breadcrumb for each fragment's lifecycle and start a span out of the active transaction bound to the scope for each launch of a fragment.
1414

15-
## Install
15+
## Auto-Installation With the Sentry Android Gradle Plugin
16+
17+
### Install
18+
19+
Starting from version `3.1.0`, the Sentry Android Gradle plugin will automatically add the `sentry-android-fragment` dependency. The plugin will only add the `sentry-android-fragment` dependency if a `androidx.fragment` dependency was discovered on the classpath.
20+
21+
Add the Sentry Android Gradle plugin in `build.gradle`:
22+
23+
```groovy
24+
buildscript {
25+
repositories {
26+
mavenCentral()
27+
}
28+
}
29+
30+
plugins {
31+
id "io.sentry.android.gradle" version "3.1.0-alpha.1"
32+
}
33+
```
34+
35+
```kotlin
36+
buildscript {
37+
repositories {
38+
mavenCentral()
39+
}
40+
}
41+
42+
plugins {
43+
id("io.sentry.android.gradle") version "3.1.0-alpha.1"
44+
}
45+
```
46+
47+
Then, initialize the [Android SDK](/platforms/android/#configure).
48+
49+
The Android SDK automatically adds the `FragmentLifecycleIntegration` if the `sentry-android-fragment` dependency was found on the classpath. The integration is added with both `enableFragmentLifecycleBreadcrumbs` and `enableAutoFragmentLifecycleTracing` enabled.
50+
51+
However, you can still override the default behaviour by adding your own instance of the `FragmentLifecycleIntegration`. For that, refer to the [manual installation](/platforms/android/configuration/integrations/fragment/#configure) section below.
52+
53+
## Manual Installation
54+
55+
### Install
1656

1757
To add the Fragment integration, [manually initialize](/platforms/android/configuration/manual-init/) the Android SDK, then add the `sentry-android-fragment` dependency. Using Gradle:
1858

@@ -21,7 +61,7 @@ implementation 'io.sentry:sentry-android:{{ packages.version('sentry.java.androi
2161
implementation 'io.sentry:sentry-android-fragment:{{ packages.version('sentry.java.android.fragment', '5.1.0') }}'
2262
```
2363

24-
## Configure
64+
### Configure
2565

2666
Configuration should happen as early as possible in your application's lifecycle.
2767

src/platforms/android/configuration/integrations/okhttp.mdx

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,76 @@ The minimum supported version of `okhttp` is `3.13.0` due to its [incompatibilit
2020

2121
</Note>
2222

23-
## Install
23+
## Auto-Installation With the Sentry Android Gradle Plugin
24+
25+
Starting from version `3.1.0`, the Sentry Android Gradle plugin will automatically add the `sentry-android-okhttp` dependency and instrument all of your `OkHttpClient` instances through bytecode manipulation. The plugin will only add the `sentry-android-okhttp` dependency if an `okhttp` dependency was discovered on the classpath.
26+
27+
### Install
28+
29+
Add the Sentry Android Gradle plugin in `build.gradle`:
30+
31+
```groovy
32+
buildscript {
33+
repositories {
34+
mavenCentral()
35+
}
36+
}
37+
38+
plugins {
39+
id "io.sentry.android.gradle" version "3.1.0-alpha.1"
40+
}
41+
```
42+
43+
```kotlin
44+
buildscript {
45+
repositories {
46+
mavenCentral()
47+
}
48+
}
49+
50+
plugins {
51+
id("io.sentry.android.gradle") version "3.1.0-alpha.1"
52+
}
53+
```
54+
55+
Then, initialize the [Android SDK](/platforms/android/#configure).
56+
57+
### Disable
58+
59+
If you would like to disable the OkHttp instrumentation feature, we expose a configuration option for that:
60+
61+
```groovy
62+
import io.sentry.android.gradle.InstrumentationFeature
63+
64+
sentry {
65+
tracingInstrumentation {
66+
enabled = true
67+
features = EnumSet.allOf(InstrumentationFeature) - InstrumentationFeature.OKHTTP
68+
}
69+
}
70+
```
71+
72+
```kotlin
73+
import java.util.EnumSet
74+
import io.sentry.android.gradle.InstrumentationFeature
75+
76+
sentry {
77+
tracingInstrumentation {
78+
enabled.set(true)
79+
features.set(EnumSet.allOf(InstrumentationFeature::class.java) - InstrumentationFeature.OKHTTP)
80+
}
81+
}
82+
```
83+
84+
<Note>
85+
86+
Learn more about the Sentry Android Gradle plugin in our [Gradle](/platforms/android/gradle/) documentation.
87+
88+
</Note>
89+
90+
## Manual Installation
91+
92+
### Install
2493

2594
Sentry captures data by adding an `OkHttp Interceptor`. To add the OkHttp integration, initialize the [Android SDK](/platforms/android/), then add the `sentry-android-okhttp` dependency. Using Gradle:
2695

@@ -29,7 +98,7 @@ implementation 'io.sentry:sentry-android:{{ packages.version('sentry.java.androi
2998
implementation 'io.sentry:sentry-android-okhttp:{{ packages.version('sentry.java.android.okhttp', '5.0.0') }}'
3099
```
31100

32-
## Configure
101+
### Configure
33102

34103
Configuration should happen once you create your `OkHttpClient` instance.
35104

src/platforms/android/configuration/integrations/timber.mdx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,47 @@ Starting from version `5.6.2`, the `Timber.tag` usage is no longer supported by
2020

2121
</Note>
2222

23-
## Install
23+
## Auto-Installation With the Sentry Android Gradle Plugin
24+
25+
### Install
26+
27+
Starting from version `3.1.0`, the Sentry Android Gradle plugin will automatically add the `sentry-android-timber` dependency. The plugin will only add the `sentry-android-timber` dependency if a `timber` dependency was discovered on the classpath.
28+
29+
Add the Sentry Android Gradle plugin in `build.gradle`:
30+
31+
```groovy
32+
buildscript {
33+
repositories {
34+
mavenCentral()
35+
}
36+
}
37+
38+
plugins {
39+
id "io.sentry.android.gradle" version "3.1.0-alpha.1"
40+
}
41+
```
42+
43+
```kotlin
44+
buildscript {
45+
repositories {
46+
mavenCentral()
47+
}
48+
}
49+
50+
plugins {
51+
id("io.sentry.android.gradle") version "3.1.0-alpha.1"
52+
}
53+
```
54+
55+
Then, initialize the [Android SDK](/platforms/android/#configure).
56+
57+
The Android SDK automatically adds the `SentryTimberIntegration` if the `sentry-android-timber` dependency was found on the classpath. The integration is added with `minEventLevel` set to `ERROR` and `minBreadcrumbLevel` set to `INFO`.
58+
59+
However, you can still override the default behaviour by adding your own instance of the `SentryTimberIntegration`. For that, refer to the [manual installation](/platforms/android/configuration/integrations/timber/#configure) section below.
60+
61+
## Manual Installation
62+
63+
### Install
2464

2565
To add the Timber integration, [manually initialize](/platforms/android/configuration/manual-init/) the Android SDK, then add the `sentry-android-timber` dependency. Using Gradle:
2666

@@ -29,7 +69,7 @@ implementation 'io.sentry:sentry-android:{{ packages.version('sentry.java.androi
2969
implementation 'io.sentry:sentry-android-timber:{{ packages.version('sentry.java.android.timber', '4.2.0') }}'
3070
```
3171

32-
## Configure
72+
### Configure
3373

3474
Configuration should happen as early as possible in your application's lifecycle.
3575

0 commit comments

Comments
 (0)