Skip to content

fix: finish spans when decorated methods throw - #49

Open
seandearnaley wants to merge 1 commit into
codebrick-corp:mainfrom
seandearnaley:fix/dd-trace-v6-peer
Open

fix: finish spans when decorated methods throw#49
seandearnaley wants to merge 1 commit into
codebrick-corp:mainfrom
seandearnaley:fix/dd-trace-v6-peer

Conversation

@seandearnaley

@seandearnaley seandearnaley commented Aug 31, 2026

Copy link
Copy Markdown

Summary

  • finish the active span before propagating synchronous errors from decorated methods
  • keep asynchronous rejections tagged, finalized, and rethrown
  • assert that both paths preserve the original error and finish the span exactly once

Problem

recordException() previously tagged and immediately rethrew the error. In the synchronous catch path, that made the following span.finish() unreachable and left the span open. Promise paths happened to finish through .finally(), but their error propagation depended on the helper throwing.

This change makes recordException() responsible only for tagging. Each caller now explicitly propagates the original error, after the synchronous path has finalized its span; asynchronous paths continue to finalize through .finally().

This is a lifecycle bug fix for the package's existing dd-trace ^5 support. It intentionally does not change the peer range, development dependency, Node.js CI version, or lockfile.

Verification

  • npm test -- --runInBand — 2 suites, 20 tests passed
  • npm run build
  • ESLINT_USE_FLAT_CONFIG=false npx eslint src/decorator.injector.ts src/decorator.injector.spec.ts --no-fix
  • repository-wide lint was also checked; it remains blocked by 41 pre-existing formatting/unused-import findings in src/datadog-trace.module.ts and src/datadog-trace.module.spec.ts

@pull-request-size pull-request-size Bot added size/M and removed size/S labels Aug 31, 2026
@seandearnaley seandearnaley changed the title fix: support dd-trace v6 and finish error spans fix: finish spans when decorated methods throw Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant