opencensus-python icon indicating copy to clipboard operation
opencensus-python copied to clipboard

Enhance httpx tracing

Open nhtgl opened this issue 3 years ago • 6 comments

In httpx Advanced Usage docs there is a chapter Request Instances where they show alternative way of sending requests, where you can use once initialized client to send various of different requests to the same host.

Current implementation of tracing doesn't cover that use case, because calling structure is different while function Client.send is actually what is common and it returns Response object.

In a nutshell:

class Client:
    ...
    def request(...) -> Response:
        ...
        request = self.build_request(...)
        return self.send(request)

so when I have something like this:

req_1 = httpx.Request(...)
req_2 = httpx.Request(...)

with httpx.Client() as client:
    client.send(req_1)
    client.send(req_2)

It's not traced.

The solution in this PR will cover both use cases - the standard one (requests-like) and the advanced usage.

nhtgl avatar Jan 24 '23 17:01 nhtgl

@macieyng update the changelog

miqm avatar Jan 26 '23 10:01 miqm

Thanks @lzchen for running the pipeline. I will fix it tomorrow.

nhtgl avatar Feb 02 '23 21:02 nhtgl

@lzchen ready for running the pipeline 🚀 My bad for not running tox locally before pushing. It turns out that implementation has to be a little bit different from requests. @inirudebwoy can you review this too, please?

nhtgl avatar Feb 03 '23 16:02 nhtgl

@lzchen can you run the pipeline? Thanks! 🙏

nhtgl avatar Feb 06 '23 17:02 nhtgl

@aabmass @jeremydvoss @hectorhdzg @calleo 🙏

nhtgl avatar Feb 07 '23 12:02 nhtgl

Failed to import opencensus.ext.zipkin.trace_exporter.
Possible hints:
* AttributeError: module 'opencensus' has no attribute 'ext'
* ModuleNotFoundError: No module named 'opencensus.ext'
Failed to import opencensus.ext.stackdriver.trace_exporter.
Possible hints:
* AttributeError: module 'opencensus' has no attribute 'ext'
* ModuleNotFoundError: No module named 'opencensus.ext'

That's not something that I touched and on my machine it fails even earlier, but that's because I'm running it locally on mac. @lzchen can I get your support with sorting this out?

nhtgl avatar Feb 08 '23 20:02 nhtgl