Skip to content

feat(internal/env): add env var config validation#3746

Merged
dd-mergequeue[bot] merged 38 commits into
mainfrom
ben.db/APMAPI-1450-wrap-os-env-calls
Sep 8, 2025
Merged

feat(internal/env): add env var config validation#3746
dd-mergequeue[bot] merged 38 commits into
mainfrom
ben.db/APMAPI-1450-wrap-os-env-calls

Conversation

@genesor

@genesor genesor commented Jul 10, 2025

Copy link
Copy Markdown
Member

What does this PR do?

This PR adds a new package internal/env that wraps os.Getenv and os.LookupEnv calls, allowing only known environment variables to be used.

All environment variables/configuration keys are now listed in internal/env/supported_configurations.json and then generated as a Go map in internal/env/supported_configurations.gen.go after running the generate command.

This PR includes new CI steps/jobs:

  • A golangci-lint rule (forbidigo) that forbids the use of os.Getenv and os.LookupEnv here
  • A config-inversion step that runs after go test (or equivalent) steps to check for the introduction of new configuration keys here
  • Config-inversion GitLab jobs that check existence against the configuration registry and mark configuration keys upon version release here

Most interesting parts to review:

  • internal/env package
    • Contains the wrapping and validation of os calls
    • Includes code that runs only during unit tests (limited by testing.Testing() being true only in go test scenarios) that adds environment variables to the JSON file
  • instrumentation/env package
  • configinverter script
  • CONTRIBUTING.md documentation for environment variables
  • DD-API-KEY handled via alias system part of config inversion.

Most of the changes involve migrating os calls and adding new tests to cover missing environment variables.

Motivation

This PR main goal is to control the use of environment variables in the tracer so that we have a way to list and document every available configuration.

There is a new configuration registry implemented on the feature parity dashboard that contains all the configuration keys for every tracer.

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 golangci-lint run locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

@pr-commenter

pr-commenter Bot commented Jul 10, 2025

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2025-09-08 09:15:53

Comparing candidate commit d3d98c0 in PR branch ben.db/APMAPI-1450-wrap-os-env-calls with baseline commit 222fce9 in branch main.

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

scenario:BenchmarkMetrics/gauge/get-handle-24

  • 🟥 execution_time [+7.350ns; +9.570ns] or [+2.727%; +3.550%]

@genesor
genesor force-pushed the ben.db/APMAPI-1450-wrap-os-env-calls branch 7 times, most recently from f6cd4c5 to f7a5a8b Compare July 16, 2025 13:38
@genesor
genesor force-pushed the ben.db/APMAPI-1450-wrap-os-env-calls branch 4 times, most recently from a139e40 to 587d59b Compare July 17, 2025 15:54
@genesor
genesor force-pushed the ben.db/APMAPI-1450-wrap-os-env-calls branch 3 times, most recently from 2c3b7c4 to bc54e6a Compare August 1, 2025 12:37
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Aug 1, 2025

Copy link
Copy Markdown

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: d3d98c0 | Docs | Was this helpful? Give us feedback!

@genesor
genesor force-pushed the ben.db/APMAPI-1450-wrap-os-env-calls branch 6 times, most recently from e2551ba to 18adcab Compare August 4, 2025 11:54
@genesor genesor changed the title [WIP] internal: feat add configuration validation feat(internal/env): add env var config inversion allowlisting feature Aug 4, 2025
@github-actions github-actions Bot added the apm:ecosystem contrib/* related feature requests or bugs label Aug 4, 2025
@genesor
genesor force-pushed the ben.db/APMAPI-1450-wrap-os-env-calls branch 3 times, most recently from 3299683 to abf0c6e Compare August 8, 2025 17:28
@genesor
genesor marked this pull request as ready for review August 11, 2025 13:54
@genesor
genesor requested review from a team as code owners August 11, 2025 13:54
@genesor
genesor force-pushed the ben.db/APMAPI-1450-wrap-os-env-calls branch from 7743838 to 3a4ffcf Compare September 5, 2025 14:08
@genesor
genesor force-pushed the ben.db/APMAPI-1450-wrap-os-env-calls branch from 3a4ffcf to d5e5a71 Compare September 8, 2025 08:25
@genesor

genesor commented Sep 8, 2025

Copy link
Copy Markdown
Member Author

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Sep 8, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-09-08 12:33:46 UTC ℹ️ Start processing command /merge


2025-09-08 12:33:56 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 15m (p90).


2025-09-08 12:47:01 UTC ℹ️ MergeQueue: This merge request was merged

@dd-mergequeue
dd-mergequeue Bot merged commit e7e5c7f into main Sep 8, 2025
291 of 295 checks passed
@dd-mergequeue
dd-mergequeue Bot deleted the ben.db/APMAPI-1450-wrap-os-env-calls branch September 8, 2025 12:46
kakkoyun pushed a commit to kakkoyun/dd-trace-go that referenced this pull request Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apm:ecosystem contrib/* related feature requests or bugs mergequeue-status: done

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants