Skip to content

feat: route feature flag config through the extension when DD_API_KEY is unset - #293

Closed
purple4reina wants to merge 1 commit into
mainfrom
rey.abolofia/ffe-extension-base-url
Closed

purple4reina wants to merge 1 commit into
mainfrom
rey.abolofia/ffe-extension-base-url

Conversation

@purple4reina

@purple4reina purple4reina commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

dd-trace-go PR

DataDog/dd-trace-go#5904 (same change in contrib/aws/datadog-lambda-go)

What does this PR do?

Jira: SVLS-10161
Same change for Python (DataDog/datadog-lambda-python#890), Node (DataDog/datadog-lambda-js#867) and Ruby (DataDog/datadog-lambda-rb#173).

A package init() sets DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL=http://127.0.0.1:8126 only when all of these are true:

  1. The extension is present (/opt/extensions/datadog-agent exists).
  2. DD_API_KEY is unset or empty.
  3. The customer has not set DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL.

In every other case it changes nothing.

Motivation

dd-trace-go's feature flag provider needs DD_API_KEY. Customers who keep the key in DD_API_KEY_SECRET_ARN, DD_API_KEY_SSM_NAME or DD_KMS_API_KEY get PROVIDER_NOT_READY on every flag check (IR-63040). DataDog/datadog-lambda-extension#1510 adds a route on the extension's trace agent that fetches flag config with the key the extension resolved. The provider uses that route only when this variable is set.

Why these conditions

  • DD_API_KEY unset: the library cannot tell which extension version is installed. An extension without the #1510 route returns 404, and the tracer does not fall back to the CDN. With this condition, nothing that works today can break: DD_API_KEY users keep going straight to the CDN, and customers without it are already broken. dd-trace-go reads only DD_API_KEY (its DD-API-KEY alias is not a valid Lambda env var name) and does not trim it, so neither do we.
  • Extension present: without the extension, port 8126 refuses the connection. Leaving the variable unset keeps the tracer's clearer error.
  • Base URL not set: an explicit customer value wins.

Why a package init()

NewDatadogProvider reads the cached internal/config instance (config.Get()). A typical main() creates the provider before lambda.Start(ddlambda.WrapFunction(...)), so setting the variable in WrapFunction (where setupAppSec sets its env vars) would be too late. init() runs before main(). No dd-trace-go package reads internal/config during its own init (the OTel bridge loads it lazily), and tracer.Start re-reads the environment through config.CreateNew().

Gotchas reviewers should know about

  • Extension older than v104: #1510 shipped after v103. With v103 or older, customers without DD_API_KEY get 404 instead of DD_API_KEY is required. Flags fail either way; only the log message changes. This can be merged before v104.
  • dd-trace-go version: this repo requires dd-trace-go.v1 v1.74.6 (which builds on dd-trace-go/v2 v2.2.3). The base URL needs dd-trace-go/v2 v2.11.0 or later, which a customer using the v2 openfeature provider gets through their own go.mod. With an older v2, the variable is ignored.
  • Runs on import: the init() runs in any binary that imports this package, whether or not it wraps a handler. It does nothing unless /opt/extensions/datadog-agent exists.
  • Provider created during another package's init: a provider built in a package-level var or init() of a package that Go initializes before this one would still miss the variable.
  • Extension cannot resolve the key (wrong ARN, missing IAM permission): the route returns 403, and the provider logs it and does not retry.
  • Port is hard-coded to 8126. That's where the extension's trace agent listens in Lambda.
  • DD_FEATURE_FLAGS_CONFIGURATION_SOURCE=remote_config or DD_FEATURE_FLAGS_ENABLED=false: the base URL applies only to the agentless source, so the variable has no effect.

Testing Guidelines

TestSetFeatureFlagsBaseURL covers the extension present or absent, DD_API_KEY set or unset, a secret ARN only, and a base URL the customer already set.

Types of changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Checklist

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog

🤖 Generated with Claude Code

… is unset

When the extension is present and DD_API_KEY and
DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL are both unset,
set the base URL to http://127.0.0.1:8126 in a package init, so
customers who use DD_API_KEY_SECRET_ARN (or SSM/KMS) get feature flags
through the extension.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@purple4reina
purple4reina requested a review from a team as a code owner November 17, 2026 06:50

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 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.

Bits Code Review: PASS

More details

The routing guards preserve existing API-key and custom-URL configurations, and the specialist confirmed the intended initialization behavior against dd-trace-go v2.11.0. End-to-end routing through the extension was not exercised.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 57d07fb

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.

1 participant