Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Generic http client handler does not work well with okhttp #1641

Open
@lmolkova

Description

@lmolkova

I'm trying to use HttpClientHandler with OkHttp and use it inside network interceptor.

When HttpClientHandler.handleStart is invoked, it supposed to inject header.
Unfortunately, OkHttp uses builder pattern to construct requests and the only way to add a header is through builder (see https://stackoverflow.com/questions/32196424/how-to-add-headers-to-okhttp-request-interceptor)

It is possible to supply HttpClientHandler with request builder, but it seems to be inefficient (re-building and extra allocations).

The only efficient way to instrument okhttp seems to be:

  1. create request builder
  2. start span
  3. inject trace context
  4. build request
  5. fill attributes (yes, you can fill them from request, but not the builder)

But this approach also does not work with the network interceptor (and it nice to be able track redirects and retries without thinking about the position in the handler list)

So I think the right long-term plan is to fix it on the okhttp side.

@rghetia am I missing something in the handler design? what http libs it intends to work with?

What version of OpenCensus are you using?

0.19.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions