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

Implement a Call.Factory for okhttp 3.x+ library instrumentation #3812

Merged
merged 7 commits into from
Aug 18, 2021

Conversation

jkwatson
Copy link
Contributor

This now actually will handle async context connections correctly!

Request request = chain.request();
Context parentContext = TracingCallFactory.getCallingContextForRequest(request);
if (parentContext == null) {
parentContext = Context.current();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

does this seem like the right default, or should we not try to propagate at all if we don't have one in the cache?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not propagate at all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we don't propagate, then interceptor-only users who have wired up a Dispatcher and only use synchronous calls will lose the context propagation, correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok

Comment on lines +49 to +51
response.body().withCloseable {
return response.code()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's really important to close the response body always when using okhttp, otherwise we're leaking responses in our test code.

Copy link
Contributor

Choose a reason for hiding this comment

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

😱

instrumentation/okhttp/okhttp-3.0/library/README.md Outdated Show resolved Hide resolved
Request request = chain.request();
Context parentContext = TracingCallFactory.getCallingContextForRequest(request);
if (parentContext == null) {
parentContext = Context.current();
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not propagate at all

@Override
OkHttpClient.Builder configureClient(OkHttpClient.Builder clientBuilder) {
return clientBuilder
// The double "new Dispatcher" style is the simplest way to decorate the default executor.
Copy link
Contributor

Choose a reason for hiding this comment

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

Well it's also nice for this to be gone :)

Comment on lines +49 to +51
response.body().withCloseable {
return response.code()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

😱

return clientBuilder.build()
}

def "reused builder has one interceptor"() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Good move

@anuraaga
Copy link
Contributor

For the record, we see a similar issue as aws sdk instrumentation, where muzzle is forcing reflection where we otherwise wouldn't need it. An annotation approach to solving this seems like a nice Splunk intern project :-) (guess it's too late this year...)

@jkwatson jkwatson force-pushed the okhttp_3_library_context branch from 2675cdb to c1d65a2 Compare August 11, 2021 17:13
@jkwatson
Copy link
Contributor Author

One downside to this approach (not that there's a better one) is that libraries that only accept an actual OkHttpClient as a dependency won't be able to consume the Call.Factory and use it. I guess if users run into that, we can create issues in the relevant library and submit fixes. :)

Comment on lines 26 to 27
@Nullable private static Method timeoutMethod;
@Nullable private static Method cloneMethod;
Copy link
Member

Choose a reason for hiding this comment

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

Can we use MethodHandles instead of reflection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take a look. I've been meaning to learn how to use them, so this is a good chance!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. please take a look because I'm not sure how to test that it works without using reflection.

instrumentation/okhttp/okhttp-3.0/library/README.md Outdated Show resolved Hide resolved
instrumentation/okhttp/okhttp-3.0/library/README.md Outdated Show resolved Hide resolved
Comment on lines -28 to -31
@Override
boolean testCausalityWithCallback() {
false
}
Copy link
Member

Choose a reason for hiding this comment

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

🥳

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
@jkwatson
Copy link
Contributor Author

any idea what we need to do to get this thing to finish the checks?

@mateuszrzeszutek
Copy link
Member

Closed and reopened -- hope they'll get triggered now.

@anuraaga anuraaga merged commit 6dbb64e into open-telemetry:main Aug 18, 2021
@jkwatson jkwatson deleted the okhttp_3_library_context branch August 18, 2021 03: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.

5 participants