feat(node): Auto-register Hapi error handler on server start - #23461
Draft
mydea wants to merge 4 commits into
Draft
feat(node): Auto-register Hapi error handler on server start#23461mydea wants to merge 4 commits into
mydea wants to merge 4 commits into
Conversation
The Hapi error handler now registers itself automatically when the server starts, so `setupHapiErrorHandler` no longer needs to be called. The handler logic moves to `@sentry/server-utils` and is wired via orchestrion channels on `@hapi/hapi`'s `start`/`initialize` methods; `setupHapiErrorHandler` is kept as a deprecated, idempotent delegate for backwards compatibility. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c88eb54. Configure here.
Contributor
size-limit report 📦
|
This reverts commit c88eb54.
mydea
marked this pull request as ready for review
August 20, 2026 10:51
mydea
marked this pull request as draft
August 20, 2026 11:33
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.

The Hapi error handler is now registered automatically when the server boots, so
setupHapiErrorHandlerno longer needs to be called. This closes the last piece of the Hapi integration that still required a manual setup step.How it works
The tracing side of the Hapi integration already runs through orchestrion diagnostics channels in
@sentry/server-utils(injected into@hapi/hapi'slib/server.js). This reuses the same mechanism for the error handler: two new channels are injected on the serverstartandinitializemethods. Orchestrion publishes the live server instance asctx.selfon those channels, which is enough to attach therequest/errorlistener that sets the transaction name and captures the exception.This also adds a
shouldHandleErrorcallback like other integrations have to decide what to capture to Sentry or not.Decisions
startandinitialize.start()calls the private_core._start()(which internally runs_initialize), so the publicinitializemethod never fires on the commonawait server.start()path. Hooking both covers the standard path plus test/serverless flows that only callinitialize()+inject().core.events) across the root server and every plugin clone, so a single listener covers all requests. Attachment is made idempotent via a non-enumerable marker on that emitter, sostart+initialize, plugin clones, and any lingering manualsetupHapiErrorHandlercall never stack up multiple listeners.setupHapiErrorHandlerstays as a deprecated delegate rather than being removed or hard no-op'd. Auto-registration only fires when orchestrion is active (the default in v11), so keeping the function functional preserves the escape hatch; it is idempotent, so calling it alongside auto-registration is harmless.@sentry/nodeinto@sentry/server-utils(integrations/hapi/) so both the auto-registration and the delegate share one implementation.Auto-registration is exercised end-to-end by dropping the manual call from the node integration-test scenario and the e2e app; a new unit suite covers the attach behaviour (single listener, idempotency, plugin-clone dedup, transaction naming, and the skip cases).