Skip to content

feat: route feature flag config through the extension when no API key is set - #867

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

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

Jira: SVLS-10161
Same change for Python: DataDog/datadog-lambda-python#890

What does this PR do?

In handler.mjs, before initTracer(), 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 and DATADOG_API_KEY are both unset, empty or whitespace.
  3. The customer has not set DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL.

In every other case the wrapper changes nothing.

Motivation

dd-trace's feature flag provider needs an API key in the tracer's environment. 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 tracer uses that route only when this variable is set.

Why these conditions

  • No API key: the wrapper 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. Customers with a key keep going straight to the CDN, and customers without one are already broken.
  • DATADOG_API_KEY too: unlike dd-trace-py, dd-trace-js reads DATADOG_API_KEY as an alias of DD_API_KEY, so those customers get flags from the CDN today. Whitespace counts as unset because dd-trace trims the key.
  • Extension present: without the extension, port 8126 refuses the connection. Leaving the variable unset keeps dd-trace's clearer DD_API_KEY is required error.

The logic is in src/utils/feature-flags.ts so it can be unit-tested. handler.mjs calls it next to the other dd-trace defaults.

Gotchas reviewers should know about

  • Extension older than v104: #1510 shipped after v103. With v103 or older, customers without a 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.
  • Only the layer's handler redirect applies it. Like the other defaults in handler.mjs, it does nothing for customers who call datadog() themselves, or who preload dd-trace with NODE_OPTIONS=--require dd-trace/init.
  • dd-trace versions: supported since 5.116.0 and 6.15.0. The layer pins ^5.136.0 || ^6.24.0. An older dd-trace bundled in the function (which initTracer prefers) ignores 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

Unit tests in src/utils/feature-flags.spec.ts cover the extension present or absent, each API key variable set, empty or whitespace, 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.)

Check all that apply

  • 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
  • This PR passes the integration tests (ask a Datadog member to run the tests)

🤖 Generated with Claude Code

… is set

When the extension is present and DD_API_KEY, DATADOG_API_KEY and
DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL are all unset,
set the base URL to http://127.0.0.1:8126 before dd-trace initializes,
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:40

@datadog-official datadog-official 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

Existing API-key and nonblank custom-endpoint configurations retain their routing. The extension default is applied before tracer initialization only when the extension is present and those values are absent.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 96326b0

This branch has not been deployed

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