Skip to content

TT-012: Node SDK drops uncaught exceptions (re-throws before the error is sent) #711

Closed

Description

@unjica

Severity: P1 · Area: SDK: Node · Found by: QA

Summary

@telemetry-tracker/node 1.3.0 never reports uncaught exceptions: it re-throws inside its own uncaughtException handler, so the process exits (code 7) before the error is sent. This is the primary crash-capture path of the Node SDK (also used by the NestJS guide), and it fails silently while the docs promise these errors are captured.

Environment and versions

Production API 1.17.23, 2026-09-26 10:00–10:02 CEST. @telemetry-tracker/[email protected] (npm latest, published 2026-07-02) with @telemetry-tracker/[email protected]. Node 20.19.2 and 22.23.3, Linux.

Steps to reproduce

  1. npm init -y && npm i @telemetry-tracker/node
  2. Create uncaught.mjs:
    import { init } from "@telemetry-tracker/node";
    init({ ingestUrl: "https://api.telemetry-tracker.com", app: "my-api", apiKey: process.env.TELEMETRY_API_KEY, platform: "node" });
    setTimeout(() => { throw new Error("Node sweep uncaughtException"); }, 200);
  3. node uncaught.mjs, then check Issues and /api/errors?app=my-api.

Expected

As documented ("After init(), uncaughtException and unhandledRejection are patched to send errors to the ingest API (and then rethrow…)"), the crash appears in Issues, then the process exits.

Actual

The process exits immediately with code 7; the stack points at the SDK's dist/index.js throw err;. 0/3 production crashes arrived (checked 20 s later). Against a local mock ingest, the SDK sent the session and a handled control error but no /ingest/error for the crash (Node 20 and 22). Handled trackError, trackEvent, release/environment tagging and unhandledRejection from the same scripts all arrived. Reproduced 4/4.

Acceptance criteria

With the newly published @telemetry-tracker/node@latest, on Node 20 and Node 22 with a valid key:

  • the process still exits non-zero;
  • within 10 s, GET /api/errors?app=my-api&q=uncaughtException returns the group with context.source = "uncaughtException";
  • against a local HTTP mock, exactly one POST /ingest/error is sent before exit;
  • unhandledRejection and handled-error behaviour unchanged;
  • total time ≤ the documented flush timeout.

Fix references

History

  • 2026-09-26 10:00–10:02 CEST: found and reproduced 4/4 on API 1.17.23. Not retested on 1.17.24 because the npm fix isn't published.

