Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Ionic/Capacitor/Cordova Wizards #5093

Merged
merged 9 commits into from
Jun 3, 2022
56 changes: 32 additions & 24 deletions src/wizard/capacitor/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ public class MainActivity extends BridgeActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
add(SentryCapacitor.class);
}});
// Capacitor 3
registerPlugin(SentryCapacitor.class);
lucas-zimerman marked this conversation as resolved.
Show resolved Hide resolved

// Capacitor 2
// this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
// add(SentryCapacitor.class);
// }});
}
}
```
Expand All @@ -59,13 +63,17 @@ import com.getcapacitor.Plugin
import io.sentry.capacitor.SentryCapacitor

class MainActivity : BridgeActivity() {
fun onCreate(savedInstanceState: Bundle?) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Initializes the Bridge
this.init(
savedInstanceState,
listOf<Class<out Plugin>>(SentryCapacitor::class.java)
)
// Capacitor 3
registerPlugin(SentryCapacitor::class.java)

// Capacitor 2
// this.init(
// savedInstanceState,
// listOf<Class<out Plugin>>(SentryCapacitor::class.java)
// )
}
}
```
Expand All @@ -78,26 +86,26 @@ With Ionic/Angular:

```typescript
// app.module.ts
import * as Sentry from "@sentry/capacitor";
import * as SentryAngular from "@sentry/angular";
import * as Sentry from '@sentry/capacitor';
import * as SentryAngular from '@sentry/angular';
// If taking advantage of automatic instrumentation (highly recommended)
import { BrowserTracing } from "@sentry/tracing";
import { BrowserTracing } from '@sentry/tracing';
// Or, if only manually tracing
// import "@sentry/tracing";
// Note: You MUST import the package in some way for tracing to work

Sentry.init(
{
dsn: "___PUBLIC_DSN___",
dsn: '___PUBLIC_DSN___',
// To set your release and dist versions
release: "my-project-name@" + process.env.npm_package_version,
dist: "1",
release: 'my-project-name@' + process.env.npm_package_version,
dist: '1',
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
tracesSampleRate: 1.0,
integrations: [
new BrowserTracing({
tracingOrigins: ["localhost", "https://yourserver.io/api"],
tracingOrigins: ['localhost', 'https://yourserver.io/api'],
}),
]
},
Expand All @@ -120,15 +128,15 @@ Standalone:

```javascript
// App.js
import * as Sentry from "@sentry/capacitor";
import * as Sentry from '@sentry/capacitor';

Sentry.init({
dsn: "___PUBLIC_DSN___",
dsn: '___PUBLIC_DSN___',

// Set your release version, such as "getsentry@1.0.0"
release: "my-project-name@<release-name>",
// Set your release version, such as 'getsentry@1.0.0'
release: 'my-project-name@<release-name>',
// Set your dist version, such as "1"
dist: "<dist>",
dist: '<dist>',
});
```

Expand All @@ -137,22 +145,22 @@ Sentry.init({
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";
import * as Sentry from '@sentry/capacitor';

Sentry.captureException("Test Captured Exception");
Sentry.captureException('Test Captured Exception');
```

You can also throw an error anywhere in your application:

```javascript
// Must be thrown after Sentry.init is called to be captured.
throw new Error(`Test Thrown Error`);
throw new Error('Test Thrown Error');
```

Or trigger a native crash:

```javascript
import * as Sentry from "@sentry/capacitor";
import * as Sentry from '@sentry/capacitor';

Sentry.nativeCrash();
```
2 changes: 1 addition & 1 deletion src/wizard/cordova/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You should `init` the SDK in the `deviceReady` function, to make sure the native

```javascript
onDeviceReady: function() {
var Sentry = cordova.require("sentry-cordova.Sentry");
var Sentry = cordova.require('sentry-cordova.Sentry');
Sentry.init({ dsn: '___PUBLIC_DSN___' });
}
```
Expand Down
48 changes: 28 additions & 20 deletions src/wizard/ionic/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ public class MainActivity extends BridgeActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
add(SentryCapacitor.class);
}});
// Capacitor 3
registerPlugin(SentryCapacitor.class);

// Capacitor 2
// this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
// add(SentryCapacitor.class);
// }});
}
}
```
Expand All @@ -52,13 +56,17 @@ import com.getcapacitor.Plugin
import io.sentry.capacitor.SentryCapacitor

class MainActivity : BridgeActivity() {
fun onCreate(savedInstanceState: Bundle?) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Initializes the Bridge
this.init(
savedInstanceState,
listOf<Class<out Plugin>>(SentryCapacitor::class.java)
)
// Capacitor 3
registerPlugin(SentryCapacitor::class.java)

// Capacitor 2
// this.init(
// savedInstanceState,
// listOf<Class<out Plugin>>(SentryCapacitor::class.java)
// )
}
}
```
Expand All @@ -68,24 +76,24 @@ class MainActivity : BridgeActivity() {
You must initialize the Sentry SDK as early as you can:

```javascript
import * as Sentry from "@sentry/capacitor";
// The example is using Angular, Import "@sentry/vue" or "@sentry/react" when using a Sibling different than Angular.
import * as SentrySibling from "@sentry/angular";
import * as Sentry from '@sentry/capacitor';
// The example is using Angular, Import '@sentry/vue' or '@sentry/react' when using a Sibling different than Angular.
import * as SentrySibling from '@sentry/angular';
// For automatic instrumentation (highly recommended)
import { BrowserTracing } from "@sentry/tracing";
import { BrowserTracing } from '@sentry/tracing';

Sentry.init(
{
dsn: "___PUBLIC_DSN___",
dsn: '___PUBLIC_DSN___',
// To set your release and dist versions
release: "my-project-name@" + process.env.npm_package_version,
dist: "1",
release: 'my-project-name@' + process.env.npm_package_version,
dist: '1',
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
tracesSampleRate: 1.0,
integrations: [
new BrowserTracing({
tracingOrigins: ["localhost", "https://yourserver.io/api"],
tracingOrigins: ['localhost', 'https://yourserver.io/api'],
}),
]
},
Expand Down Expand Up @@ -113,22 +121,22 @@ Additionally for Angular, you will also need to alter NgModule (same code doesn'
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";
import * as Sentry from '@sentry/capacitor';

Sentry.captureException("Test Captured Exception");
Sentry.captureException('Test Captured Exception');
```

You can also throw an error anywhere in your application:

```javascript
// Must be thrown after Sentry.init is called to be captured.
throw new Error(`Test Thrown Error`);
throw new Error('Test Thrown Error');
```

Or trigger a native crash:

```javascript
import * as Sentry from "@sentry/capacitor";
import * as Sentry from '@sentry/capacitor';

Sentry.nativeCrash();
```