diff --git a/docs/platforms/javascript/guides/capacitor/index.mdx b/docs/platforms/javascript/guides/capacitor/index.mdx index 992b2961079a8..b0d427a75ab5b 100644 --- a/docs/platforms/javascript/guides/capacitor/index.mdx +++ b/docs/platforms/javascript/guides/capacitor/index.mdx @@ -1,6 +1,6 @@ --- title: Capacitor -description: Sentry's Capacitor SDK enables automatic reporting of errors, exceptions, and messages. It includes native crash support on iOS and Android. +description: Learn how to set up Sentry in your Capacitor application, capture your first errors and traces, and view them in Sentry. sdk: sentry.javascript.capacitor categories: - javascript @@ -8,559 +8,267 @@ categories: - mobile --- -## Install + -Sentry captures data by using an SDK within your application's runtime. + -Install the Sentry Capacitor SDK alongside the corresponding Sentry SDK for the framework you're using: +This guide will show you setup instructions for Angular, React, Vue, and Nuxt. If you use any other JavaScript framework (or none at all) with Capacitor, follow the vanilla instructions outlined under "Other". -```bash {tabTitle:Angular} -# npm -npm install @sentry/capacitor @sentry/angular --save + -# yarn -yarn add @sentry/capacitor @sentry/angular +## Step 1: Install -# pnpm -pnpm add @sentry/capacitor @sentry/angular -``` +### Install the Sentry SDK -```bash {tabTitle:React} -# npm -npm install @sentry/capacitor @sentry/react --save +Run the command for your preferred package manager to add Sentry's Capacitor SDK and the SDK for the framework you're using to your application: -# yarn -yarn add @sentry/capacitor @sentry/react + -# pnpm -pnpm add @sentry/capacitor @sentry/react -``` + -```bash {tabTitle:Vue} -# npm -npm install @sentry/capacitor @sentry/vue --save +#### Angular -# yarn -yarn add @sentry/capacitor @sentry/vue +Currently, the Sentry Capacitor SDK only supports Angular 14 and newer. If you're using an older version of Angular, you also need to use an older version of the SDK. See this table for compatibility guidance: -# pnpm -pnpm add @sentry/capacitor @sentry/vue -``` +| Angular version | Recommended Sentry SDK | +| --------------- | ------------------------------------------------- | +| 14 and newer | `@sentry/capacitor` `@sentry/angular` | +| 12 or 13 | `@sentry/capacitor^0` `@sentry/angular-ivy@^7` \* | +| 10 or 11 | `@sentry/capacitor^0` `@sentry/angular@^7` \* | -```bash {tabTitle:Nuxt} -# npm -npm install @sentry/capacitor @sentry/nuxt --save +\* These versions of the SDK are no longer maintained or tested. Version 0 might still receive bug fixes, but we don't guarantee support. -# yarn -yarn add @sentry/capacitor @sentry/nuxt +### React and Vue -# pnpm -pnpm add @sentry/capacitor @sentry/nuxt -``` +Both frameworks are fully compatible with the current and beta versions of Sentry Capacitor. -```bash {tabTitle:Other} -# npm -npm install @sentry/capacitor @sentry/browser --save + -# yarn -yarn add @sentry/capacitor @sentry/browser +## Step 2: Configure -# pnpm -pnpm add @sentry/capacitor @sentry/browser -``` +Choose the features you want to configure, and this guide will show you how: -### Angular Version Compatibility + -Currently, the Sentry Capacitor SDK only supports Angular 14 and newer. + -If you're using an older version of Angular, you also need to use an older version of the SDK. See the table below for compatibility guidance: +### Initialize the Sentry SDK -| Angular version | Recommended Sentry SDK | -| --------------- | --------------------------------------------------- | -| 14 and newer | `@sentry/capacitor` `@sentry/angular` | -| 12 or 13 | `@sentry/capacitor^0` `@sentry/angular-ivy@^7` * | -| 10 or 11 | `@sentry/capacitor^0` `@sentry/angular@^7` * | +Initialize Sentry as early as possible in your application's lifecycle. -\* These versions of the SDK are no longer maintained or tested. Version 0 might still receive bug fixes, but we don't guarantee support. +If you're using Angular, React, Vue, or Nuxt, make sure to forward the `init` method from the framework's Sentry SDK, as you can see in these code snippets. If you're following the vanilla setup, you don't need to do this. -### React and Vue Version Compatibility + -Both Frameworks are fully compatible with the current and beta versions of Sentry Capacitor. +## Step 3: Add Readable Stack Traces With Source Maps (Optional) -## Configure + -In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/). You can also get to the root of an error or performance issue faster, by watching a video-like reproduction of a user session with [session replay](/product/explore/session-replay/web/getting-started/). +## Step 4: Provide Native Debug Information for iOS (Optional) -Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below. +You need to provide debug information to Sentry to make the stack-trace information for native crashes on iOS easier to understand. You can provide debug information by [uploading dSYM files](/platforms/javascript/guides/capacitor/dsym). - +## Step 5: Verify -Configuration should happen as early as possible in your application's lifecycle. +Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project. -Then forward the `init` method from the sibling Sentry SDK for the framework you use, such as Angular in this example: +### Issues +To verify that Sentry captures errors and creates issues in your Sentry project, add the following test button and logic: -```typescript {tabTitle: Angular 14+} {filename: app.module.ts} -import * as Sentry from "@sentry/capacitor"; -import * as SentryAngular from "@sentry/angular"; - -Sentry.init( - { - dsn: "___PUBLIC_DSN___", - - // Adds request headers and IP for users, for more info visit: - // https://docs.sentry.io/platforms/javascript/guides/capacitor/configuration/options/#sendDefaultPii - sendDefaultPii: true, - - // Set your release version, such as "getsentry@1.0.0" - release: "my-project-name@", - // Set your dist version, such as "1" - dist: "", - // ___PRODUCT_OPTION_START___ logs - // Logs requires @sentry/capacitor 2.0.0 or newer. - _experiments: { - enableLogs: true, - beforeSendLog: (log) => { - // Add custom filters to logs. - return log; - } - }, - // ___PRODUCT_OPTION_END___ logs - integrations: [ - // ___PRODUCT_OPTION_START___ performance - // Registers and configures the Tracing integration, - // which automatically instruments your application to monitor its - // performance, including custom Angular routing instrumentation - Sentry.browserTracingIntegration(), - // ___PRODUCT_OPTION_END___ performance - // ___PRODUCT_OPTION_START___ session-replay - // Registers the Replay integration, - // which automatically captures Session Replays - Sentry.replayIntegration(), - // ___PRODUCT_OPTION_END___ session-replay - // ___PRODUCT_OPTION_START___ user-feedback - Sentry.feedbackIntegration({ - // Additional SDK configuration goes in here, for example: - colorScheme: "system", - }), - // ___PRODUCT_OPTION_END___ user-feedback - ], - // ___PRODUCT_OPTION_START___ performance - - // Set tracesSampleRate to 1.0 to capture 100% - // of transactions for tracing. - // We recommend adjusting this value in production - // Learn more at - // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate - tracesSampleRate: 1.0, - - // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled - tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/], - // ___PRODUCT_OPTION_END___ performance - // ___PRODUCT_OPTION_START___ session-replay - - // Capture Replay for 10% of all sessions, - // plus for 100% of sessions with an error - // Learn more at - // https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration - replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1.0, - // ___PRODUCT_OPTION_END___ session-replay - }, - // Forward the init method from @sentry/angular - SentryAngular.init -); - -@NgModule({ - providers: [ - { - provide: ErrorHandler, - // Attach the Sentry ErrorHandler - useValue: SentryAngular.createErrorHandler(), - }, - // ___PRODUCT_OPTION_START___ performance - { - provide: SentryAngular.TraceService, - deps: [Router], - }, - { - provide: APP_INITIALIZER, - useFactory: () => () => {}, - deps: [SentryAngular.TraceService], - multi: true, - }, - // ___PRODUCT_OPTION_END___ performance - ], +```javascript {tabTitle: Angular 12, 13, 14+} +@Component({ + selector: "app-root", + template: ` + + ` }) +class AppComponent { + // ... + throwError(): void { + throw new Error("Sentry Test Error"); + } +} ``` -```typescript {tabTitle: Angular 12, 13} {filename: app.module.ts} -// Requires @sentry/capacitor V0. -import * as Sentry from "@sentry/capacitor"; -import * as SentryAngular from "@sentry/angular-ivy"; - -Sentry.init( - { - dsn: "___PUBLIC_DSN___", - - // Adds request headers and IP for users, for more info visit: - // https://docs.sentry.io/platforms/javascript/guides/capacitor/configuration/options/#sendDefaultPii - sendDefaultPii: true, - - // Set your release version, such as "getsentry@1.0.0" - release: "my-project-name@", - // Set your dist version, such as "1" - dist: "", - // ___PRODUCT_OPTION_START___ logs - // Logs requires Angular 14 or newer. - // ___PRODUCT_OPTION_END___ logs - integrations: [ - // ___PRODUCT_OPTION_START___ performance - // Registers and configures the Tracing integration, - // which automatically instruments your application to monitor its - // performance, including custom Angular routing instrumentation - new Sentry.BrowserTracing(), - // ___PRODUCT_OPTION_END___ performance - // ___PRODUCT_OPTION_START___ session-replay - // Registers the Replay integration, - // which automatically captures Session Replays - new Sentry.Replay(), - // ___PRODUCT_OPTION_END___ session-replay - // ___PRODUCT_OPTION_START___ user-feedback - Sentry.feedbackIntegration({ - // Additional SDK configuration goes in here, for example: - colorScheme: "system", - }), - // ___PRODUCT_OPTION_END___ user-feedback - ], - - // ___PRODUCT_OPTION_START___ performance - // Set tracesSampleRate to 1.0 to capture 100% - // of transactions for tracing. - // We recommend adjusting this value in production - // Learn more at - // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate - tracesSampleRate: 1.0, - - // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled - tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/], - // ___PRODUCT_OPTION_END___ performance - // ___PRODUCT_OPTION_START___ session-replay - - // Capture Replay for 10% of all sessions, - // plus for 100% of sessions with an error - // Learn more at - // https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration - replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1.0, - // ___PRODUCT_OPTION_END___ session-replay - }, - // Forward the init method from @sentry/angular - SentryAngular.init -); - -@NgModule({ - providers: [ - { - provide: ErrorHandler, - // Attach the Sentry ErrorHandler - useValue: SentryAngular.createErrorHandler(), - }, - { - provide: SentryAngular.TraceService, - deps: [Router], - }, - { - provide: APP_INITIALIZER, - useFactory: () => () => {}, - deps: [SentryAngular.TraceService], - multi: true, - }, - ], -}) +```javascript {tabTitle: React} + ``` -```typescript {tabTitle: React} {filename: index.tsx} -import * as Sentry from "@sentry/capacitor"; -import * as SentryReact from "@sentry/react"; - -Sentry.init( - { - dsn: "___PUBLIC_DSN___", - - // Adds request headers and IP for users, for more info visit: - // https://docs.sentry.io/platforms/javascript/guides/capacitor/configuration/options/#sendDefaultPii - sendDefaultPii: true, - - // Set your release version, such as "getsentry@1.0.0" - release: "my-project-name@", - // Set your dist version, such as "1" - dist: "", - // ___PRODUCT_OPTION_START___ logs - // Logs requires @sentry/capacitor 2.0.0 or newer. - enableLogs: true, - beforeSendLog: (log) => { - // Add custom filters to logs. - return log; - }, - // ___PRODUCT_OPTION_END___ logs - integrations: [ - // ___PRODUCT_OPTION_START___ performance - // Registers and configures the Tracing integration, - // which automatically instruments your application to monitor its - // performance, including custom Angular routing instrumentation - Sentry.browserTracingIntegration(), - // ___PRODUCT_OPTION_END___ performance - // ___PRODUCT_OPTION_START___ session-replay - // Registers the Replay integration, - // which automatically captures Session Replays - Sentry.replayIntegration(), - // ___PRODUCT_OPTION_END___ session-replay - // ___PRODUCT_OPTION_START___ user-feedback - Sentry.feedbackIntegration({ - // Additional SDK configuration goes in here, for example: - colorScheme: "system", - }), - // ___PRODUCT_OPTION_END___ user-feedback - ], - // ___PRODUCT_OPTION_START___ performance - - // Set tracesSampleRate to 1.0 to capture 100% - // of transactions for tracing. - // We recommend adjusting this value in production - // Learn more at - // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate - tracesSampleRate: 1.0, - - // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled - tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/], - // ___PRODUCT_OPTION_END___ performance - // ___PRODUCT_OPTION_START___ session-replay - - // Capture Replay for 10% of all sessions, - // plus for 100% of sessions with an error - // Learn more at - // https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration - replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1.0, - // ___PRODUCT_OPTION_END___ session-replay - }, - // Forward the init method from @sentry/react - SentryReact.init -); +```javascript {tabTitle: Vue} + + +export default { + // ... + methods: { + throwError() { + throw new Error('Sentry Error'); + } + } +}; ``` -```typescript {tabTitle: Vue} {filename: main.ts} -import * as Sentry from "@sentry/capacitor"; -import * as SentryVue from "@sentry/vue"; -import { createApp } from 'vue' - -const app = createApp(App) - -Sentry.init( - { - dsn: "___PUBLIC_DSN___", - - // Vue specific settings. - siblingOptions: { - vueOptions: { - app: app, - attachErrorHandler: false, - attachProps: true, - }, - }, - - // Adds request headers and IP for users, for more info visit: - // https://docs.sentry.io/platforms/javascript/guides/capacitor/configuration/options/#sendDefaultPii - sendDefaultPii: true, - - // Set your release version, such as "getsentry@1.0.0" - release: "my-project-name@", - // Set your dist version, such as "1" - dist: "", - // ___PRODUCT_OPTION_START___ logs - // Logs requires @sentry/capacitor 2.0.0 or newer. - enableLogs: true, - beforeSendLog: (log) => { - // Add custom filters to logs. - return log; - }, - // ___PRODUCT_OPTION_END___ logs - integrations: [ - // ___PRODUCT_OPTION_START___ performance - // Registers and configures the Tracing integration, - // which automatically instruments your application to monitor its - // performance, including custom Angular routing instrumentation - Sentry.browserTracingIntegration(), - // ___PRODUCT_OPTION_END___ performance - // ___PRODUCT_OPTION_START___ session-replay - // Registers the Replay integration, - // which automatically captures Session Replays - Sentry.replayIntegration(), - // ___PRODUCT_OPTION_END___ session-replay - // ___PRODUCT_OPTION_START___ user-feedback - Sentry.feedbackIntegration({ - // Additional SDK configuration goes in here, for example: - colorScheme: "system", - }), - // ___PRODUCT_OPTION_END___ user-feedback - ], - // ___PRODUCT_OPTION_START___ performance - - // Set tracesSampleRate to 1.0 to capture 100% - // of transactions for tracing. - // We recommend adjusting this value in production - // Learn more at - // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate - tracesSampleRate: 1.0, - - // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled - tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/], - // ___PRODUCT_OPTION_END___ performance - // ___PRODUCT_OPTION_START___ session-replay - - // Capture Replay for 10% of all sessions, - // plus for 100% of sessions with an error - // Learn more at - // https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration - replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1.0, - // ___PRODUCT_OPTION_END___ session-replay - }, - - // Forward the init method from @sentry/vue - SentryVue.init -); +```html {tabTitle: Nuxt} + + + ``` -```typescript {tabTitle: Nuxt} {filename: sentry.client.config.ts} -import * as Sentry from "@sentry/capacitor"; -import * as SentryNuxt from "@sentry/nuxt"; - -Sentry.init( - { - dsn: "___PUBLIC_DSN___", - // Adds request headers and IP for users, for more info visit: - // https://docs.sentry.io/platforms/javascript/guides/capacitor/configuration/options/#sendDefaultPii - sendDefaultPii: true, - - // Set your release version, such as "getsentry@1.0.0" - release: "my-project-name@", - // Set your dist version, such as "1" - dist: "", - // ___PRODUCT_OPTION_START___ logs - // Logs requires @sentry/capacitor 2.0.0 or newer. - enableLogs: true, - beforeSendLog: (log) => { - // Add custom filters to logs. - return log; - }, - // ___PRODUCT_OPTION_END___ logs - integrations: [ - // ___PRODUCT_OPTION_START___ performance - // Registers and configures the Tracing integration, - // which automatically instruments your application to monitor its - // performance, including custom Angular routing instrumentation - Sentry.browserTracingIntegration(), - // ___PRODUCT_OPTION_END___ performance - // ___PRODUCT_OPTION_START___ session-replay - // Registers the Replay integration, - // which automatically captures Session Replays - Sentry.replayIntegration(), - // ___PRODUCT_OPTION_END___ session-replay - // ___PRODUCT_OPTION_START___ user-feedback - Sentry.feedbackIntegration({ - // Additional SDK configuration goes in here, for example: - colorScheme: "system", - }), - // ___PRODUCT_OPTION_END___ user-feedback - ], - // ___PRODUCT_OPTION_START___ performance - - // Set tracesSampleRate to 1.0 to capture 100% - // of transactions for tracing. - // We recommend adjusting this value in production - // Learn more at - // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate - tracesSampleRate: 1.0, - - // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled - tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/], - // ___PRODUCT_OPTION_END___ performance - // ___PRODUCT_OPTION_START___ session-replay - - // Capture Replay for 10% of all sessions, - // plus for 100% of sessions with an error - // Learn more at - // https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration - replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1.0, - // ___PRODUCT_OPTION_END___ session-replay - }, - - // Forward the init method from @sentry/nuxt - SentryNuxt.init -); +```html {tabTitle: Other} + + + ``` -You can also use the features available with the Sentry SDK for the framework you use, such as [Angular](/platforms/javascript/guides/angular/). + + Open the page in a browser and click the button to trigger a frontend error. + + + -### Source Maps + -You will need to upload source maps to make sense of the events you receive in Sentry. +### Tracing -If you are using Capacitor with Ionic-Angular, upload your outputPath folder (typically `www` or `dist`) on **every build** you release. The values for `` and `` must match the values passed into `Sentry.init` for events to be deminified correctly. +To test your tracing configuration, update the previous code snippet and wrap the error in a custom span: -```bash {tabTitle: Ionic Build & others} -sentry-cli sourcemaps inject --org ___ORG_SLUG___ --project ___PROJECT_SLUG___ ./www -sentry-cli sourcemaps upload --release --dist ./www +```javascript {tabTitle: Angular 12, 13, 14+} +import * as Sentry from "@sentry/capacitor"; + +@Component({ + selector: "app-root", + template: ` + + ` +}) +class AppComponent { + // ... + throwError(): void { + Sentry.startSpan({ op: "test", name: "Example Frontend Span" }, () => { + throw new Error("Sentry Test Error"); + }); + } +} ``` -```bash {tabTitle: Ionic Capacitor Build} +```javascript {tabTitle: React} +import * as Sentry from "@sentry/capacitor"; -# Android -sentry-cli sourcemaps inject --org ___ORG_SLUG___ --project ___PROJECT_SLUG___ ./android/app/src/main/assets/public -sentry-cli sourcemaps upload --org ___ORG_SLUG___ --project ___PROJECT_SLUG___ --release --dist ./android/app/src/main/assets/public -find ./android/app/src/main/assets/public -type f -name '*.map' -delete # Optional, removes sourcemaps from the mobile app. +; +``` -# iOS -sentry-cli sourcemaps inject --org ___ORG_SLUG___ --project ___PROJECT_SLUG___ ./ios/App/App/public -sentry-cli sourcemaps upload --org ___ORG_SLUG___ --project ___PROJECT_SLUG___ --release --dist ./ios/App/App/public, -find ./ios/App/App/public -type f -name '*.map' -delete # Optional, removes sourcemaps from the mobile app. +```javascript {tabTitle: Vue} +import * as Sentry from "@sentry/capacitor"; + + +export default { + // ... + methods: { + throwError() { + Sentry.startSpan({ op: "test", name: "Example Frontend Span" }, async () => { + throw new Error("Sentry Error"); + }); + } + } +}; ``` - -If you are building your project using `ionic capacitor build`, you must upload the source maps from the native app folder (e.g., android/app/build/assets) — not from the `outputPath` defined in your web project (like `www` or `dist`). - +```html {tabTitle: Nuxt} + + + +``` +```html {tabTitle: Other} + -Learn more about uploading [source maps](/platforms/javascript/guides/capacitor/sourcemaps/). + +``` -## Verify +Open the page in a browser and click the button to trigger a frontend error and trace. -This snippet includes an intentional error, so you can test that everything is working as soon as you set it up. + -```javascript -import * as Sentry from "@sentry/capacitor"; +### View Captured Data in Sentry -Sentry.captureException("Test Captured Exception"); -``` +Now, head over to your project on [Sentry.io](https://sentry.io/) to view the collected data (it takes a couple of moments for the data to appear). -You can also throw an error anywhere in your application: + -```javascript -throw new Error(`Test Thrown Error`); -``` +## Next Steps - +At this point, you should have integrated Sentry into your Capacitor application and should already be sending data to your Sentry project. -Learn more about manually capturing an error or message in our Usage documentation. +Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are: - +- Learn how to use Sentry with Ionic +- Continue to customize your configuration +- Learn how to manually capture errors +- Make use of framework-specific features, such as [Angular](/platforms/javascript/guides/angular/features/), [Vue](/platforms/javascript/guides/vue/features/), [React](/platforms/javascript/guides/react/features/), or [Nuxt](/platforms/javascript/guides/nuxt/features/) + + +- Find various topics in Troubleshooting +- [Get support](https://sentry.zendesk.com/hc/en-us/) -To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved. + diff --git a/includes/sentry-cli-sourcemaps.mdx b/includes/sentry-cli-sourcemaps.mdx index a89cafd6c8e36..0fb25ecf7d26c 100644 --- a/includes/sentry-cli-sourcemaps.mdx +++ b/includes/sentry-cli-sourcemaps.mdx @@ -24,10 +24,30 @@ Debug IDs are used to match the stack frame of an event with its corresponding m To inject Debug IDs, use the following command: + + +```bash {tabTitle: Ionic Build & others} +sentry-cli sourcemaps inject ./www +``` + +```bash {tabTitle: Ionic Capacitor Build} +# Android +sentry-cli sourcemaps inject ./android/app/src/main/assets/public + +# iOS +sentry-cli sourcemaps inject ./ios/App/App/public +``` + + + + + ```bash sentry-cli sourcemaps inject /path/to/directory ``` + + #### Verify Debug IDs Were Injected in Artifacts Minified source files should contain at the end a comment named `debugId` like: @@ -52,10 +72,38 @@ Source maps should contain a field named `debug_id` like: After you've injected Debug IDs into your artifacts, upload them using the following command. + + +```bash {tabTitle: Ionic Build & others} +sentry-cli sourcemaps upload --release --dist ./www +``` + +```bash {tabTitle: Ionic Capacitor Build} + +# Android +sentry-cli sourcemaps upload --release --dist ./android/app/src/main/assets/public +find ./android/app/src/main/assets/public -type f -name '*.map' -delete # Optional, removes sourcemaps from the mobile app. + +# iOS +sentry-cli sourcemaps upload --release --dist ./ios/App/App/public +find ./ios/App/App/public -type f -name '*.map' -delete # Optional, removes sourcemaps from the mobile app. + +``` + + +Run these commands for every production build. The `` and `` values must match the values you pass to `Sentry.init` for events to be deminified correctly. + + + + + + ```bash sentry-cli sourcemaps upload /path/to/directory ``` + + #### Verify That Artifact Bundles Were Uploaded Open up Sentry and navigate to **Project Settings > Source Maps**. If you choose “Artifact Bundles” in the tabbed navigation, you'll see all the artifact bundles that have been successfully uploaded to Sentry. diff --git a/platform-includes/getting-started-config/javascript.capacitor.mdx b/platform-includes/getting-started-config/javascript.capacitor.mdx new file mode 100644 index 0000000000000..9885a27feb043 --- /dev/null +++ b/platform-includes/getting-started-config/javascript.capacitor.mdx @@ -0,0 +1,448 @@ +```typescript {tabTitle: Angular 14+} {filename: app.module.ts} +import * as Sentry from "@sentry/capacitor"; +import * as SentryAngular from "@sentry/angular"; + +Sentry.init( + { + dsn: "___PUBLIC_DSN___", + + // Adds request headers and IP for users, for more info visit: + // https://docs.sentry.io/platforms/javascript/guides/capacitor/configuration/options/#sendDefaultPii + sendDefaultPii: true, + + // Set your release version, such as "getsentry@1.0.0" + release: "my-project-name@", + // Set your dist version, such as "1" + dist: "", + // ___PRODUCT_OPTION_START___ logs + // Logs requires @sentry/capacitor 2.0.0 or newer. + enableLogs: true, + // ___PRODUCT_OPTION_END___ logs + integrations: [ + // ___PRODUCT_OPTION_START___ performance + // Registers and configures the Tracing integration, + // which automatically instruments your application to monitor its + // performance, including custom Angular routing instrumentation + Sentry.browserTracingIntegration(), + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ session-replay + // Registers the Replay integration, + // which automatically captures Session Replays + Sentry.replayIntegration(), + // ___PRODUCT_OPTION_END___ session-replay + // ___PRODUCT_OPTION_START___ user-feedback + Sentry.feedbackIntegration({ + // Additional SDK configuration goes in here, for example: + colorScheme: "system", + }), + // ___PRODUCT_OPTION_END___ user-feedback + ], + // ___PRODUCT_OPTION_START___ performance + + // Set tracesSampleRate to 1.0 to capture 100% + // of transactions for tracing. + // We recommend adjusting this value in production + // Learn more at + // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate + tracesSampleRate: 1.0, + + // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled + tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/], + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ session-replay + + // Capture Replay for 10% of all sessions, + // plus for 100% of sessions with an error + // Learn more at + // https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0, + // ___PRODUCT_OPTION_END___ session-replay + }, + // Forward the init method from @sentry/angular + SentryAngular.init +); + +@NgModule({ + providers: [ + { + provide: ErrorHandler, + // Attach the Sentry ErrorHandler + useValue: SentryAngular.createErrorHandler(), + }, + // ___PRODUCT_OPTION_START___ performance + { + provide: SentryAngular.TraceService, + deps: [Router], + }, + { + provide: APP_INITIALIZER, + useFactory: () => () => {}, + deps: [SentryAngular.TraceService], + multi: true, + }, + // ___PRODUCT_OPTION_END___ performance + ], +}) +``` + +```typescript {tabTitle: Angular 12, 13} {filename: app.module.ts} +// Requires @sentry/capacitor V0. +import * as Sentry from "@sentry/capacitor"; +import * as SentryAngular from "@sentry/angular-ivy"; + +Sentry.init( + { + dsn: "___PUBLIC_DSN___", + + // Adds request headers and IP for users, for more info visit: + // https://docs.sentry.io/platforms/javascript/guides/capacitor/configuration/options/#sendDefaultPii + sendDefaultPii: true, + + // Set your release version, such as "getsentry@1.0.0" + release: "my-project-name@", + // Set your dist version, such as "1" + dist: "", + // ___PRODUCT_OPTION_START___ logs + // Logs requires Angular 14 or newer. + // ___PRODUCT_OPTION_END___ logs + integrations: [ + // ___PRODUCT_OPTION_START___ performance + // Registers and configures the Tracing integration, + // which automatically instruments your application to monitor its + // performance, including custom Angular routing instrumentation + new Sentry.BrowserTracing(), + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ session-replay + // Registers the Replay integration, + // which automatically captures Session Replays + new Sentry.Replay(), + // ___PRODUCT_OPTION_END___ session-replay + // ___PRODUCT_OPTION_START___ user-feedback + Sentry.feedbackIntegration({ + // Additional SDK configuration goes in here, for example: + colorScheme: "system", + }), + // ___PRODUCT_OPTION_END___ user-feedback + ], + + // ___PRODUCT_OPTION_START___ performance + // Set tracesSampleRate to 1.0 to capture 100% + // of transactions for tracing. + // We recommend adjusting this value in production + // Learn more at + // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate + tracesSampleRate: 1.0, + + // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled + tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/], + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ session-replay + + // Capture Replay for 10% of all sessions, + // plus for 100% of sessions with an error + // Learn more at + // https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0, + // ___PRODUCT_OPTION_END___ session-replay + }, + // Forward the init method from @sentry/angular + SentryAngular.init +); + +@NgModule({ + providers: [ + { + provide: ErrorHandler, + // Attach the Sentry ErrorHandler + useValue: SentryAngular.createErrorHandler(), + }, + { + provide: SentryAngular.TraceService, + deps: [Router], + }, + { + provide: APP_INITIALIZER, + useFactory: () => () => {}, + deps: [SentryAngular.TraceService], + multi: true, + }, + ], +}) +``` + +```typescript {tabTitle: React} {filename: index.tsx} +import * as Sentry from "@sentry/capacitor"; +import * as SentryReact from "@sentry/react"; + +Sentry.init( + { + dsn: "___PUBLIC_DSN___", + + // Adds request headers and IP for users, for more info visit: + // https://docs.sentry.io/platforms/javascript/guides/capacitor/configuration/options/#sendDefaultPii + sendDefaultPii: true, + + // Set your release version, such as "getsentry@1.0.0" + release: "my-project-name@", + // Set your dist version, such as "1" + dist: "", + // ___PRODUCT_OPTION_START___ logs + // Logs requires @sentry/capacitor 2.0.0 or newer. + enableLogs: true, + // ___PRODUCT_OPTION_END___ logs + integrations: [ + // ___PRODUCT_OPTION_START___ performance + // Registers and configures the Tracing integration, + // which automatically instruments your application to monitor its + // performance, including custom Angular routing instrumentation + Sentry.browserTracingIntegration(), + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ session-replay + // Registers the Replay integration, + // which automatically captures Session Replays + Sentry.replayIntegration(), + // ___PRODUCT_OPTION_END___ session-replay + // ___PRODUCT_OPTION_START___ user-feedback + Sentry.feedbackIntegration({ + // Additional SDK configuration goes in here, for example: + colorScheme: "system", + }), + // ___PRODUCT_OPTION_END___ user-feedback + ], + // ___PRODUCT_OPTION_START___ performance + + // Set tracesSampleRate to 1.0 to capture 100% + // of transactions for tracing. + // We recommend adjusting this value in production + // Learn more at + // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate + tracesSampleRate: 1.0, + + // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled + tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/], + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ session-replay + + // Capture Replay for 10% of all sessions, + // plus for 100% of sessions with an error + // Learn more at + // https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0, + // ___PRODUCT_OPTION_END___ session-replay + }, + // Forward the init method from @sentry/react + SentryReact.init +); +``` + +```typescript {tabTitle: Vue} {filename: main.ts} +import * as Sentry from "@sentry/capacitor"; +import * as SentryVue from "@sentry/vue"; +import { createApp } from "vue"; + +const app = createApp(App); + +Sentry.init( + { + dsn: "___PUBLIC_DSN___", + + // Vue specific settings. + siblingOptions: { + vueOptions: { + app: app, + attachErrorHandler: false, + attachProps: true, + }, + }, + + // Adds request headers and IP for users, for more info visit: + // https://docs.sentry.io/platforms/javascript/guides/capacitor/configuration/options/#sendDefaultPii + sendDefaultPii: true, + + // Set your release version, such as "getsentry@1.0.0" + release: "my-project-name@", + // Set your dist version, such as "1" + dist: "", + // ___PRODUCT_OPTION_START___ logs + // Logs requires @sentry/capacitor 2.0.0 or newer. + enableLogs: true, + // ___PRODUCT_OPTION_END___ logs + integrations: [ + // ___PRODUCT_OPTION_START___ performance + // Registers and configures the Tracing integration, + // which automatically instruments your application to monitor its + // performance, including custom Angular routing instrumentation + Sentry.browserTracingIntegration(), + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ session-replay + // Registers the Replay integration, + // which automatically captures Session Replays + Sentry.replayIntegration(), + // ___PRODUCT_OPTION_END___ session-replay + // ___PRODUCT_OPTION_START___ user-feedback + Sentry.feedbackIntegration({ + // Additional SDK configuration goes in here, for example: + colorScheme: "system", + }), + // ___PRODUCT_OPTION_END___ user-feedback + ], + // ___PRODUCT_OPTION_START___ performance + + // Set tracesSampleRate to 1.0 to capture 100% + // of transactions for tracing. + // We recommend adjusting this value in production + // Learn more at + // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate + tracesSampleRate: 1.0, + + // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled + tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/], + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ session-replay + + // Capture Replay for 10% of all sessions, + // plus for 100% of sessions with an error + // Learn more at + // https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0, + // ___PRODUCT_OPTION_END___ session-replay + }, + + // Forward the init method from @sentry/vue + SentryVue.init +); +``` + +```typescript {tabTitle: Nuxt} {filename: sentry.client.config.ts} +import * as Sentry from "@sentry/capacitor"; +import * as SentryNuxt from "@sentry/nuxt"; + +Sentry.init( + { + dsn: "___PUBLIC_DSN___", + // Adds request headers and IP for users, for more info visit: + // https://docs.sentry.io/platforms/javascript/guides/capacitor/configuration/options/#sendDefaultPii + sendDefaultPii: true, + + // Set your release version, such as "getsentry@1.0.0" + release: "my-project-name@", + // Set your dist version, such as "1" + dist: "", + // ___PRODUCT_OPTION_START___ logs + // Logs requires @sentry/capacitor 2.0.0 or newer. + enableLogs: true, + // ___PRODUCT_OPTION_END___ logs + integrations: [ + // ___PRODUCT_OPTION_START___ performance + // Registers and configures the Tracing integration, + // which automatically instruments your application to monitor its + // performance, including custom Angular routing instrumentation + Sentry.browserTracingIntegration(), + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ session-replay + // Registers the Replay integration, + // which automatically captures Session Replays + Sentry.replayIntegration(), + // ___PRODUCT_OPTION_END___ session-replay + // ___PRODUCT_OPTION_START___ user-feedback + Sentry.feedbackIntegration({ + // Additional SDK configuration goes in here, for example: + colorScheme: "system", + }), + // ___PRODUCT_OPTION_END___ user-feedback + ], + // ___PRODUCT_OPTION_START___ performance + + // Set tracesSampleRate to 1.0 to capture 100% + // of transactions for tracing. + // We recommend adjusting this value in production + // Learn more at + // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate + tracesSampleRate: 1.0, + + // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled + tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/], + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ session-replay + + // Capture Replay for 10% of all sessions, + // plus for 100% of sessions with an error + // Learn more at + // https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0, + // ___PRODUCT_OPTION_END___ session-replay + }, + + // Forward the init method from @sentry/nuxt + SentryNuxt.init +); +``` + +```javascript {tabTitle: Other} {filename: main.(ts|js)} +import * as Sentry from "@sentry/capacitor"; +// ___PRODUCT_OPTION_START___ user-feedback +import { feedbackIntegration } from "@sentry/browser"; +// ___PRODUCT_OPTION_END___ user-feedback + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + + // Adds request headers and IP for users, for more info visit: + // https://docs.sentry.io/platforms/javascript/guides/capacitor/configuration/options/#sendDefaultPii + sendDefaultPii: true, + + // Set your release version, such as "getsentry@1.0.0" + release: "my-project-name@", + // Set your dist version, such as "1" + dist: "", + // ___PRODUCT_OPTION_START___ logs + // Logs requires @sentry/capacitor 2.0.0 or newer. + enableLogs: true, + // ___PRODUCT_OPTION_END___ logs + integrations: [ + // ___PRODUCT_OPTION_START___ performance + // Registers and configures the Tracing integration, + // which automatically instruments your application to monitor its + // performance, including custom Angular routing instrumentation + Sentry.browserTracingIntegration(), + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ session-replay + // Registers the Replay integration, + // which automatically captures Session Replays + Sentry.replayIntegration(), + // ___PRODUCT_OPTION_END___ session-replay + // ___PRODUCT_OPTION_START___ user-feedback + feedbackIntegration({ + // Additional SDK configuration goes in here, for example: + colorScheme: "system", + }), + // ___PRODUCT_OPTION_END___ user-feedback + ], + // ___PRODUCT_OPTION_START___ performance + + // Set tracesSampleRate to 1.0 to capture 100% + // of transactions for tracing. + // We recommend adjusting this value in production + // Learn more at + // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate + tracesSampleRate: 1.0, + + // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled + tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/], + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ session-replay + + // Capture Replay for 10% of all sessions, + // plus for 100% of sessions with an error + // Learn more at + // https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0, + // ___PRODUCT_OPTION_END___ session-replay +}); +``` diff --git a/platform-includes/getting-started-install/javascript.capacitor.mdx b/platform-includes/getting-started-install/javascript.capacitor.mdx new file mode 100644 index 0000000000000..c28a49c26351d --- /dev/null +++ b/platform-includes/getting-started-install/javascript.capacitor.mdx @@ -0,0 +1,54 @@ +```bash {tabTitle:Angular} +# npm +npm install @sentry/capacitor @sentry/angular --save + +# yarn +yarn add @sentry/capacitor @sentry/angular + +# pnpm +pnpm add @sentry/capacitor @sentry/angular +``` + +```bash {tabTitle:React} +# npm +npm install @sentry/capacitor @sentry/react --save + +# yarn +yarn add @sentry/capacitor @sentry/react + +# pnpm +pnpm add @sentry/capacitor @sentry/react +``` + +```bash {tabTitle:Vue} +# npm +npm install @sentry/capacitor @sentry/vue --save + +# yarn +yarn add @sentry/capacitor @sentry/vue + +# pnpm +pnpm add @sentry/capacitor @sentry/vue +``` + +```bash {tabTitle:Nuxt} +# npm +npm install @sentry/capacitor @sentry/nuxt --save + +# yarn +yarn add @sentry/capacitor @sentry/nuxt + +# pnpm +pnpm add @sentry/capacitor @sentry/nuxt +``` + +```bash {tabTitle:Other} +# npm +npm install @sentry/capacitor @sentry/browser --save + +# yarn +yarn add @sentry/capacitor @sentry/browser + +# pnpm +pnpm add @sentry/capacitor @sentry/browser +```