Migrated from the QA regression list on 2026-09-26. Source: QA report 2026-09-26-sweep.md (#tt-012).

Activity

  1. added
    bug
    sdk
    qa
    on Sep 26, 2026
  2. unjica commented on Sep 26, 2026

    @unjica
    CollaboratorAuthor

    QA SDK re-test, 2026-09-26 10:40–10:50 CEST: reproduced with the published packages against a local mock ingest. Node 18/20/22/24/26, Linux. Status unchanged: open. No fix is published yet.

    Published packages under test

    Package Version npm publish time gitHead in npm metadata
    @telemetry-tracker/node 1.3.0 (only version, latest) 2026-07-02 16:14 CEST none
    @telemetry-tracker/core 1.4.0 (latest, resolved by node's ^1.3.0) 2026-07-17 00:20 CEST none

    Reproduction (anyone can run it)

    // mock.mjs: logs every request with a timestamp. Run it with `node mock.mjs` (DELAY=3000 for a slow server)
    import http from "node:http";
    http.createServer((req, res) => { let b = ""; req.on("data", c => b += c); req.on("end", () => {
      console.log(new Date().toISOString(), req.method, req.url, b.slice(0, 200));
      setTimeout(() => res.writeHead(204).end(), Number(process.env.DELAY || 0)); }); }).listen(4318);
    // uncaught.mjs   (npm i @telemetry-tracker/[email protected]; "type": "module")
    import { init } from "@telemetry-tracker/node";
    init({ ingestUrl: "http://127.0.0.1:4318", app: "qa-node", apiKey: "test", environment: "qa" });
    setTimeout(() => { console.error("throwing at", new Date().toISOString()); throw new Error("QA uncaught"); }, 300);

    node uncaught.mjs; echo "exit=$?" gives exit=7. The mock logs POST /ingest/session and nothing else.

    Results: 3 throw sites × 5 Node versions, plus slow and unreachable endpoints

    Build Case Exit code /ingest/error received Timing, from the throw
    npm 1.3.0 top-level ESM throw, setTimeout throw, fs.readFile callback throw 7 (15/15) 0/15. No request and no partial body: the mock logged no aborted request exit seen by the parent 7.6–10.3 ms after the throw
    npm 1.3.0 setTimeout throw, server delaying its response 500 ms / 3 s, or unreachable 7 (15/15) 0/15 exit 7.8–12.7 ms. The server's speed doesn't matter, because the request is never sent
    No SDK (control) same 3 throw sites 1 – –
    repo develop build (node dist + core dist @ c652e61) same 3 throw sites, fast server 1 15/15, full body received +2.2–3.0 ms, exit +3.2–5.4 ms
    repo build server responds after 500 ms 1 5/5 received +2.5–3.7 ms, exit +504–505 ms (after the response)
    repo build server responds after 3 s 1 5/5 full body received; response never delivered received +2.8–3.8 ms, exit +2002–2003 ms (2 s cap)
    repo build unreachable endpoint 1 0/5 (fetch failed, error lost) exit +2.5–3.2 ms

    Other observations:

    • With npm 1.3.0, the app's own process.on("exit") listeners don't run on the crash (0/15). With no SDK, and with the repo build, they do.
    • The stderr of every crash points at the SDK (node_modules/@telemetry-tracker/node/dist/index.js:9 throw err;) and prints [Symbol(telemetry.reported)]: true.
    • node --unhandled-rejections=strict routes rejections into the same handler, so it also exits 7 without reporting (npm, Node 20/22/24).

    Root cause

    • npm @telemetry-tracker/[email protected] dist/index.js:7-10: process.on("uncaughtException", err => { coreTrackError(err, …); throw err; }). Core trackError ([email protected] dist/index.js:392-420) fires send() → fetch without awaiting (dist/index.js:277-300). The synchronous re-throw inside the listener is a fatal error: Node exits with code 7 before the fetch even connects.
    • The npm dist is byte-identical to the repo at 9798ea3 ("Rename SDK packages…", committed 2026-07-02 16:15:56 CEST, 89 s after the publish). The repo source there (packages/telemetry-node/src/index.ts:21-24) has the same throw err.
    • repo develop/main (identical for this package), packages/telemetry-node/src/index.ts:25-30 + src/fatal.ts:1-21 (dist dist/index.js:9-14, dist/fatal.js): flushFatalError races ingestError() against 2000 ms, then process.exit(1). That's commits 0e9158e (src) and e2dae47 (dist), but package.json is still 1.3.0.

    The repo fix can't ship alone: it needs a new core

    • The repo node imports ingestError from core (src/index.ts:6). Published [email protected] doesn't export it. Its runtime exports are SDK_VERSION WEB_VITAL_EVENT_NAME buildIngestHeaders buildWebVitalProperties endSession getAnonymousId getConfigOrNull getSessionId getUserId identify init installWebVitals isWebVitalsCaptureEnabled rateWebVital resolveClientPiiScrub screen scrubPiiRecord scrubPiiText setWebVitalsCaptureEnabled shutdown trackError trackEvent.
    • I built the repo node against published core 1.4.0:
      • tsc fails: src/index.ts(6,3): error TS2305: Module '"@telemetry-tracker/core"' has no exported member 'ingestError';
      • running the repo's committed dist with core 1.4.0 fails at import, SyntaxError: The requested module '@telemetry-tracker/core' does not provide an export named 'ingestError', exit 1, nothing sent (Node 18–26, 5/5).
    • ingestError exists only in the repo core (packages/telemetry-core/src/index.ts:508, dist :413). The repo core is still labelled 1.4.0 and differs from npm 1.4.0: it adds ingestError and the Web-Crypto UUID fallback from a92510e/5501575. npm core 1.4.0 = repo 3a61577 dist, byte-identical.
    • Because node declares "@telemetry-tracker/core": "workspace:*" (published as ^1.3.0), a node release with the fix would install the broken combination for anyone whose lockfile keeps core 1.4.0.

    Release coordination (proposal, not executed)

    1. Publish @telemetry-tracker/[email protected] (new export ingestError, so minor), from a clean checkout with gitHead recorded.
    2. Then publish @telemetry-tracker/[email protected] (or 1.4.0) with "@telemetry-tracker/core": "^1.5.0", so it can never resolve to 1.4.0.
    3. Retest against the published packages using the acceptance criteria above, plus: process.on("exit") listeners run, a 3 s server gives exit 1 at ~2 s, and the unreachable endpoint gives exit 1 without hanging.
    4. After verification, consider npm deprecate @telemetry-tracker/[email protected] "uncaught exceptions are not reported; upgrade to >=1.3.1".

    Follow-up notes, not blocking this issue:

    • Even the repo fix flushes only the error. Queued $request events in the 5 s batch are dropped on the crash (0/3 received in the middleware test where a sync handler throw killed the server).
    • The session is never ended.
    • Docs /docs/node and /error-tracking/nodejs say "rethrow"; they should describe "report, wait up to 2 s, exit 1".
  3. unjica commented on Oct 2, 2026

    @unjica
    CollaboratorAuthor

    QA verification — PASS (closed)

    When: 2026-10-02 ~08:56 CEST (weekday smoke)
    Fix: PR #722 (@telemetry-tracker/[email protected] + @telemetry-tracker/core@^1.5.0; clean-room resolve got core 1.5.1)
    Method: Fresh registry install (not repo workspace). Ran the acceptance uncaughtException script twice against production ingest.

    Run Exit Error in dashboard
    r1 1 yes (1 occurrence)
    r2 1 yes (1 occurrence)

    Previously (npm 1.3.0): exit 7, 0 /ingest/error. Published dist includes flushFatalError and no longer re-throws inside the handler.

    Closing as verified-fixed on the published packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugqasdk

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions