refactor(config): create a new DD_API_KEY config on internal/config#4712
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8727f8e48
ℹ️ 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".
| cfg := Get() | ||
| require.NotNil(t, cfg) | ||
| assert.Equal(t, "", cfg.APIKey()) |
There was a problem hiding this comment.
Clear DD_API_KEY in the unset API key subtest
This subtest assumes DD_API_KEY is absent, but it never unsets it before calling Get(). When developers run tests with DD_API_KEY already set in their shell/CI environment, cfg.APIKey() will be non-empty and this assertion fails even though the code is correct, making the test environment-dependent and flaky. Explicitly setting DD_API_KEY to an empty value in this subtest would make it deterministic.
Useful? React with 👍 / 👎.
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 6a9cf4d | Docs | Datadog PR Page | Give us feedback! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
🚀 New features to boost your workflow:
|
BenchmarksBenchmark execution time: 2026-05-01 18:13:04 Comparing candidate commit 6a9cf4d in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 269 metrics, 8 unstable metrics.
|
4e76530
into
main
Copy of: #4700
What does this PR do?
Centralizes
DD_API_KEYaccess throughinternalConfig.APIKey()instead of reading the environment variable directly via
env.Get("DD_API_KEY").Changes
internal/config/config.go— AddAPIKey()method to internal configinternal/config/config_test.go— Add test case forAPIKey()ddtrace/tracer/option.go— Replaceenv.Get("DD_API_KEY")withc.internalConfig.APIKey()ddtrace/tracer/telemetry.go— Replaceenv.Get("DD_API_KEY")withc.internalConfig.APIKey(), remove unusedenvimportTesting
Result
=== RUN TestAPIKey
=== RUN TestAPIKey/from_env
=== RUN TestAPIKey/default_empty_when_unset
--- PASS: TestAPIKey (0.00s)
--- PASS: TestAPIKey/from_env (0.00s)
--- PASS: TestAPIKey/default_empty_when_unset (0.00s)
PASS
ok github.com/DataDog/dd-trace-go/v2/internal/config 0.836s
Result
--- PASS: TestTelemetryEnabled (0.55s)
--- PASS: TestTelemetryEnabled/tracer_start (0.25s)
--- PASS: TestTelemetryEnabled/telemetry_customer_or_dynamic_rules (0.04s)
--- PASS: TestTelemetryEnabled/telemetry_local_rules (0.02s)
--- PASS: TestTelemetryEnabled/tracer_start_with_empty_rules (0.01s)
--- PASS: TestTelemetryEnabled/profiler_start,_tracer_start (0.20s)
--- PASS: TestTelemetryEnabled/orchestrion_telemetry (0.03s)
PASS
ok github.com/DataDog/dd-trace-go/v2/ddtrace/tracer 1.923s
Motivation
Reviewer's Checklist
make lintlocally.make testlocally.make generatelocally.make fix-moduleslocally.Unsure? Have a question? Request a review!