Skip to content

Commit 168deb8

Browse files
committed
ref(nestjs): Add mechanism to captured errors
1 parent 815fc27 commit 168deb8

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

packages/nestjs/src/integrations/sentry-nest-event-instrumentation.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ export class SentryNestEventInstrumentation extends InstrumentationBase {
109109
return result;
110110
} catch (error) {
111111
// exceptions from event handlers are not caught by global error filter
112-
captureException(error);
112+
captureException(error, {
113+
mechanism: {
114+
handled: false,
115+
type: 'nestjs.on-event',
116+
},
117+
});
113118
throw error;
114119
}
115120
});

packages/nestjs/src/setup.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ class SentryGlobalFilter extends BaseExceptionFilter {
101101
this._logger.error(exception.message, exception.stack);
102102
}
103103

104-
captureException(exception);
104+
captureException(exception, {
105+
mechanism: {
106+
handled: false,
107+
type: 'nestjs.graphql',
108+
},
109+
});
105110
throw exception;
106111
}
107112

@@ -117,15 +122,25 @@ class SentryGlobalFilter extends BaseExceptionFilter {
117122
// Handle any other kind of error
118123
if (!(exception instanceof Error)) {
119124
if (!isExpectedError(exception)) {
120-
captureException(exception);
125+
captureException(exception, {
126+
mechanism: {
127+
handled: false,
128+
type: 'nestjs.rpc',
129+
},
130+
});
121131
}
122132
throw exception;
123133
}
124134

125135
// In this case we're likely running into an RpcException, which the user should handle with a dedicated filter
126136
// https://github.com/nestjs/nest/blob/master/sample/03-microservices/src/common/filters/rpc-exception.filter.ts
127137
if (!isExpectedError(exception)) {
128-
captureException(exception);
138+
captureException(exception, {
139+
mechanism: {
140+
handled: false,
141+
type: 'nestjs.rpc-exception',
142+
},
143+
});
129144
}
130145

131146
this._logger.warn(
@@ -139,7 +154,12 @@ class SentryGlobalFilter extends BaseExceptionFilter {
139154

140155
// HTTP exceptions
141156
if (!isExpectedError(exception)) {
142-
captureException(exception);
157+
captureException(exception, {
158+
mechanism: {
159+
handled: false,
160+
type: 'nestjs.http',
161+
},
162+
});
143163
}
144164

145165
return super.catch(exception, host);

0 commit comments

Comments
 (0)