Repository navigation
fix: respect explicit DD_LOGS_INJECTION when using the extension - #757
Merged
avangelillo merged 1 commit intoNov 6, 2026
Merged
Conversation
avangelillo
force-pushed
the
alex.angelillo/svls-9919-logs-injection-extension
branch
2 times, most recently
from
November 5, 2026 13:00
afc7423 to
7ce332c
Compare
avangelillo
force-pushed
the
alex.angelillo/svls-9919-logs-injection-extension
branch
3 times, most recently
from
November 6, 2026 15:54
f371e7c to
8b6eced
Compare
Previously the plugin forced DD_LOGS_INJECTION=false on every function when addExtension was true, ignoring function-level and provider-level values and custom.datadog.injectLogContext. DD_LOGS_INJECTION now resolves per function, first match wins: function-level value, explicit injectLogContext, provider-level value, then the default (true, or false with the extension). Null counts as unset. Without the extension, a provider-level DD_LOGS_INJECTION now also applies instead of being overridden by the default, unless injectLogContext is set explicitly. Fixes #747 (SVLS-9919) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
avangelillo
force-pushed
the
alex.angelillo/svls-9919-logs-injection-extension
branch
from
November 6, 2026 18:28
8b6eced to
cfef1da
Compare
avangelillo
marked this pull request as ready for review
November 6, 2026 18:33
nina9753
approved these changes
Nov 6, 2026
joepeeples
approved these changes
Nov 6, 2026
avangelillo
deleted the
alex.angelillo/svls-9919-logs-injection-extension
branch
November 6, 2026 19:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Stops the plugin from overriding a user-set
DD_LOGS_INJECTIONwhenaddExtension: true.DD_LOGS_INJECTIONnow resolves per function, first match wins:DD_LOGS_INJECTION.custom.datadog.injectLogContext.DD_LOGS_INJECTION, copied into the function's environment (the same patternaddDDEnvVarsuses forDD_SERVICE,DD_ENV, etc.).true, orfalsewhen the extension is used. That second case keeps the current default.A
nullvalue (an empty YAML key) counts as unset at every level.To tell an explicit
injectLogContextapart from the default,injectLogContextis removed fromdefaultConfigurationand is now optional inConfiguration.setEnvConfigurationtakes an optionalproviderEnvironment, andindex.tspassesprovider.environmentinto it.Motivation
Fixes #747 (SVLS-9919). Since #396,
DD_LOGS_INJECTION=falsewas forced whenever the extension was enabled. Function-level env, provider-level env andinjectLogContext: trueall had no effect. Users with JSON loggers such aspinocouldn't getdd.trace_id/dd.span_idin their logs without workarounds.Background: why #396 forced
false, and why this undoes it#396 (SLS-2166, June 2023) aimed to "deprecate DD_LOGS_INJECTION when using the Extension", because the extension correlates logs and traces by Lambda request ID. Follow-up PRs #401 here and DataDog/datadog-cdk-constructs#191 called it an "unneeded env var" and tried to stop adding it at all, to save env var space. Both were closed without merging. Nothing in that work argues for blocking users who set the variable themselves.
CDK parity:
datadog-cdk-constructsmade the same change in DataDog/datadog-cdk-constructs#188 withsetEnvIfUnset(DD_LOGS_INJECTION, "false"), which defaults tofalsewith the extension but keeps a value the user already set. That's still how it works today. Only this plugin overwrote the user's value unconditionally. This PR brings the plugin in line with the CDK constructs: stillfalseby default with the extension, but a user-set value is respected.Testing Guidelines
getConfig/setEnvConfigurationspecs that asserted the old default.injectLogContext: truewith the extension, a function-level value, function-level beatinginjectLogContext,injectLogContextbeating a provider-level value in both directions (with and without the extension), a provider-level value replacing the extension default,nullcounting as unset, anullprovider environment, and the default without the extension.index.spec.ts) for anullprovider.environment(an emptyenvironment:key in YAML), a provider-level value, andinjectLogContext: truewith the extension.yarn test(vitest, 268 passing),yarn build,yarn lint(oxlint) andyarn check-formatting(oxfmt) are clean../scripts/run_snapshot_tests.shwith Serverless 3.39 (same as CI) passes for all three snapshots without regenerating them. The default output is unchanged.Additional Notes
Upgrade note: with the extension, the plugin used to force
DD_LOGS_INJECTION=falseno matter what was configured. After upgrading, these services start gettingDD_LOGS_INJECTION=true:injectLogContext: truein their config (it was the plugin's default value until now),DD_LOGS_INJECTION: truein theirenvironment,DD_LOGS_INJECTION: trueinprovider.environment.Their log output may change, because the tracer will start adding
dd.trace_id/dd.span_id. To keep the old behavior, remove those settings or set them tofalse. This should go in the release notes.Also adds an
injectLogContextrow to the README configuration table.setEnvConfigurationtreats anullprovider.environment(an emptyenvironment:key in YAML) as empty. This PR never assigns toprovider.environment: without the extension nothing else creates it, and an empty one would add anEnvironmentblock to excluded functions. With the extension,addDDEnvVarsalready creates it, as before.Behavior change without the extension: a provider-level
DD_LOGS_INJECTIONused to be overridden at function level by the defaultinjectLogContext: true. It's now applied, unlessinjectLogContextis set explicitly. An explicitinjectLogContextstill beats it, the same as before.Types of changes
Check all that apply
🤖 Generated with Claude Code