Skip to content

Commit 84b3ec6

Browse files
committed
chore: extra notes for sentry
1 parent 5fa321b commit 84b3ec6

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

content/guide/crash-reporting-sentry.md

+69
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,72 @@ Your crashes should appear in your Sentry dashboard shortly after triggering.
282282
---
283283

284284
You're now successfully integrated with Sentry, gaining powerful insights into your app's performance and stability.
285+
286+
## Config Considerations
287+
288+
Within `nativescript.config.ts`, be mindful of the following.
289+
290+
```ts
291+
export default {
292+
discardUncaughtJsExceptions: true,
293+
android: {
294+
v8Flags: '--expose_gc',
295+
markingMode: 'none',
296+
codeCache: true,
297+
suppressCallJSMethodExceptions: true,
298+
},
299+
}
300+
```
301+
302+
The options to `discardUncaughtJsExceptions` and `suppressCallJSMethodExceptions` will suppress JavaScript exceptions like those using `throw` which can prevent them from showing up in Sentry so just keep that in mind.
303+
304+
## Flavor Notes
305+
306+
Various flavors may need some extra considerations.
307+
308+
### Angular
309+
310+
You can setup a custom error handler.
311+
312+
Define a `SentryErrorHandler` within `sentry.ts`.
313+
314+
```ts
315+
import { ErrorHandler } from '@angular/core'
316+
317+
export class SentryErrorHandler implements ErrorHandler {
318+
handleError(error: unknown) {
319+
if (__ENABLE_SENTRY__ && initialized) {
320+
Sentry.captureException(error)
321+
}
322+
}
323+
}
324+
```
325+
326+
You can use it within your custom Angular error handler.
327+
328+
```ts
329+
import { ErrorHandler, Injectable } from '@angular/core'
330+
import { SentryErrorHandler } from './sentry'
331+
332+
@Injectable()
333+
export class GlobalErrorHandler extends ErrorHandler {
334+
sentryErrorHandler = new SentryErrorHandler()
335+
336+
handleError(error: Error) {
337+
console.error('GlobalErrorHandler', error)
338+
console.error(error.stack)
339+
this.sentryErrorHandler.handleError(error)
340+
}
341+
}
342+
```
343+
344+
Then in your `app.component.ts` or `app.module.ts`, depending on if using standalone, use the provider.
345+
346+
```ts
347+
providers: [
348+
{
349+
provide: ErrorHandler,
350+
useClass: GlobalErrorHandler,
351+
},
352+
]
353+
```

0 commit comments

Comments
 (0)