Skip to content

okhttp: use request tag to carry context when it is available#15977

Merged
laurit merged 2 commits intoopen-telemetry:mainfrom
laurit:okhttp-tag
Jan 27, 2026
Merged

okhttp: use request tag to carry context when it is available#15977
laurit merged 2 commits intoopen-telemetry:mainfrom
laurit:okhttp-tag

Conversation

@laurit
Copy link
Copy Markdown
Contributor

@laurit laurit commented Jan 23, 2026

In library instrumentations virtual fields rely on weak references. We should use other means when possible.

@laurit laurit requested a review from a team as a code owner January 23, 2026 15:08
@laurit
Copy link
Copy Markdown
Contributor Author

laurit commented Jan 26, 2026

Using tags could also be handy for #15664 where currently context is kept in maps. Though there context for the current span is needed but here we keep the parent context.

@surbhiia
Copy link
Copy Markdown

surbhiia commented Jan 26, 2026

Using tags could also be handy for #15664 where currently context is kept in maps. Though there context for the current span is needed but here we keep the parent context.

Actually storing context on the request tag doesn't work for EventListener as the call object available in the EventListener is immutable and references the original request and not the modified request with span context from the TracingInterceptor. I did try using request tag in #15664 but it did not work for this reason.

It was confusing to me first as tags work from one interceptor to next as chain contains the modified request and I thought similarly it should work for event listener but event listener references the immutable call object which only contains the original request.

Here it worked when request to context map was used in earlier solution as the ContextInterceptor that references the stored context is the very first interceptor so it ensures that chain.request() would return the original request. With the new solution there's no dependence on original request as all modified request will also contain the tags from the original request.

@laurit
Copy link
Copy Markdown
Contributor Author

laurit commented Jan 27, 2026

Actually storing context on the request tag doesn't work for EventListener as the call object available in the EventListener is immutable and references the original request and not the modified request with span context from the TracingInterceptor. I did try using request tag in #15664 but it did not work for this reason.

I'd imagine that these issues could be overcome by adding a mutable tag to the request when the call is created an updating it with the context for the created span once it becomes available.

@laurit laurit merged commit 208a79a into open-telemetry:main Jan 27, 2026
85 checks passed
@laurit laurit deleted the okhttp-tag branch January 27, 2026 12:32
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