|
| 1 | +import Vue from 'nativescript-vue'; |
| 2 | +import * as Sentry from '@nativescript-community/sentry'; |
| 3 | +import * as Tracing from '@nativescript-community/sentry/tracing'; |
| 4 | +import { Application, NavigatedData, Page, Trace, Utils, View } from '@nativescript/core'; |
| 5 | +import { on as applicationOn, launchEvent } from '@nativescript/core/application'; |
| 6 | +import Basic from './Basic'; |
| 7 | + |
| 8 | +Trace.addCategories(Sentry.SentryTraceCategory); |
| 9 | +Trace.enable(); |
| 10 | + |
| 11 | +declare const SENTRY_DSN: string; |
| 12 | +declare const SENTRY_PREFIX: string; |
| 13 | +declare const __APP_ID__: string; |
| 14 | +declare const __APP_VERSION__: string; |
| 15 | +declare const __APP_BUILD_NUMBER__: string; |
| 16 | +async function startSentry() { |
| 17 | + try { |
| 18 | + Sentry.init({ |
| 19 | + dsn: SENTRY_DSN, |
| 20 | + debug: true, |
| 21 | + enablePerformanceV2: true, |
| 22 | + release: `${__APP_ID__}@${__APP_VERSION__}+${__APP_BUILD_NUMBER__}`, |
| 23 | + dist: `${__APP_BUILD_NUMBER__}.${__ANDROID__ ? 'android' : 'ios'}`, |
| 24 | + flushSendEvent: true, |
| 25 | + enableNativeCrashHandling: true, |
| 26 | + attachScreenshot: true, |
| 27 | + tracesSampleRate: 1.0, |
| 28 | + sampleRate: 1.0, |
| 29 | + enableAutoPerformanceTracking: true, |
| 30 | + enableAutoSessionTracking: true, |
| 31 | + integrations: [ |
| 32 | + new Tracing.NativescriptTracing({ |
| 33 | + enableAppStartTracking: true, |
| 34 | + enableNativeFramesTracking: true, |
| 35 | + // routingInstrumentation: HttpService.sentryTracing, |
| 36 | + enableStallTracking: true |
| 37 | + }) |
| 38 | + ], |
| 39 | + enableUIViewControllerTracing: false, |
| 40 | + enableUserInteractionTracing: false, |
| 41 | + enableAutoBreadcrumbTracking: false |
| 42 | + }); |
| 43 | + Page.on('navigatingTo', (event: NavigatedData) => { |
| 44 | + Sentry.addBreadcrumb({ |
| 45 | + category: 'navigation', |
| 46 | + type: 'navigation', |
| 47 | + // We assume that context.name is the name of the route. |
| 48 | + message: `Navigation to ${event.object}`, |
| 49 | + data: { |
| 50 | + isBackNavigation: event.isBackNavigation, |
| 51 | + from: `${(event.object as Page).frame?.currentPage}`, |
| 52 | + to: `${event.object}` |
| 53 | + } |
| 54 | + }); |
| 55 | + }); |
| 56 | + View.on('showingModally', (event: NavigatedData) => { |
| 57 | + Sentry.addBreadcrumb({ |
| 58 | + category: 'navigation', |
| 59 | + type: 'navigation', |
| 60 | + // We assume that context.name is the name of the route. |
| 61 | + message: `Navigation to Modal ${event.object}`, |
| 62 | + data: { |
| 63 | + from: `${(event.object as View)._modalParent}`, |
| 64 | + to: `${event.object}` |
| 65 | + } |
| 66 | + }); |
| 67 | + }); |
| 68 | + View.on('closingModally', (event: NavigatedData) => { |
| 69 | + Sentry.addBreadcrumb({ |
| 70 | + category: 'navigation', |
| 71 | + type: 'navigation', |
| 72 | + // We assume that context.name is the name of the route. |
| 73 | + message: `Closing modal ${event.object}`, |
| 74 | + data: { |
| 75 | + from: `${event.object as View}` |
| 76 | + } |
| 77 | + }); |
| 78 | + }); |
| 79 | + setTimeout(() => { |
| 80 | + Sentry.withScope((scope) => { |
| 81 | + try { |
| 82 | + scope.setTag('myTag', 'tag-value'); |
| 83 | + scope.setExtra('myExtra', 'extra-value'); |
| 84 | + scope.addBreadcrumb({ message: 'test' }); |
| 85 | + Sentry.captureMessage('Hello Sentry!'); |
| 86 | + } catch (error) { |
| 87 | + console.error(error); |
| 88 | + } |
| 89 | + }); |
| 90 | + }, 1000); |
| 91 | + } catch (err) { |
| 92 | + console.error(err, err.stack); |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +export function installPlugin() { |
| 97 | + if (!__ANDROID__ || Utils.android.getApplicationContext()) { |
| 98 | + startSentry(); |
| 99 | + } else { |
| 100 | + applicationOn(launchEvent, startSentry); |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +export const demos = [{ name: 'Basic', path: 'Basic', component: Basic }]; |
0 commit comments