Skip to content

Commit b72e55c

Browse files
Refactor Ionic/Capacitor/Cordova Wizards (#5093)
Co-authored-by: Isabel <[email protected]>
1 parent 923d52c commit b72e55c

File tree

5 files changed

+77
-34
lines changed

5 files changed

+77
-34
lines changed

src/includes/getting-started-install/javascript.capacitor.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ npm install --save @sentry/capacitor
1616
yarn add @sentry/capacitor
1717
```
1818

19-
### Android Specifics
19+
### Capacitor 2 - Android Specifics
20+
21+
<Note>
22+
23+
This step is not needed if you are using Capacitor 3
24+
25+
</Note>
2026

2127
Add the plugin declaration to your `MainActivity.java` file
2228

src/platforms/javascript/guides/capacitor/troubleshooting.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,28 @@ Then update your iOS settings:
2727
```bash
2828
npx cap sync
2929
```
30+
31+
## Capacitor on Android
32+
33+
### No events sent
34+
35+
Check if you added `SentryCapacitor` to the bridge. This step is required for Capacitor 2 and optional on Capacitor 3. (It's only required if you are initializing other plugins using the old method. If so, we recommend you use `registerPlugin` instead of the deprecated code for initializing plugins.)
36+
37+
```java
38+
import io.sentry.capacitor.SentryCapacitor;
39+
40+
public class MainActivity extends BridgeActivity {
41+
@Override
42+
public void onCreate(Bundle savedInstanceState) {
43+
super.onCreate(savedInstanceState);
44+
45+
// Capacitor 3
46+
registerPlugin(SentryCapacitor.class);
47+
48+
// Capacitor 2
49+
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
50+
add(SentryCapacitor.class);
51+
}});
52+
}
53+
}
54+
```

src/wizard/capacitor/index.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ npm install --save @sentry/capacitor @sentry/tracing
2525
yarn add @sentry/capacitor
2626
```
2727

28-
## Android Installation
28+
## Capacitor 2 - Android Installation
29+
30+
<Note>
31+
32+
This step is not needed if you are using Capacitor 3
33+
34+
</Note>
2935

3036
Then, add the `SentryCapacitor` plugin class inside the `onCreate` method of your `MainActivity` file.
3137

@@ -59,7 +65,7 @@ import com.getcapacitor.Plugin
5965
import io.sentry.capacitor.SentryCapacitor
6066

6167
class MainActivity : BridgeActivity() {
62-
fun onCreate(savedInstanceState: Bundle?) {
68+
override fun onCreate(savedInstanceState: Bundle?) {
6369
super.onCreate(savedInstanceState)
6470
// Initializes the Bridge
6571
this.init(
@@ -78,26 +84,26 @@ With Ionic/Angular:
7884

7985
```typescript
8086
// app.module.ts
81-
import * as Sentry from "@sentry/capacitor";
82-
import * as SentryAngular from "@sentry/angular";
87+
import * as Sentry from '@sentry/capacitor';
88+
import * as SentryAngular from '@sentry/angular';
8389
// If taking advantage of automatic instrumentation (highly recommended)
84-
import { BrowserTracing } from "@sentry/tracing";
90+
import { BrowserTracing } from '@sentry/tracing';
8591
// Or, if only manually tracing
8692
// import "@sentry/tracing";
8793
// Note: You MUST import the package in some way for tracing to work
8894

8995
Sentry.init(
9096
{
91-
dsn: "___PUBLIC_DSN___",
97+
dsn: '___PUBLIC_DSN___',
9298
// To set your release and dist versions
93-
release: "my-project-name@" + process.env.npm_package_version,
94-
dist: "1",
99+
release: 'my-project-name@' + process.env.npm_package_version,
100+
dist: '1',
95101
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
96102
// We recommend adjusting this value in production.
97103
tracesSampleRate: 1.0,
98104
integrations: [
99105
new BrowserTracing({
100-
tracingOrigins: ["localhost", "https://yourserver.io/api"],
106+
tracingOrigins: ['localhost', 'https://yourserver.io/api'],
101107
}),
102108
]
103109
},
@@ -120,15 +126,15 @@ Standalone:
120126

121127
```javascript
122128
// App.js
123-
import * as Sentry from "@sentry/capacitor";
129+
import * as Sentry from '@sentry/capacitor';
124130

125131
Sentry.init({
126-
dsn: "___PUBLIC_DSN___",
132+
dsn: '___PUBLIC_DSN___',
127133

128-
// Set your release version, such as "[email protected]"
129-
release: "my-project-name@<release-name>",
134+
// Set your release version, such as '[email protected]'
135+
release: 'my-project-name@<release-name>',
130136
// Set your dist version, such as "1"
131-
dist: "<dist>",
137+
dist: '<dist>',
132138
});
133139
```
134140

@@ -137,22 +143,22 @@ Sentry.init({
137143
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:
138144

139145
```javascript
140-
import * as Sentry from "@sentry/capacitor";
146+
import * as Sentry from '@sentry/capacitor';
141147

142-
Sentry.captureException("Test Captured Exception");
148+
Sentry.captureException('Test Captured Exception');
143149
```
144150

145151
You can also throw an error anywhere in your application:
146152

147153
```javascript
148154
// Must be thrown after Sentry.init is called to be captured.
149-
throw new Error(`Test Thrown Error`);
155+
throw new Error('Test Thrown Error');
150156
```
151157

152158
Or trigger a native crash:
153159

154160
```javascript
155-
import * as Sentry from "@sentry/capacitor";
161+
import * as Sentry from '@sentry/capacitor';
156162

157163
Sentry.nativeCrash();
158164
```

src/wizard/cordova/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ You should `init` the SDK in the `deviceReady` function, to make sure the native
1515

1616
```javascript
1717
onDeviceReady: function() {
18-
var Sentry = cordova.require("sentry-cordova.Sentry");
18+
var Sentry = cordova.require('sentry-cordova.Sentry');
1919
Sentry.init({ dsn: '___PUBLIC_DSN___' });
2020
}
2121
```

src/wizard/ionic/index.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ yarn add @sentry/capacitor @sentry/angular
1818
```
1919
The same installation process applies to the other siblings, all you need to do is to replace `@sentry/angular` by the desired sibling.
2020

21-
## Android Installation
21+
## Capacitor 2 - Android Installation
22+
23+
<Note>
24+
25+
This step is not needed if you are using Capacitor 3
26+
27+
</Note>
2228

2329
Then, add the `SentryCapacitor` plugin class inside the `onCreate` method of your `MainActivity` file.
2430

@@ -52,7 +58,7 @@ import com.getcapacitor.Plugin
5258
import io.sentry.capacitor.SentryCapacitor
5359

5460
class MainActivity : BridgeActivity() {
55-
fun onCreate(savedInstanceState: Bundle?) {
61+
override fun onCreate(savedInstanceState: Bundle?) {
5662
super.onCreate(savedInstanceState)
5763
// Initializes the Bridge
5864
this.init(
@@ -68,24 +74,24 @@ class MainActivity : BridgeActivity() {
6874
You must initialize the Sentry SDK as early as you can:
6975

7076
```javascript
71-
import * as Sentry from "@sentry/capacitor";
72-
// The example is using Angular, Import "@sentry/vue" or "@sentry/react" when using a Sibling different than Angular.
73-
import * as SentrySibling from "@sentry/angular";
77+
import * as Sentry from '@sentry/capacitor';
78+
// The example is using Angular, Import '@sentry/vue' or '@sentry/react' when using a Sibling different than Angular.
79+
import * as SentrySibling from '@sentry/angular';
7480
// For automatic instrumentation (highly recommended)
75-
import { BrowserTracing } from "@sentry/tracing";
81+
import { BrowserTracing } from '@sentry/tracing';
7682

7783
Sentry.init(
7884
{
79-
dsn: "___PUBLIC_DSN___",
85+
dsn: '___PUBLIC_DSN___',
8086
// To set your release and dist versions
81-
release: "my-project-name@" + process.env.npm_package_version,
82-
dist: "1",
87+
release: 'my-project-name@' + process.env.npm_package_version,
88+
dist: '1',
8389
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
8490
// We recommend adjusting this value in production.
8591
tracesSampleRate: 1.0,
8692
integrations: [
8793
new BrowserTracing({
88-
tracingOrigins: ["localhost", "https://yourserver.io/api"],
94+
tracingOrigins: ['localhost', 'https://yourserver.io/api'],
8995
}),
9096
]
9197
},
@@ -113,22 +119,22 @@ Additionally for Angular, you will also need to alter NgModule (same code doesn'
113119
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:
114120

115121
```javascript
116-
import * as Sentry from "@sentry/capacitor";
122+
import * as Sentry from '@sentry/capacitor';
117123

118-
Sentry.captureException("Test Captured Exception");
124+
Sentry.captureException('Test Captured Exception');
119125
```
120126

121127
You can also throw an error anywhere in your application:
122128

123129
```javascript
124130
// Must be thrown after Sentry.init is called to be captured.
125-
throw new Error(`Test Thrown Error`);
131+
throw new Error('Test Thrown Error');
126132
```
127133

128134
Or trigger a native crash:
129135

130136
```javascript
131-
import * as Sentry from "@sentry/capacitor";
137+
import * as Sentry from '@sentry/capacitor';
132138

133139
Sentry.nativeCrash();
134140
```

0 commit comments

Comments
 (0)