refactor: native HTTP client#18792
Conversation
Codeowners resolved as |
We refactor the HTTP connection classes to use the new native HTTP connection. This way we can avoid the use of the http.client from the standard library, increasing isolation from the runtime.
8e0dfbb to
044993d
Compare
|
BenchmarksBenchmark execution time: 2026-07-17 11:20:17 Comparing candidate commit 75cf8e7 in PR branch Found 0 performance improvements and 5 performance regressions! Performance is the same for 615 metrics, 11 unstable metrics. scenario:iastaspects-swapcase_aspect
scenario:iastaspectsospath-ospathbasename_aspect
scenario:span-start
scenario:telemetryaddmetric-1-count-metric-1-times
scenario:tracer-small
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e3da075fa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
ecaa757 to
c3c115b
Compare
yannham
left a comment
There was a problem hiding this comment.
LGTM as far as I can tell, although my Python fu is limited - I came to review the Rust part but it's rather thin 😅
c3c115b to
fd75c45
Compare
1be8581 to
8aaf9ec
Compare
8aaf9ec to
fdc4361
Compare
Circular import analysis
|
|
requires #19005 |
9ed6273 to
f6fbf1f
Compare
christophe-papazian
left a comment
There was a problem hiding this comment.
Two potential blockers found during review, both on production transport paths. Details inline. Not requesting changes — flagging for confirmation, since each is reproducible.
There was a problem hiding this comment.
Pull request overview
This PR refactors ddtrace’s internal HTTP transport to use the native Rust HTTP client end-to-end (including UDS), reducing reliance on http.client/Python sockets and updating writers/tests to match the new behavior.
Changes:
- Introduces a native-backed
ddtrace.internal.httpconnection/response layer with client pooling and fork-safety cache clearing. - Removes the legacy UDS
http.client-based implementation and updates internal callers/writers to handle URL path prefixes explicitly where needed. - Updates tests to mock at the native-connection layer and adjusts expectations for error types and header normalization; adds crypto-provider initialization for rustls.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/tracer/test_writer.py | Updates UDS tests to use HTTPConnection(unix://…) and expands expected exception types for native client errors. |
| tests/tracer/test_endpoint_config.py | Switches endpoint-config tests to mock ddtrace.internal.http.HTTPResponse and removes http.client-specific mocking. |
| tests/telemetry/test_writer.py | Replaces httpretty usage with NativeHTTPConnection.getresponse mocking and normalizes header lookups. |
| tests/telemetry/test_telemetry.py | Makes header assertions case-insensitive to match native client normalization. |
| tests/llmobs/test_llmobs_span_agentless_writer.py | Adds regression test for preserving intake URL path prefixes; updates timeout test to patch HTTPConnection. |
| tests/llmobs/test_llmobs_service.py | Updates fixture patch target from get_connection to HTTPConnection. |
| tests/internal/test_utils_http.py | Replaces socket-level mocking with NativeHTTPConnection.getresponse mocking for connector tests. |
| tests/internal/test_auto.py | Adjusts gevent/socket-patching expectations to assert no Python-socket dependency in the new connection. |
| src/native/http_client/client.rs | Adds one-time rustls crypto-provider installation before client creation. |
| src/native/Cargo.toml | Adds explicit rustls dependency with ring provider support. |
| ddtrace/llmobs/_writer.py | Uses HTTPConnection directly and updates request targets to avoid losing base-path prefixes. |
| ddtrace/llmobs/_http.py | Replaces LLMObs-local connection logic with re-exports from internal HTTP utilities (behavior change). |
| ddtrace/internal/writer/writer.py | Adds intake base-path handling so writer requests include configured HTTP path prefixes (but not unix socket paths). |
| ddtrace/internal/utils/http.py | Simplifies get_connection() to return the native HTTPConnection and explicitly strips URL paths. |
| ddtrace/internal/uds.py | Removes the legacy UDSHTTPConnection implementation. |
| ddtrace/internal/telemetry/writer.py | Updates return type annotations to use internal HTTPResponse. |
| ddtrace/internal/native_runtime.py | Refactors singleton creation to functools.cache. |
| ddtrace/internal/http.py | Implements the native-backed HTTPConnection/HTTPResponse wrappers with pooled client caching and container header injection. |
| ddtrace/internal/ci_visibility/_api_client.py | Updates connection typing to use HTTPConnection instead of the removed union type. |
| ddtrace/bootstrap/cloning.py | Removes pre-imports of the deleted UDS module; adjusts imports during module cleanup. |
| ddtrace/aiguard/_api_client.py | Reworks request execution to build native HTTP connections and send path-only requests. |
| benchmarks/suitespec.yml | Removes the deleted UDS module from the benchmark component list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
We refactor the HTTP connection classes to use the new native HTTP connection. This way we can avoid the use of the http.client from the standard library, increasing isolation from the runtime.