|
1 |
| -import { captureException, deepReadDirSync, getCurrentHub, Handlers, startTransaction } from '@sentry/node'; |
| 1 | +import { |
| 2 | + captureException, |
| 3 | + configureScope, |
| 4 | + deepReadDirSync, |
| 5 | + getCurrentHub, |
| 6 | + Handlers, |
| 7 | + startTransaction, |
| 8 | +} from '@sentry/node'; |
2 | 9 | import { extractTraceparentData, getActiveTransaction, hasTracingEnabled } from '@sentry/tracing';
|
3 |
| -import { fill, isString, logger, stripUrlQueryAndFragment } from '@sentry/utils'; |
| 10 | +import { addExceptionMechanism, fill, isString, logger, stripUrlQueryAndFragment } from '@sentry/utils'; |
4 | 11 | import * as domain from 'domain';
|
5 | 12 | import * as http from 'http';
|
6 | 13 | import { default as createNextServer } from 'next';
|
@@ -145,8 +152,26 @@ function makeWrappedHandlerGetter(origHandlerGetter: HandlerGetter): WrappedHand
|
145 | 152 | */
|
146 | 153 | function makeWrappedErrorLogger(origErrorLogger: ErrorLogger): WrappedErrorLogger {
|
147 | 154 | return function(this: Server, err: Error): void {
|
148 |
| - // TODO add context data here |
| 155 | + // TODO add more context data here |
| 156 | + |
| 157 | + // We can use `configureScope` rather than `withScope` here because we're using domains to ensure that each request |
| 158 | + // gets its own scope. (`configureScope` has the advantage of not creating a clone of the current scope before |
| 159 | + // modifying it, which in this case is unnecessary.) |
| 160 | + configureScope(scope => { |
| 161 | + scope.addEventProcessor(event => { |
| 162 | + addExceptionMechanism(event, { |
| 163 | + type: 'instrument', |
| 164 | + handled: true, |
| 165 | + data: { |
| 166 | + function: 'logError', |
| 167 | + }, |
| 168 | + }); |
| 169 | + return event; |
| 170 | + }); |
| 171 | + }); |
| 172 | + |
149 | 173 | captureException(err);
|
| 174 | + |
150 | 175 | return origErrorLogger.call(this, err);
|
151 | 176 | };
|
152 | 177 | }
|
|
0 commit comments