Skip to content

Commit 35a3855

Browse files
committed
Update the Android OkHttp instrumentation docs and fix some Otel docs
1 parent 911d73d commit 35a3855

File tree

2 files changed

+25
-2
lines changed
  • content/en
    • real_user_monitoring/mobile_and_tv_monitoring/android
    • tracing/trace_collection/custom_instrumentation/android

2 files changed

+25
-2
lines changed

content/en/real_user_monitoring/mobile_and_tv_monitoring/android/setup.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,31 @@ OkHttpClient okHttpClient = new OkHttpClient.Builder()
417417
{{% /tab %}}
418418
{{< /tabs >}}
419419

420+
If you want RUM resources and Spans to be automatically created for your OkHttp requests, you can use the `DatadogInterceptor` as an interceptor.
421+
420422
This records each request processed by the `OkHttpClient` as a resource, with all the relevant information (URL, method, status code, and error) automatically filled in. Only the network requests that started when a view is active are tracked. To track requests when your application is in the background, [create a view manually][13].
421423

424+
In case you want to monitor the network redirects or retries, you can use the `DatadogInterceptor` as a network interceptor.
425+
426+
{{< tabs >}}
427+
{{% tab "Kotlin" %}}
428+
```kotlin
429+
val okHttpClient = OkHttpClient.Builder()
430+
.addNetworkInterceptor(DatadogInterceptor.Builder(tracedHostsWithHeaderType).build())
431+
.build()
432+
```
433+
{{% /tab %}}
434+
{{% tab "Java" %}}
435+
```java
436+
OkHttpClient okHttpClient = new OkHttpClient.Builder()
437+
.addNetworkInterceptor(new DatadogInterceptor.Builder(tracedHostsWithHeaderType).build())
438+
.build();
439+
```
440+
{{% /tab %}}
441+
{{< /tabs >}}
442+
443+
**Note**: In case you only want to have Spans without RUM resources, you can use the `TracingInterceptor` instead of `DatadogInterceptor` the same way we explained above.
444+
422445
**Note**: If you also use multiple Interceptors, add `DatadogInterceptor` first.
423446

424447
You can also add an `EventListener` for the `OkHttpClient` to [automatically track resource timing][14] for third-party providers and network requests.

content/en/tracing/trace_collection/custom_instrumentation/android/otel.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ GlobalOpenTelemetry.set(object : OpenTelemetry {
335335
}
336336
})
337337
// and later on if you want to access the tracer provider
338-
val tracerProvider = GlobalOpenTelemetry.get().getTracer(instrumentationName = "<instrumentation_name>")
338+
val tracer = GlobalOpenTelemetry.get().getTracer(instrumentationName = "<instrumentation_name>")
339339
```
340340
{{% /tab %}}
341341
{{% tab "Java" %}}
@@ -356,7 +356,7 @@ GlobalOpenTelemetry.set(new OpenTelemetry() {
356356
}
357357
});
358358
// and later on if you want to access the tracer provider
359-
final TracerProvider tracerProvider = GlobalOpenTelemetry.get().getTracer("<instrumentation_name>");
359+
final Tracer tracer = GlobalOpenTelemetry.get().getTracer("<instrumentation_name>");
360360
```
361361
{{% /tab %}}
362362
{{< /tabs >}}

0 commit comments

Comments
 (0)