Skip to content

Sentry.init() prevents http.Server 'upgrade' events (WebSocket) from firing #20132

@ReneGreen27

Description

@ReneGreen27

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node - express

SDK Version

@sentry/node: 10.47.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

Create an Express app and attach it to a shared HTTP server:

const app = express();
const server = http.createServer(app);

Attach a WebSocket upgrade handler using ws with noServer: true:

const wss = new WebSocketServer({ noServer: true });

server.prependListener('upgrade', (req, socket, head) => {
  wss.handleUpgrade(req, socket, head, (ws) => {
    // connection established
  });
});

Initialize Sentry early (either via import side-effect or preload):

import * as Sentry from "@sentry/node";

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  tracesSampleRate: 1.0,
});

Start the server and attempt a WebSocket connection.

Results in

  • The 'upgrade' handler is never called
  • WebSocket connection fails silently
  • No errors are thrown

Control (Working Case)

  • Remove Sentry.init() (keep import only)
  • Restart server
  • WebSocket upgrade handler fires as expected

Steps to Reproduce

See above

Expected Result

Calling Sentry.init() should not interfere with Node.js HTTP server event propagation.

Specifically, handlers registered via:

server.on('upgrade', handler)
server.prependListener('upgrade', handler)

should continue to fire normally for WebSocket upgrade requests.

Actual Result

When Sentry.init() is called:

'upgrade' event listeners are never invoked
WebSocket connections fail silently
No errors are thrown
Behavior is consistent across all tested configurations

Additional Context

What Was Tried:

  • Early Sentry.init() with default integrations
  • Early Sentry.init() with integrations: [] and tracing disabled
  • Filtering HTTP traffic using ignoreIncomingRequests for WebSocket paths
  • Removing HttpServer integration explicitly
  • Using server.on('upgrade') vs server.prependListener('upgrade')
  • Using node --require @sentry/node/preload to force earliest initialization
  • Verifying behavior with only a bare @sentry/node import (no init)
  • Deferring Sentry.init() until after server + upgrade handler setup

Outcome Summary

All early initialization approaches -> 'upgrade' events do not fire
Bare import without Sentry.init() -> works
Deferred Sentry.init() -> works

Related to internal ticket #179168

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions