|
| 1 | +import { loggingTransport } from '@sentry-internal/node-integration-tests'; |
| 2 | +import * as Sentry from '@sentry/node'; |
| 3 | + |
| 4 | +Sentry.init({ |
| 5 | + // No dsn, means client is disabled |
| 6 | + // dsn: 'https://[email protected]/1337', |
| 7 | + release: '1.0', |
| 8 | + transport: loggingTransport, |
| 9 | +}); |
| 10 | + |
| 11 | +// We add http integration to ensure request isolation etc. works |
| 12 | +const initialClient = Sentry.getClient(); |
| 13 | +initialClient?.addIntegration(Sentry.httpIntegration()); |
| 14 | + |
| 15 | +// Store this so we can update the client later |
| 16 | +const initialCurrentScope = Sentry.getCurrentScope(); |
| 17 | + |
| 18 | +import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests'; |
| 19 | +import express from 'express'; |
| 20 | + |
| 21 | +const app = express(); |
| 22 | + |
| 23 | +Sentry.setTag('global', 'tag'); |
| 24 | + |
| 25 | +app.get('/test/no-init', (_req, res) => { |
| 26 | + Sentry.addBreadcrumb({ message: 'no init breadcrumb' }); |
| 27 | + Sentry.setTag('no-init', 'tag'); |
| 28 | + |
| 29 | + res.send({}); |
| 30 | +}); |
| 31 | + |
| 32 | +app.get('/test/init', (_req, res) => { |
| 33 | + // Call init again, but with DSN |
| 34 | + Sentry.init({ |
| 35 | + dsn: 'https://[email protected]/1337', |
| 36 | + release: '1.0', |
| 37 | + transport: loggingTransport, |
| 38 | + }); |
| 39 | + // Set this on initial scope, to ensure it can be inherited |
| 40 | + initialCurrentScope.setClient(Sentry.getClient()!); |
| 41 | + |
| 42 | + Sentry.addBreadcrumb({ message: 'init breadcrumb' }); |
| 43 | + Sentry.setTag('init', 'tag'); |
| 44 | + |
| 45 | + res.send({}); |
| 46 | +}); |
| 47 | + |
| 48 | +app.get('/test/error/:id', (req, res) => { |
| 49 | + const id = req.params.id; |
| 50 | + Sentry.addBreadcrumb({ message: `error breadcrumb ${id}` }); |
| 51 | + Sentry.setTag('error', id); |
| 52 | + |
| 53 | + Sentry.captureException(new Error(`This is an exception ${id}`)); |
| 54 | + |
| 55 | + res.send({}); |
| 56 | +}); |
| 57 | + |
| 58 | +Sentry.setupExpressErrorHandler(app); |
| 59 | + |
| 60 | +startExpressServerAndSendPortToRunner(app); |
0 commit comments