Skip to content

refactor(config): create a new DD_API_KEY config on internal/config#4712

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
mainfrom
pr/4700-eunskin-add-api-key
May 5, 2026
Merged

refactor(config): create a new DD_API_KEY config on internal/config#4712
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
mainfrom
pr/4700-eunskin-add-api-key

Conversation

@mtoffl01

@mtoffl01 mtoffl01 commented May 1, 2026

Copy link
Copy Markdown
Contributor

Copy of: #4700

What does this PR do?

Centralizes DD_API_KEY access through internalConfig.APIKey()
instead of reading the environment variable directly via env.Get("DD_API_KEY").

Changes

  • internal/config/config.go — Add APIKey() method to internal config
  • internal/config/config_test.go — Add test case for APIKey()
  • ddtrace/tracer/option.go — Replace env.Get("DD_API_KEY") with c.internalConfig.APIKey()
  • ddtrace/tracer/telemetry.go — Replace env.Get("DD_API_KEY") with c.internalConfig.APIKey(), remove unused env import

Testing

cd dd-trace-go
go test ./internal/config -run '^TestAPIKey$' -count=1 -v
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

go test ./ddtrace/tracer/... -run Telemetry -count=1 -v
go test ./internal/llmobs/... -count=1
go test ./ddtrace/tracer/... -count=1
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

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • New code is free of linting errors. You can check this by running make lint locally.
  • New code doesn't break existing tests. You can check this by running make test locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • All generated files are up to date. You can check this by running make generate locally.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild. Make sure all nested modules are up to date by running make fix-modules locally.

Unsure? Have a question? Request a review!

@mtoffl01
mtoffl01 requested review from a team as code owners May 1, 2026 16:51

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +883 to +885
cfg := Get()
require.NotNil(t, cfg)
assert.Equal(t, "", cfg.APIKey())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

via os.UnsetEnv?

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented May 1, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 61.48% (-0.06%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 6a9cf4d | Docs | Datadog PR Page | Give us feedback!

@codecov

codecov Bot commented May 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.19%. Comparing base (09bfbae) to head (6a9cf4d).

Additional details and impacted files
Files with missing lines Coverage Δ
ddtrace/tracer/option.go 85.07% <100.00%> (-2.16%) ⬇️
ddtrace/tracer/telemetry.go 89.02% <100.00%> (-3.66%) ⬇️
internal/config/config.go 61.11% <100.00%> (-3.75%) ⬇️

... and 274 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pr-commenter

pr-commenter Bot commented May 1, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-05-01 18:13:04

Comparing candidate commit 6a9cf4d in PR branch pr/4700-eunskin-add-api-key with baseline commit 09bfbae in branch main.

Found 0 performance improvements and 1 performance regressions! Performance is the same for 269 metrics, 8 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:BenchmarkPayloadVersions/simple_1000spans/v0_4-25

  • 🟥 execution_time [+5.887µs; +7.125µs] or [+2.948%; +3.568%]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants