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

Enhance httpx tracing

Open macieyng opened this issue 2 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.

macieyng avatar Jan 24 '23 17:01 macieyng

@macieyng update the changelog

miqm avatar Jan 26 '23 10:01 miqm

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

macieyng avatar Feb 02 '23 21:02 macieyng

@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?

macieyng avatar Feb 03 '23 16:02 macieyng

@lzchen can you run the pipeline? Thanks! 🙏

macieyng avatar Feb 06 '23 17:02 macieyng

@aabmass @jeremydvoss @hectorhdzg @calleo 🙏

macieyng avatar Feb 07 '23 12:02 macieyng

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?

macieyng avatar Feb 08 '23 20:02 macieyng