Skip to content

Commit 9b42055

Browse files
authored
Merge branch 'NativeScript:main' into main
2 parents e7af8e2 + 5856278 commit 9b42055

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

content/guide/crash-reporting-sentry.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,78 @@ 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+
## Example Repo
287+
288+
You can compare your setup against this example repo which follows this documentation.
289+
290+
https://github.com/NativeScript/example-sentry
291+
292+
## Config Considerations
293+
294+
Within `nativescript.config.ts`, be mindful of the following.
295+
296+
```ts
297+
export default {
298+
discardUncaughtJsExceptions: true,
299+
android: {
300+
v8Flags: '--expose_gc',
301+
markingMode: 'none',
302+
codeCache: true,
303+
suppressCallJSMethodExceptions: true,
304+
},
305+
}
306+
```
307+
308+
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.
309+
310+
## Flavor Notes
311+
312+
Various flavors may need some extra considerations.
313+
314+
### Angular
315+
316+
You can setup a custom error handler.
317+
318+
Define a `SentryErrorHandler` within `sentry.ts`.
319+
320+
```ts
321+
import { ErrorHandler } from '@angular/core'
322+
323+
export class SentryErrorHandler implements ErrorHandler {
324+
handleError(error: unknown) {
325+
if (__ENABLE_SENTRY__ && initialized) {
326+
Sentry.captureException(error)
327+
}
328+
}
329+
}
330+
```
331+
332+
You can use it within your custom Angular error handler.
333+
334+
```ts
335+
import { ErrorHandler, Injectable } from '@angular/core'
336+
import { SentryErrorHandler } from './sentry'
337+
338+
@Injectable()
339+
export class GlobalErrorHandler extends ErrorHandler {
340+
sentryErrorHandler = new SentryErrorHandler()
341+
342+
handleError(error: Error) {
343+
console.error('GlobalErrorHandler', error)
344+
console.error(error.stack)
345+
this.sentryErrorHandler.handleError(error)
346+
}
347+
}
348+
```
349+
350+
Then in your `app.component.ts` or `app.module.ts`, depending on if using standalone, use the provider.
351+
352+
```ts
353+
providers: [
354+
{
355+
provide: ErrorHandler,
356+
useClass: GlobalErrorHandler,
357+
},
358+
]
359+
```

0 commit comments

Comments
 (0)