Skip to content

[SVLS-9883] feat: add datadog-serverless-logging crate for DD_LOG_LEVEL_BY_TARGET - #180

Merged
lym953 merged 6 commits into
mainfrom
yiming.luo/serverless-logging-crate
Oct 13, 2026
Merged

lym953 merged 6 commits into
mainfrom
yiming.luo/serverless-logging-crate

Conversation

@lym953

@lym953 lym953 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds the crate datadog-serverless-logging. It lets a user set the log level of one target of a serverless agent with the environment variable DD_LOG_LEVEL_BY_TARGET. For example:

Environment variable Value
DD_LOG_LEVEL_BY_TARGET cold_start_duration=debug,dogstatsd=debug

With this value, the agent logs debug messages with the custom target cold_start_duration, and debug messages from the dogstatsd crate. The other targets keep the agent's default level. The README lists the kinds of targets.

The agent calls build_env_filter(base, levels_by_target) when it sets up logging. It adds each valid <target>=<level> entry to the agent's base filter, such as h2=off,info, and returns the entries that are not valid. The agent then logs a warning for those entries. A bare level such as debug, an unknown level, and a span filter such as [span]=debug are not valid.

Motivation

DataDog/datadog-lambda-extension#1413 uses this crate, so that a user can see the cold start step durations without all the debug logs. The code is in this repository so that other serverless agents, such as datadog-serverless-compat, can use the same variable.

Additional Notes

This PR does not change datadog-serverless-compat.

Describe how to test/QA your changes

I tested the crate through #1413 on a real Lambda function, with an arm64 build of #1413 at 4a71d023, which uses this crate at e5524046. I forced 2 cold starts for each row and counted the extension's log lines in CloudWatch. Each cold start logs 11 cold start duration lines.

DD_LOG_LEVEL DD_LOG_LEVEL_BY_TARGET Debug lines Cold start duration lines Warnings ERROR lines
info cold_start_duration=debug 22 22 0 0
debug cold_start_duration=off 56 0 0 0
info debug,cold_start_duration=verbose,cold_start_duration=debug 22 22 2 0
info dogstatsd=debug 10 0 0 0
not set cold_start_duration=debug 22 22 0 0

In the third row, the extension ignored debug and cold_start_duration=verbose with a warning. In the fourth row, all the debug messages come from the dogstatsd crate.

🤖 Generated with Claude Code

lym953 and others added 6 commits October 9, 2026 13:55
…EL_BY_TARGET

Adds a crate with the DD_LOG_LEVEL_BY_TARGET name and build_env_filter,
which adds each valid `target=level` entry to an agent's base filter and
returns the invalid entries. The Lambda extension will use it, and
datadog-serverless-compat can use it later. Each agent keeps its own
subscriber and log format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nt variable

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…agent

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lym953 added a commit to DataDog/datadog-lambda-extension that referenced this pull request Oct 9, 2026
The parsing and the variable name move to the new crate in
serverless-components (DataDog/serverless-components#180), so that other
serverless agents can share them. Points all five serverless-components
dependencies at the head of #180. Its other changes since the current
revision are docs and a lock file bump that the extension does not use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lym953 added a commit to DataDog/datadog-lambda-extension that referenced this pull request Oct 9, 2026
The parsing and the variable name move to the new crate in
serverless-components (DataDog/serverless-components#180), so that other
serverless agents can share them. Points all five serverless-components
dependencies at the head of #180. Its other changes since the current
revision are docs and a lock file bump that the extension does not use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lym953
lym953 marked this pull request as ready for review October 9, 2026 19:04
@lym953
lym953 requested review from a team as code owners October 9, 2026 19:04
@lym953
lym953 requested review from Lewis-E and clifordshelton and a balanced review from Copilot and removed request for a team October 9, 2026 19:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation is focused, validated, documented, and adequately tested.

0 open findings

What changed in this PR

Adds reusable target-specific tracing filter support for serverless agents.

Changes:

  • Builds filters from validated <target>=<level> directives.
  • Returns invalid directives for caller warnings.
  • Documents usage and adds unit coverage.
File Description
crates/​datadog-serverless-logging/​src/​lib.rs Implements filtering and tests.
crates/​datadog-serverless-logging/​README.md Documents configuration and targets.
crates/​datadog-serverless-logging/​Cargo.toml Defines the new crate.
Cargo.lock Records the workspace package.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@lym953
lym953 merged commit 9538fc7 into main Oct 13, 2026
28 of 29 checks passed
@lym953
lym953 deleted the yiming.luo/serverless-logging-crate branch October 13, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants