-
Notifications
You must be signed in to change notification settings - Fork 42
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
OkHttp migration to instrumentaion API #505
Conversation
public OpenTelemetryRum getOpenTelemetryRum() { | ||
return openTelemetryRum; | ||
} | ||
|
||
@Override | ||
public void install( | ||
@NotNull Application application, @NotNull OpenTelemetryRum openTelemetryRum) { | ||
this.openTelemetryRum = openTelemetryRum; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
There was a problem hiding this 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.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
Migrating the okhttp instrumentation.
This should also address this issue: #433 since now
GlobalOpenTelemetry
isn't needed.