Skip to content

WO-1582 Add span.recordException - #7081

Open
jmorrell-cloudflare wants to merge 4 commits into
mainfrom
jmorrell/span-recordexception
Open

WO-1582 Add span.recordException#7081
jmorrell-cloudflare wants to merge 4 commits into
mainfrom
jmorrell/span-recordexception

Conversation

@jmorrell-cloudflare

@jmorrell-cloudflare jmorrell-cloudflare commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

We currently send uncaught exceptions to the tail worker, but this would allow us to capture them on the span where they were emitted

This adds span.recordException

 recordException(
    exception:
      | string
      | {
          code: string | number;
          name?: string;
          message?: string;
          stack?: string;
        }
      | {
          code?: string | number;
          name: string;
          message?: string;
          stack?: string;
        }
      | {
          code?: string | number;
          name?: string;
          message: string;
          stack?: string;
        },
  ): void;

The types here should match OpenTelemetry JS's span.recordException, though we don't yet support passing in your own timestamp:

https://github.com/open-telemetry/opentelemetry-js/blob/main/api/src/trace/span.ts#L144-L150
https://github.com/open-telemetry/opentelemetry-js/blob/main/api/src/common/Exception.ts#L6-L38

The STW interface already supports an exception event. This adds code?: string | number to the payload.

Comment thread src/workerd/api/tracing.h
@ask-bonk

ask-bonk Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

Adds Span.recordException() and serializes exception codes to tail streams.

  1. [P1] Posted 1 inline finding.

github run

@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@jmorrell-cloudflare
jmorrell-cloudflare force-pushed the jmorrell/span-recordexception branch from 34d9a16 to 219c797 Compare August 20, 2026 23:36
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 26.34146% with 151 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.65%. Comparing base (1162ae2) to head (219c797).

Files with missing lines Patch % Lines
src/workerd/api/tracing.c++ 0.00% 74 Missing ⚠️
src/workerd/io/tracer.c++ 39.62% 31 Missing and 1 partial ⚠️
src/workerd/io/trace.c++ 50.00% 14 Missing and 8 partials ⚠️
src/workerd/io/trace-stream.c++ 0.00% 9 Missing and 1 partial ⚠️
src/workerd/server/server.c++ 0.00% 9 Missing ⚠️
src/workerd/io/trace-test.c++ 73.33% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7081      +/-   ##
==========================================
- Coverage   67.72%   67.65%   -0.08%     
==========================================
  Files         458      458              
  Lines      129441   129631     +190     
  Branches    21167    21223      +56     
==========================================
+ Hits        87661    87697      +36     
- Misses      28927    29069     +142     
- Partials    12853    12865      +12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jmorrell-cloudflare
jmorrell-cloudflare marked this pull request as ready for review August 21, 2026 01:24
@jmorrell-cloudflare
jmorrell-cloudflare requested review from a team as code owners August 21, 2026 01:24
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.

2 participants