Skip to content

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

Closed
eunskin wants to merge 3 commits into
DataDog:mainfrom
eunskin:add_api_key
Closed

refactor(config): create a new DD_API_KEY config on internal/config#4700
eunskin wants to merge 3 commits into
DataDog:mainfrom
eunskin:add_api_key

Conversation

@eunskin

@eunskin eunskin commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

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!

@eunskin
eunskin requested review from a team as code owners April 28, 2026 06:33
@codecov

codecov Bot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.14%. Comparing base (7e5ced7) to head (e8727f8).

Additional details and impacted files
Files with missing lines Coverage Δ
ddtrace/tracer/option.go 85.07% <100.00%> (ø)
ddtrace/tracer/telemetry.go 89.02% <100.00%> (ø)
internal/config/config.go 61.11% <100.00%> (+61.11%) ⬆️

... and 445 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.

@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: 5d8fe30e5e

ℹ️ 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 thread internal/config/config.go Outdated

@mtoffl01 mtoffl01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM so I am giving approval, but be sure to address the couple of nits I left. Also, make sure that CI is green. The failures look unrelated to your changes so you can:

  • update your branch with main
  • rerun CI
    Let me know if it doesn't green-ify after that 😄

Comment thread ddtrace/tracer/telemetry.go Outdated
Comment thread internal/config/config.go Outdated

@darccio darccio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good!

@datadog-datadog-prod-us1

This comment has been minimized.

@eunskin

eunskin commented May 4, 2026

Copy link
Copy Markdown
Collaborator Author

closed this PR and created a new PR

@eunskin eunskin closed this May 4, 2026
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request May 5, 2026
…4712)


### 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

```bash
cd dd-trace-go
go test ./internal/config -run '^TestAPIKey$' -count=1 -v
```

<details>
<summary>Result</summary>

=== 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  

</details>

```bash
go test ./ddtrace/tracer/... -run Telemetry -count=1 -v
go test ./internal/llmobs/... -count=1
go test ./ddtrace/tracer/... -count=1
```

<details>
<summary>Result</summary>

--- 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

</details>



<!--
* A brief description of the change being made with this pull request.
* If the description here cannot be expressed in a succinct form, consider
  opening multiple pull requests instead of a single one.
-->

### Motivation

- [https://datadoghq.atlassian.net/browse/APMAPI-1895](https://datadoghq.atlassian.net/browse/APMAPI-1895) 

<!--
* What inspired you to submit this pull request?
* Link any related GitHub issues or PRs here.
* If this resolves a GitHub issue, include "Fixes #XXXX" to link the issue and auto-close it on merge.
-->

### Reviewer's Checklist
<!--
* Authors can use this list as a reference to ensure that there are no problems
  during the review but the signing off is to be done by the reviewer(s).
-->

- [ ] Changed code has unit tests for its functionality at or near 100% coverage.
- [ ] [System-Tests](https://github.com/DataDog/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!


Co-authored-by: hannahkm <[email protected]>
Co-authored-by: eunskin <[email protected]>
Co-authored-by: mikayla.toffler <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants