[EXPORTER] Add custom HTTP client#4071
Conversation
|
Could you please add a test to use a simple custom http client? |
|
Thanks @ltowarek. Couple of review comments as of now -
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4071 +/- ##
==========================================
+ Coverage 82.00% 82.51% +0.52%
==========================================
Files 385 387 +2
Lines 16030 16435 +405
==========================================
+ Hits 13143 13559 +416
+ Misses 2887 2876 -11
🚀 New features to boost your workflow:
|
dbarker
left a comment
There was a problem hiding this comment.
Thanks for the PR. Please see the question below.
|
Thanks for the feedback! I think I've covered everything in the new patch set:
|
marcalff
left a comment
There was a problem hiding this comment.
Thanks for the contribution.
Please consider to use:
- an abstract class
HttpClientFactory, with virtual methods forCreateandCreateSync - A child class
HttpCurlClientFactory, which implement this for CURL - a HttpCurlClientFactory::singleton
Everywhere the static method HttpClientFactory::Create() is used today, pass a HttpClientFactory instance instead, taken as input parameter.
The user of an HTTP client can then decide which implementation to use:
- pass HttpCurlClientFactory::singleton to use CURL
- pass an instance of MyOwnHttpClientFactory for alternate implementations.
It should be possible to mix CURL and non CURL HTTP clients in the same binary, for example:
- send traces using HTTP + CURL to endpoint A
- send metrics using HTTP + alternate to endpoint B
5147826 to
516c51b
Compare
@marcalff, it looks like a good idea. My main goal with the current PR is build-time configuration - to enable I think runtime changes should be a part of a separate PR which I'm open to working on. |
|
Thanks for adding the runtime factory path. I think this is moving in the right direction, but can we make the injection story consistent across all HTTP exporters? Right now Also, after making |
…to fix/issue-24-custom-http-client
|
@lalitb thanks for the feedback! I've addressed your comments in the latest commits. |
…to fix/issue-24-custom-http-client
| } // namespace | ||
|
|
||
| OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options) | ||
| : OtlpHttpClient(std::move(options), ext::http::client::GetDefaultHttpClientFactory()) |
There was a problem hiding this comment.
Can we keep the custom-client path independent from the default-client path?
If a user explicitly passes a custom HttpClientFactory or HttpClient, that should not require the default curl factory symbol to exist. The default factory should only be needed when a default constructor/factory overload is actually used.
Right now the exporter object files still contain default-client constructors like this one that reference GetDefaultHttpClientFactory(). In a no-curl/custom-only build, that can still create a link-time dependency on a symbol the user did not intend to use. Could we guard the default-client overloads when no default backend exists, or provide a no-curl fallback that fails clearly only if the default path is used?
Fixes #2084
Changes
Adds a way to provide a custom HTTP client instead of the default
libcurl-based client.The main motivation are embedded and cross-compiled targets where libcurl is unavailable. A working example for ESP32S3 using ESP-IDF's
esp_http_clientas the transport backend is at ltowarek/esp-opentelemetry-cpp#30.