Connect a Connect application to Bugsink
When Connect middleware fails, Bugsink shows you the exception, the application frame that raised it, and the HTTP request being handled.
This guide loads the Node SDK before Connect and adds its error handler to an existing middleware stack. You’ll then send one failed inventory request through the application. To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.
Install the Node SDK
Install version 10 of the open-source Sentry SDK for Node.js. Bugsink accepts the Sentry event protocol, so the SDK can send Connect exceptions directly to your Bugsink project:
npm install @sentry/node@10npm install @sentry/node@10
The major-version constraint matters for Connect. SDK 11 no longer exposes the Connect setup helper; see Limitations below.
Initialize the SDK before Connect
Create instrument.mjs and initialize the SDK with the DSN from the
environment:
import * as Sentry from "@sentry/node"; Sentry.init({ dsn: process.env.SENTRY_DSN, });import * as Sentry from "@sentry/node"; Sentry.init({ dsn: process.env.SENTRY_DSN, });
Load that module with Node’s --import option before the server module. This
lets the SDK instrument Connect while its modules load:
"scripts": { "start": "node --import ./instrument.mjs server.mjs" },"scripts": { "start": "node --import ./instrument.mjs server.mjs" },
Set SENTRY_DSN in the environment where the application runs:
export SENTRY_DSN=https://key@bugsink.example/1export SENTRY_DSN=https://key@bugsink.example/1
Add the Connect error handler
Import the SDK in your server module. After registering application middleware, add the SDK’s handler before your existing final error responder:
import * as Sentry from "@sentry/node"; import connect from "connect"; :::javascript Sentry.setupConnectErrorHandler(app); app.use((error, request, response, next) => { response.statusCode = 500; response.setHeader("Content-Type", "application/json"); response.end(JSON.stringify({ error: error.message })); });import * as Sentry from "@sentry/node"; import connect from "connect"; :::javascript Sentry.setupConnectErrorHandler(app); app.use((error, request, response, next) => { response.statusCode = 500; response.setHeader("Content-Type", "application/json"); response.end(JSON.stringify({ error: error.message })); });
The SDK observes the exception and passes it on. Your application still owns the response body and status code.
Send a failed request
Application middleware does not need reporting calls. This inventory path throws an ordinary domain exception when a requested product is missing:
const sku = decodeURIComponent(checkout[1]); const product = inventory.get(sku); if (!product) { throw new ProductNotFound(`Product ${sku} is not in inventory`); }const sku = decodeURIComponent(checkout[1]); const product = inventory.get(sku); if (!product) { throw new ProductNotFound(`Product ${sku} is not in inventory`); }
Start the application, then request a missing product:
npm start :::bash curl http://127.0.0.1:3000/checkout/connect-missingnpm start :::bash curl http://127.0.0.1:3000/checkout/connect-missing
Connect still returns the application’s normal JSON 500 response:
{"error":"Product connect-missing is not in inventory"}{"error":"Product connect-missing is not in inventory"}
See the request in Bugsink
Open your Bugsink project and select the new ProductNotFound issue. Its event
points to the failing middleware line and includes the GET request.
ProductNotFound
That’s it: exceptions reaching Connect’s error path will now be reported to Bugsink, while your existing error responder continues to control the client response.
Limitations
Connect support is available through @sentry/node 10.78.0. SDK 11 can still
send manually captured Node events to Bugsink, but it removed
setupConnectErrorHandler() and connectIntegration(). Keep the major-version
constraint while this application still uses Connect.
For handled exceptions, messages, tags, structured context, breadcrumbs, and other SDK options, continue with the broader Node.js guide.
