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.
There was a problem hiding this comment.
I thought about that but I ended up adding more parameters here. However you have a point here, maybe taking the same approach as in TelemetryClientConfig would be better? WDYT?
| 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...
There was a problem hiding this comment.
I agree, we shouldn't be changing behaviour in a library based on environment vars, it can cause problems for our consumers. Since the scope for the PR is to solve problems with the releases we can fix the env var issue in a subsequent PR?
The aim is to reduce the ways a crate can consume a type. If the consumer only uses telemetry it would be more than ok re-exporting the symbols through telemetry so there is only one source for them. Hoewever in our current situation we would be coupling telemetry to common and that will cascade into releasing major versions for multiple crates across the workspace. |
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.