Skip to content

fix: flush tracer DogStatsD metrics after each invocation - #873

Merged
joeyzhao2018 merged 3 commits into
mainfrom
codex/flush-tracer-metrics
Nov 30, 2026
Merged

joeyzhao2018 merged 3 commits into
mainfrom
codex/flush-tracer-metrics

Conversation

@joeyzhao2018

@joeyzhao2018 joeyzhao2018 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Flush tracer.dogstatsd at the start of MetricsListener.onCompleteInvocation, before flushing the Lambda metrics client and requesting an extension flush. This runs after every invocation, including when the handler throws, and does not depend on extension detection.

The metrics and trace listeners share one TracerWrapper so they use the same resolved tracer instance. The wrapper tolerates missing tracer APIs and catches flush errors so they cannot change the handler result.

Motivation

Fixes #868. Custom metrics emitted through tracer.dogstatsd.* otherwise wait for the tracer's 10-second timer and can remain buffered when Lambda freezes an infrequently invoked function.

Testing Guidelines

  • Build, TypeScript, lint, and formatting checks pass.
  • Full unit suite: 54 suites, 746 tests, and 3 snapshots pass.
  • Regression coverage includes tracer-before-extension flush ordering (including when the Lambda metrics client fails), flushing without the extension, repeated invocations, successful and failing handlers, flush failures, and absent or older tracer APIs.

Additional Notes

Local validation reused installed dependencies with Node.js 26.12.0 and dd-trace 5.118.0. Deployed AWS integration tests were not run.

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)

@joeyzhao2018
joeyzhao2018 requested a review from a team as a code owner November 25, 2026 21:12
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T21:14:02.379207Z 2ef044a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 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 completion hook flushes tracer metrics after successful and failed handlers, with guards for missing APIs and synchronous flush errors. Source review identified no actionable defect.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 2ef044a

Comment thread src/trace/listener.ts Resolved
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 2 Pipeline jobs failed

DataDog/datadog-lambda-js | publish layer sandbox (node22): [us-west-2]

View more details · View in GitLab

DataDog/datadog-lambda-js | publish layer sandbox (node24): [us-west-2]

View more details · View in GitLab

ℹ️ Info

🔁 Datadog re-ran publish layer sandbox (node24): [us-west-2] after it failed. The re-run did not pass. View in Datadog

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 9b322a3 | Docs | View more details | Give us feedback!

@joeyzhao2018
joeyzhao2018 merged commit e555186 into main Nov 30, 2026
63 of 66 checks passed
@joeyzhao2018
joeyzhao2018 deleted the codex/flush-tracer-metrics branch November 30, 2026 22:15
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.

Metrics emitted via dd-trace are not flushed at end of invocations

2 participants