refactor(libdd-telemetry)!: avoid leaking libdd-common types in the public API#2152
refactor(libdd-telemetry)!: avoid leaking libdd-common types in the public API#2152hoolioh wants to merge 1 commit into
Conversation
|
Clippy Allow Annotation ReportComparing clippy allow annotations between branches:
Summary by Rule
Annotation Counts by File
Annotation Stats by Crate
About This ReportThis report tracks Clippy allow annotations for specific rules, showing how they've changed in this PR. Decreasing the number of these annotations generally improves code quality. |
📚 Documentation Check Results📦
|
🔒 Cargo Deny Results📦
|
Artifact Size Benchmark Reportaarch64-alpine-linux-musl
aarch64-unknown-linux-gnu
libdatadog-x64-windows
libdatadog-x86-windows
x86_64-alpine-linux-musl
x86_64-unknown-linux-gnu
|
276e7c6 to
2064bd2
Compare
2064bd2 to
d482c08
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d482c08f56
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if !api_key.is_empty() { | ||
| try_c!(config.set_endpoint_api_key(Some(api_key.as_ref()))); | ||
| } |
There was a problem hiding this comment.
Clear stale API keys when replacing endpoints
When the builder was instantiated from an environment with _DD_DIRECT_SUBMISSION_ENABLED=true and DD_API_KEY set, passing an empty api_key here no longer clears that key while replacing the endpoint. The previous Endpoint-based setter replaced the whole endpoint, so ddog_endpoint_from_url(...) produced an endpoint with no API key; now the old key is preserved and set_endpoint_url rewrites HTTP URLs to the direct-submission path, causing callers that explicitly configure an agent/file endpoint without a key to send with the stale API key and potentially to /api/v2/apmtelemetry instead of the agent proxy path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I suppose the solution is to set to None if the api key is empty, instead of not setting anything?
yannham
left a comment
There was a problem hiding this comment.
I initially thought you wanted to get rid of the libdd-common dependency for libdd-telemetry. But if I understand correctly, there's still a Endpoint lurking there internally, is that correct? Then I'm not sure I understand the motivation. Is it just to avoid having to add explicitly libdd-common for end-user crates just to import Endpoint? Then why not just re-export it from libdd-telemetry, if it's there anyway?
| if !api_key.is_empty() { | ||
| try_c!(config.set_endpoint_api_key(Some(api_key.as_ref()))); | ||
| } |
There was a problem hiding this comment.
I suppose the solution is to set to None if the api key is empty, instead of not setting anything?
| url: ffi::CharSlice, | ||
| api_key: ffi::CharSlice, | ||
| timeout_ms: u64, | ||
| test_token: ffi::CharSlice, | ||
| use_system_resolver: bool, |
There was a problem hiding this comment.
The endpoint seems to carry quite a bit of different fields, that now have to be set manually one by one and inflate function arguments (there's a risk to forget about one field when setting the endpoint now instead of cfg.set_endpoint previously). I'm just thinking out loud, but would it make sense to re-introduce an Endpoint (or a different name) but stand-alone in libdd-telemetry that packs url, api_key, timeout_ms, together ? At least if we always want to set them all at once.
| let mut config = Config::from_env(); | ||
| config.direct_submission_enabled = true; | ||
| config.debug_enabled = true; | ||
| let api_key = std::env::var("DD_API_KEY").unwrap(); |
There was a problem hiding this comment.
I know this existed before this PR, but we should avoid reading env vars in libdatadog. Not sure this one can really be avoided in a cross-platform way though...
What does this PR do?
Break down endpoint settings into smaller functions which accept primitive types in order not to leak libdd-common types through the public API.
Motivation
Most of downstream projects don't use the Endpoint abstraction because it's thought to handle connections with intake/agent so forcing them to import libdd-common just to configure the connection doesn't seem right.