Skip to content

fix: Fix log processing rule on orphan log#912

Merged
lym953 merged 4 commits into
mainfrom
yiming.luo/missing-runtime
Nov 5, 2025
Merged

fix: Fix log processing rule on orphan log#912
lym953 merged 4 commits into
mainfrom
yiming.luo/missing-runtime

Conversation

@lym953

@lym953 lym953 commented Oct 30, 2025

Copy link
Copy Markdown
Contributor

Problem

When a user follows our doc to set the env var: DD_LOGS_CONFIG_PROCESSING_RULES : [{"type": "exclude_at_match", "name": "exclude_start_and_end_logs", "pattern": "(START|END|REPORT) RequestId"}], we not only excludes START, END and REPORT logs, but some other logs as well, such as (1) extension log and (2) error log from the Lambda handler. As a result, errors can be left unobserved.

Bug

This is because we first apply the log processing rules to the log we receive from telemetry API, to decide whether to send it to Datadog, then use the same result for "orphan log", which may include extension log and user error log.

This PR

For each orphan log, evaluate log processing rules again, instead of reusing the existing result.

Testing

Setup

  • Lambda runtime: Node 22
  • Handler:
const region = process.env["NO_REGION"];
if (!region) {
  throw new Error("NO_REGION environment variable not set");
}


export const handler = async (event) => {
  const response = {
    statusCode: 200,
    body: JSON.stringify('Hello from Lambda!'),
  };
  return response;
};
  • Env var: DD_LOGS_CONFIG_PROCESSING_RULES : [{"type": "exclude_at_match", "name": "exclude_start_and_end_logs", "pattern": "(START|END|REPORT) RequestId"}]

Result before:

No log showed up in Datadog's Log Explorer or Live Tail

Result after:

Custom error log and extension log showed up.
image

Notes

Thanks @duncanista @astuyve @litianningdatadog for debugging and discussion.

Jira: https://datadoghq.atlassian.net/browse/SLES-2469

@lym953
lym953 requested a review from a team as a code owner October 30, 2025 21:57
Comment thread bottlecap/src/logs/lambda/processor.rs Outdated
for mut orphan_log in self.orphan_logs.drain(..) {
orphan_log.message.lambda.request_id =
Some(self.invocation_context.request_id.clone());
let should_send_log = self.logs_enabled

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.

Oh god, this failed because we shadowed the should_send_log variable?

This reassignment works, but can we refactor this into an instance method which just borrows the message itself?

If that is too complicated to pass the borrow checker, can we instead rename this variable to orphan_should_send_log so we don't reshadow this?

@lym953 lym953 Oct 31, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It failed because we reused the result of should_send_log from the first message for all the log messages.
Will try to refactor this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

@lym953
lym953 merged commit bac841c into main Nov 5, 2025
39 checks passed
@lym953
lym953 deleted the yiming.luo/missing-runtime branch November 5, 2025 16:33
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.

3 participants