Skip to content

Commit 36fc1a4

Browse files
committed
Allow customer to change okHttpInstrumentationType in init call + updated docs
1 parent b23b799 commit 36fc1a4

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

packages/react-native/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ setFeatureFlagExposure('beta_mode', false);
149149

150150
The automatic capture of network requests can be achieved in a few different ways depending on the platform and the networking library being used.
151151

152+
When initialization is done in JavaScript, always pass `enableNetworkInstrumentation: true` to `init(...)`. This is required on both iOS and Android.
153+
152154
#### iOS
153155

154156
When initializing via JS, pass `enableNetworkInstrumentation: true` as one of the options to `init`:
@@ -176,6 +178,21 @@ plugins {
176178

177179
To find the version to use, use the same version of the Capture SDK that is being used in the React Native project. Check the `build.gradle` file in the `node_modules/@bitdrift/react-native/android` directory for the version of the Capture SDK being used.
178180

181+
For Android, the plugin also needs instrumentation settings:
182+
183+
```gradle
184+
capture {
185+
instrumentation {
186+
automaticOkHttpInstrumentation = true
187+
okHttpInstrumentationType = OVERWRITE
188+
}
189+
}
190+
```
191+
192+
`okHttpInstrumentationType` modes:
193+
- `PROXY` (plugin default): preserves existing `EventListener.Factory` behavior in OkHttp clients.
194+
- `OVERWRITE`: replaces the listener factory and can avoid duplicate network spans in some app setups.
195+
179196
In addition to this the plugin repository needs to be added to the `pluginManagement` block in the `settings.gradle` file:
180197

181198
```gradle
@@ -209,3 +226,26 @@ When using Expo to generate the project, this can be achieved by setting the `ne
209226
}
210227
}
211228
```
229+
230+
The Android plugin mode can be configured with `okHttpInstrumentationType`:
231+
232+
```json
233+
{
234+
"expo": {
235+
"plugins": [
236+
[
237+
"@bitdrift/react-native",
238+
{
239+
"networkInstrumentation": true,
240+
"okHttpInstrumentationType": "OVERWRITE"
241+
}
242+
]
243+
]
244+
}
245+
}
246+
```
247+
248+
- `PROXY` (default): preserves existing `EventListener.Factory` behavior in OkHttp clients.
249+
- `OVERWRITE`: replaces the listener factory and can avoid duplicate network spans in some app setups.
250+
251+
If you recently upgraded and started seeing duplicate spans on Android, set `okHttpInstrumentationType` to `OVERWRITE`.

packages/react-native/src/plugin/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77

88
export default interface PluginProps {
99
networkInstrumentation?: boolean;
10+
// Only used when networkInstrumentation is true.
11+
okHttpInstrumentationType?: 'PROXY' | 'OVERWRITE';
1012
}

packages/react-native/src/plugin/withAndroid.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,22 @@ const withBitdriftAppBuildGradle: ConfigPlugin<PluginProps | void> = (
1919
// TODO(snowp): Eventually we'd always install the plugin and gate the okhttp instrumentation
2020
// config on the networkInstrumentation prop.
2121
if (props && props.networkInstrumentation) {
22+
const okHttpInstrumentationType =
23+
props.okHttpInstrumentationType === 'OVERWRITE' ? 'OVERWRITE' : 'PROXY';
24+
2225
// Add the capture-plugin at the very top of the file.
2326
config.modResults.contents =
2427
`plugins {
2528
id 'io.bitdrift.capture-plugin' version '0.22.12'
2629
}
2730
31+
capture {
32+
instrumentation {
33+
automaticOkHttpInstrumentation = true
34+
okHttpInstrumentationType = ${okHttpInstrumentationType}
35+
}
36+
}
37+
2838
` + config.modResults.contents;
2939
}
3040

0 commit comments

Comments
 (0)