refactor(config): create a new DD_API_KEY config on internal/config#4700
refactor(config): create a new DD_API_KEY config on internal/config#4700eunskin wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
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 😄
This comment has been minimized.
This comment has been minimized.
|
closed this PR and created a new PR |
…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]>
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!