Skip to content
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

OkHttp migration to instrumentaion API #505

Merged
merged 16 commits into from
Aug 14, 2024

Conversation

LikeTheSalad
Copy link
Contributor

@LikeTheSalad LikeTheSalad commented Aug 1, 2024

Migrating the okhttp instrumentation.

This should also address this issue: #433 since now GlobalOpenTelemetry isn't needed.

@LikeTheSalad LikeTheSalad requested a review from a team August 1, 2024 09:22
@LikeTheSalad LikeTheSalad changed the title Okhttp migration to instrumentaion API OkHttp migration to instrumentaion API Aug 1, 2024
Comment on lines 125 to 133
public OpenTelemetryRum getOpenTelemetryRum() {
return openTelemetryRum;
}

@Override
public void install(
@NotNull Application application, @NotNull OpenTelemetryRum openTelemetryRum) {
this.openTelemetryRum = openTelemetryRum;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmmm, this feels weird to me. Installing does nothing but hold onto the instance, so that we can add a get() method to this instrumentation so that the lazy singletons can get at the instance. Shouldn't the install() method actually help do the creational work?

The lifecycle is further complicated / obfuscated by the lazy caching stuff in the singletons class.

Here's an idea: What if the install() method just passed the needed otel instance to a static factory method in the singletons class, and that is responsible for setting up the instrumenter and the dependent interceptors?

I made a demonstration PR to this branch to show you more what I'm talking about: LikeTheSalad#1

Note that in addition to the lifecycle being somewhat clearer, it also allows us to remove the otelRum instance, remove the lazy interceptor, and the cached supplier.

Copy link
Contributor Author

@LikeTheSalad LikeTheSalad Aug 2, 2024

Choose a reason for hiding this comment

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

Got it, thanks! I took a quick look and your approach looks a lot cleaner, although I'm concerned about removing the laziness of the singletons due to the timing between the instantiation of OkHttpClient objects and the OTel rum initialization. I remember it was a key issue when using GlobalOpenTelemetry, though maybe it's no longer the case. I'd like to discuss it further in the SIG just to make sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I've applied the changes suggested here taking into account what was discussed in the SIG meeting as well 👍

Copy link
Contributor

@breedx-splk breedx-splk left a comment

Choose a reason for hiding this comment

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

This seems largely ok to me, but I want us to discuss the lifecycle a bit more before we get too far down the road and establish a pattern for other library instrumentations.

Comment on lines +43 to +56
from
the [OkHttpInstrumentation](library/src/main/java/io/opentelemetry/instrumentation/library/okhttp/v3_0/OkHttpInstrumentation.java))
instance provided via the AndroidInstrumentationLoader as shown below:

```java
OkHttpInstrumentation instrumentation = AndroidInstrumentationLoader.getInstrumentation(OkHttpInstrumentation.class);

// Call `instrumentation` setters.
```

> [!NOTE]
> You must make sure to apply any configurations **before** initializing your OpenTelemetryRum
> instance (i.e. calling OpenTelemetryRum.builder()...build()). Otherwise your configs won't be
> taken into account during the RUM initialization process.
Copy link
Contributor

Choose a reason for hiding this comment

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

I like these docs and am wondering how we might document this more broadly in the near future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I've created this issue for it: #532

Copy link
Contributor

@breedx-splk breedx-splk left a comment

Choose a reason for hiding this comment

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

👍🏻

@LikeTheSalad LikeTheSalad merged commit 64f42d7 into open-telemetry:main Aug 14, 2024
3 checks passed
@LikeTheSalad LikeTheSalad deleted the okhttp-migration branch August 23, 2024 09:58
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.

3 participants