Skip to content

Update the Android OkHttp instrumentation docs and fix some Otel docs #29392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mariusc83
Copy link
Member

What does this PR do? What is the motivation?

This pull request updates documentation for Android setup and custom instrumentation, focusing on improving clarity and providing additional examples. The most important changes include adding instructions for using DatadogInterceptor with OkHttpClient and updating code snippets to correct terminology for accessing tracers.

Additions to Android setup documentation:

  • Added instructions for using DatadogInterceptor as a network interceptor with OkHttpClient to automatically create RUM resources and Spans for network requests. Included Kotlin and Java code examples.
  • Clarified that TracingInterceptor can be used instead of DatadogInterceptor if only Spans are needed, without RUM resources.

Updates to custom instrumentation documentation:

  • Updated Kotlin and Java code snippets to replace tracerProvider with tracer for accessing tracers via GlobalOpenTelemetry.get(), aligning with correct terminology

Merge instructions

Merge readiness:

  • Ready for merge

For Datadog employees:
Merge queue is enabled in this repo. Your branch name MUST follow the <name>/<description> convention and include the forward slash (/). Without this format, your pull request will not pass in CI, the GitLab pipeline will not run, and you won't get a branch preview. Getting a branch preview makes it easier for us to check any issues with your PR, such as broken links.

If your branch doesn't follow this format, rename it or create a new branch and PR.

To have your PR automatically merged after it receives the required reviews, add the following PR comment:

/merge

Additional notes

@mariusc83 mariusc83 self-assigned this May 16, 2025
@mariusc83 mariusc83 requested a review from a team as a code owner May 16, 2025 08:30
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].

In case you want to monitor the network redirects or retries, you can use the `DatadogInterceptor` as a network interceptor.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it is worth to link OkHttp documentation on the difference between interceptor and networkInterceptor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, I am waiting for suggestions here from doc reviewers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We link to the OkHttp docs early in step 3, right before the tabs that you can see the closing tags for at the very top of this PR. I think that's close enough to this note to be useful, but I'm not against adding the link again if you're concerned about users getting the two confused.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, linking to the OkHttp docs is a good idea. I would put the link on the phrase "network interceptor."

@mariusc83 mariusc83 force-pushed the mconstantin/rum-7538/update-fix-tracing-docs branch from 0af7196 to 35a3855 Compare May 16, 2025 09:33
@mariusc83 mariusc83 force-pushed the mconstantin/rum-7538/update-fix-tracing-docs branch from 35a3855 to abcabfb Compare May 16, 2025 09:35
@@ -417,8 +417,31 @@ OkHttpClient okHttpClient = new OkHttpClient.Builder()
{{% /tab %}}
{{< /tabs >}}

If you want RUM resources and Spans to be automatically created for your OkHttp requests, you can use the `DatadogInterceptor` as an interceptor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you want RUM resources and Spans to be automatically created for your OkHttp requests, you can use the `DatadogInterceptor` as an interceptor.
To automatically create RUM resources and spans for your OkHttp requests, use the `DatadogInterceptor` as an interceptor.

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

In case you want to monitor the network redirects or retries, you can use the `DatadogInterceptor` as a network interceptor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In case you want to monitor the network redirects or retries, you can use the `DatadogInterceptor` as a network interceptor.
To monitor the network redirects or retries, you can use the `DatadogInterceptor` as a network interceptor.

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

In case you want to monitor the network redirects or retries, you can use the `DatadogInterceptor` as a network interceptor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, linking to the OkHttp docs is a good idea. I would put the link on the phrase "network interceptor."

{{% /tab %}}
{{< /tabs >}}

**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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**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.
**Note**: To use spans but not RUM resources, you can use the `TracingInterceptor` instead of `DatadogInterceptor` as described above.

Copy link
Contributor

@janine-c janine-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I have some suggestions to try and make the structure more readable, but they're subject to what info you think would be most helpful - let me know what you think and how you think we can improve them 🙂

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

In case you want to monitor the network redirects or retries, you can use the `DatadogInterceptor` as a network interceptor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We link to the OkHttp docs early in step 3, right before the tabs that you can see the closing tags for at the very top of this PR. I think that's close enough to this note to be useful, but I'm not against adding the link again if you're concerned about users getting the two confused.

Comment on lines +420 to +441
If you want RUM resources and Spans to be automatically created for your OkHttp requests, you can use the `DatadogInterceptor` as an interceptor.

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

In case you want to monitor the network redirects or retries, you can use the `DatadogInterceptor` as a network interceptor.

{{< tabs >}}
{{% tab "Kotlin" %}}
```kotlin
val okHttpClient = OkHttpClient.Builder()
.addNetworkInterceptor(DatadogInterceptor.Builder(tracedHostsWithHeaderType).build())
.build()
```
{{% /tab %}}
{{% tab "Java" %}}
```java
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addNetworkInterceptor(new DatadogInterceptor.Builder(tracedHostsWithHeaderType).build())
.build();
```
{{% /tab %}}
{{< /tabs >}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two notes about using DatadogInterceptor seem similar to each other; I'm wondering if someone reading quickly might skip "network" and get confused.

I'm not sure I totally understand the intended placement of the paragraphs as they are now; I suspect that more should be embedded under step 3 than currently is, and that we can use some further embedding to make the relationships between these pieces more clear. I was wondering if this would make sense to you:

Suggested change
If you want RUM resources and Spans to be automatically created for your OkHttp requests, you can use the `DatadogInterceptor` as an interceptor.
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].
In case you want to monitor the network redirects or retries, you can use the `DatadogInterceptor` as a network interceptor.
{{< tabs >}}
{{% tab "Kotlin" %}}
```kotlin
val okHttpClient = OkHttpClient.Builder()
.addNetworkInterceptor(DatadogInterceptor.Builder(tracedHostsWithHeaderType).build())
.build()
```
{{% /tab %}}
{{% tab "Java" %}}
```java
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addNetworkInterceptor(new DatadogInterceptor.Builder(tracedHostsWithHeaderType).build())
.build();
```
{{% /tab %}}
{{< /tabs >}}
- If you want RUM resources and Spans to be automatically created for your OkHttp requests, you can use the `DatadogInterceptor` as an interceptor.
- 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].
- In case you want to monitor the network redirects or retries, you can use the `DatadogInterceptor` as a network interceptor:
{{< tabs >}}
{{% tab "Kotlin" %}}
\```kotlin
val okHttpClient = OkHttpClient.Builder()
.addNetworkInterceptor(DatadogInterceptor.Builder(tracedHostsWithHeaderType).build())
.build()
\```
{{% /tab %}}
{{% tab "Java" %}}
\```java
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addNetworkInterceptor(new DatadogInterceptor.Builder(tracedHostsWithHeaderType).build())
.build();
\```
{{% /tab %}}
{{< /tabs >}}

Note that in order to make that suggestion render properly in GitHub, I had to escape the code samples, so if you accept that change, you have to un-escape them. I don't know how to make that less buggy 😬

This is what that would look like:
image

Comment on lines +443 to 445
**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.

**Note**: If you also use multiple Interceptors, add `DatadogInterceptor` first.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**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.
**Note**: If you also use multiple Interceptors, add `DatadogInterceptor` first.
**Notes**:
- If you only want to have Spans without RUM resources, you can use the `TracingInterceptor` in the place of the `DatadogInterceptor`.
- If you also use multiple Interceptors, add `DatadogInterceptor` first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants