fix(cdp): give external-request timeouts a real stack and upstream context#67268
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(cdp): give external-request timeouts a real stack and upstream context#67268posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
…ntext AbortSignal.timeout rejects with a DOMException built inside Node's timer callback, so its stack is entirely node-internal and identical for every caller — every fetch timeout across the service collapsed into one un-debuggable error fingerprint with no URL or caller context. Wrap the timeout rejection in _fetch and legacyFetch and rethrow a RequestTimeoutError from the awaiting call site: the stack now follows the async caller chain and the target host is embedded in the message, so timeouts group by which upstream is actually degraded. The original DOMException is preserved as `cause`. Generated-By: PostHog Code Task-Id: 6337f532-5050-407d-9f2f-17a38adf7cb6
Contributor
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every outbound request in
nodejs/src/common/utils/request.tsis givensignal: AbortSignal.timeout(...). When an upstream endpoint is slow and that signal fires, it rejects with aTimeoutErrorDOMExceptionthat is constructed inside Node's timer callback — so its stack contains only node-internal frames (process.processTimers→listOnTimeout→Timeout._onTimeout→new DOMException) and no caller context. Because the stack is identical regardless of who made the call, every external-request timeout across the service collapses into a single error-tracking fingerprint, with no URL to say which dependency is actually timing out.This is an internal observability problem: the one giant issue both drowns out real errors and hides which upstream is degraded, and (because each capture uses a fresh anonymous distinct ID) inflates the "users" count into noise.
Changes
RequestTimeoutError, which carries the targethost, fullurl, andtimeoutMs, and preserves the originalDOMExceptionascause.AbortSignal.timeoutrejection in both_fetchandlegacyFetchso a timeout is rethrown from the awaiting call site. The rethrown error's stack follows the async caller chain (real in-app frames) instead of the node-internal timer frames, and the message names the host. Together these make timeouts group by real caller + upstream rather than into one bucket.signal.abortedon the timeout signal — robust regardless of whether undici surfaces the abort as aTimeoutErrororAbortError.Retry behavior is unchanged:
isFetchResponseRetriablestill treats the timeout as a general retriable error, andisConnectionLevelErrorstill returns false for it (nocode), exactly as with the previous rawDOMException.Separately worth a follow-up: the default
EXTERNAL_REQUEST_TIMEOUT_MSis3000ms — this change makes it observable which upstreams are hitting that ceiling, so the team can decide whether it's too tight for the callers now timing out (likely CDP fetch destinations).How did you test this code?
I'm an agent; I did not do manual testing. Automated tests I ran locally in
nodejs/:request.test.ts(request timeout handling): a request against a non-responding local route with a shorttimeoutMsmust surface as aRequestTimeoutErrornaming the host, withhost/timeoutMs/causepopulated. This guards the fix's core contract — a regression that reverted to the raw node-internalDOMException(nameTimeoutError, no host) would fail it. It couldn't extend an existing test because none exercised the timeout path.src/common/utils/request.test.tssuite: 80 passed, 2 pre-existing skips.tsc --noEmitandeslinton the changed files: clean.Automatic notifications
Docs update
🤖 Agent context
Autonomy: Fully autonomous
Authored by Claude Code (Opus 4.8) acting on an inbox report about a spiking, un-debuggable error-tracking issue. Invoked the
/writing-testsskill before adding the test to apply the value gate (targeted regression guard, single parameter-free case on the cheapest rung).Key decisions:
signal.aborted, not error name. In these two functions the timeout signal is the only abort source, soabortedunambiguously means "timed out" and is robust to whether undici rethrows the reason directly or wraps it.urlis retained as a property for when a handler logsextra.EXTERNAL_REQUEST_TIMEOUT_MSat 3000ms — changing a global timeout is a separate risk decision; this PR makes that decision informable.Created with PostHog Code from an inbox report.