Skip to content

Commit 095c598

Browse files
authored
feat(android): Update Gradle docs with auto-installation and okhttp instrumentation (#4829)
1 parent add167e commit 095c598

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

src/platforms/android/common/gradle.mdx

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,25 @@ sentry {
8989
9090
// Specifies a set of instrumentation features that are eligible for bytecode manipulation.
9191
// Defaults to all available values of InstrumentationFeature enum class.
92-
features = [InstrumentationFeature.DATABASE, InstrumentationFeature.FILE_IO]
92+
features = [InstrumentationFeature.DATABASE, InstrumentationFeature.FILE_IO, InstrumentationFeature.OKHTTP]
93+
}
94+
95+
// Enable auto-installation of Sentry components (sentry-android SDK and okhttp, timber and fragment integrations).
96+
// Default is enabled.
97+
// Only available v3.1.0 and above.
98+
autoInstallation {
99+
enabled = true
100+
101+
// Specifies a version of the sentry-android SDK and fragment, timber and okhttp integrations.
102+
//
103+
// This is also useful, when you have the sentry-android SDK already included into a transitive dependency/module and want to
104+
// align integration versions with it (if it's a direct dependency, the version will be inferred).
105+
//
106+
// NOTE: if you have a higher version of the sentry-android SDK or integrations on the classpath, this setting will have no effect
107+
// as Gradle will resolve it to the latest version.
108+
//
109+
// Defaults to the latest published sentry version.
110+
sentryVersion = '{{ packages.version('sentry.java.android', '5.0.0') }}'
93111
}
94112
}
95113
```
@@ -136,7 +154,25 @@ sentry {
136154

137155
// Specifies a set of instrumentation features that are eligible for bytecode manipulation.
138156
// Defaults to all available values of InstrumentationFeature enum class.
139-
features.set(setOf(InstrumentationFeature.DATABASE, InstrumentationFeature.FILE_IO))
157+
features.set(setOf(InstrumentationFeature.DATABASE, InstrumentationFeature.FILE_IO, InstrumentationFeature.OKHTTP))
158+
}
159+
160+
// Enable auto-installation of Sentry components (sentry-android SDK and okhttp, timber and fragment integrations).
161+
// Default is enabled.
162+
// Only available v3.1.0 and above.
163+
autoInstallation {
164+
enabled.set(true)
165+
166+
// Specifies a version of the sentry-android SDK and fragment, timber and okhttp integrations.
167+
//
168+
// This is also useful, when you have the sentry-android SDK already included into a transitive dependency/module and want to
169+
// align integration versions with it (if it's a direct dependency, the version will be inferred).
170+
//
171+
// NOTE: if you have a higher version of the sentry-android SDK or integrations on the classpath, this setting will have no effect
172+
// as Gradle will resolve it to the latest version.
173+
//
174+
// Defaults to the latest published sentry version.
175+
sentryVersion.set("{{ packages.version('sentry.java.android', '5.0.0') }}")
140176
}
141177
}
142178
```
@@ -245,7 +281,18 @@ enum class InstrumentationFeature {
245281
*
246282
* Requires sentry-android SDK version 5.5.0 and above
247283
*/
248-
FILE_IO
284+
FILE_IO,
285+
286+
/**
287+
* When enabled the SDK will create spans for outgoing network requests and attach
288+
* sentry-trace-header for distributed tracing.
289+
* This feature uses bytecode manipulation and attaches SentryOkHttpInterceptor to all OkHttp
290+
* clients in the project.
291+
*
292+
* Requires sentry-android SDK version 5.0.0 and above.
293+
* Only available v3.1.0 and above of the Sentry Android Gradle plugin.
294+
*/
295+
OKHTTP
249296
}
250297
```
251298

@@ -256,3 +303,23 @@ Check [Integrations](/platforms/android/configuration/integrations/) page for mo
256303
To learn more about the internals of auto-instrumentation, check out this [blog post](https://blog.sentry.io/2021/12/14/bytecode-transformations-the-android-gradle-plugin).
257304

258305
</Note>
306+
307+
## Auto-Installation
308+
309+
The plugin offers the automated installation feature of the Sentry Android SDK and the [Fragment](/platforms/android/configuration/integrations/fragment/), [Timber](/platforms/android/configuration/integrations/timber/), and [OkHttp](/platforms/android/configuration/integrations/okhttp/) integrations. Starting with version 3.1.0, the feature is enabled by default, so you don't need to add any dependencies — you just use the Sentry Gradle plugin.
310+
311+
The plugin algorithm does the following when defining dependency versions:
312+
313+
1. Check if the module/app has a direct dependency on the Sentry Android SDK:
314+
315+
- If yes, then use the version of the direct dependency.
316+
317+
- If no, then automatically add the sentry-android dependency with the specified `sentryVersion` from the plugin configuration (defaults to the latest published SDK version).
318+
319+
2. Check if the module/app has a direct dependency on any of the integrations (Fragment, Timber, or OkHttp):
320+
321+
- If yes, then keep the current version of the direct dependency.
322+
323+
- If no, then automatically add the integration dependency with the version of the Sentry Android SDK inferred from above.
324+
325+
3. If there are transitive dependencies on any of the integrations or the Sentry Android SDK, then their versions are not considered. However, if the versions are higher than those bundled with the Sentry Gradle plugin, Gradle will choose them instead.

0 commit comments

Comments
 (0)