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

feat: Prepare for Android alpha + refactor the SDK to be used in conjunction with @sentry/angular #35

Merged
merged 11 commits into from
Jun 2, 2021
27 changes: 27 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"editor.formatOnType": true,
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.rulers": [
120
],
"editor.tabSize": 2,
"files.autoSave": "onWindowChange",
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"search.exclude": {
"**/node_modules/": true,
"**/build/": true,
"**/dist/": true
},
"typescript.tsdk": "./node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"[json]": {
"editor.formatOnType": false,
"editor.formatOnPaste": false,
"editor.formatOnSave": false
},
"react-native-tools.projectRoot": "./sample"
}
32 changes: 5 additions & 27 deletions android/src/main/java/io/sentry/capacitor/SentryCapacitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ public void startWithOptions(final PluginCall capOptions) {
SentryAndroid.init(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side note: bump the Android SDK to the latest GA, 5.0.0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, after this PR I'll make one to bump Android and another to bump JS

this.getContext(),
options -> {
if (capOptions.getData().has("debug") && capOptions.getBoolean("debug")) {
options.setDebug(true);
logger.setLevel(Level.INFO);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually have DEBUG by default. User can lower it if it's too noisy, but out of the box we give as much information as we can

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.setLevel(Level.INFO); is only within the SentryCapacitor.java, its not the Android SDK logger, so its fine

}

String dsn = capOptions.getString("dsn") != null ? capOptions.getString("dsn") : "";
logger.info(String.format("Starting with DSN: '%s'", dsn));
options.setDsn(dsn);

if (capOptions.getData().has("debug")) {
options.setDebug(capOptions.getBoolean("debug"));
}

if (capOptions.getData().has("environment") && capOptions.getString("environment") != null) {
options.setEnvironment(capOptions.getString("environment"));
}
Expand Down Expand Up @@ -145,29 +146,6 @@ public void startWithOptions(final PluginCall capOptions) {
capOptions.resolve(resp);
}

@PluginMethod
public void setLogLevel(PluginCall call) {
int level = call.getInt("level", 2);
try {
logger.setLevel(this.logLevel(level));
} catch (Exception ex) {
ex.printStackTrace();
}
}

private Level logLevel(int level) {
switch (level) {
case 1:
return Level.SEVERE;
case 2:
return Level.INFO;
case 3:
return Level.ALL;
default:
return Level.OFF;
}
}

@PluginMethod
public void setUser(PluginCall call) {
Sentry.configureScope(scope -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its a sample so it does not matter but are we calling an HTTP endpoint instead of HTTPS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I had to add this to get the capacitor dev server to work



<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
"appId": "io.ionic.starter",
"appName": "ionic-angular",
"bundledWebRuntime": false,
"cordova": {},
"includePlugins": [
"../../"
],
"npmClient": "npm",
"webDir": "www",
"plugins": {
"SplashScreen": {
"launchShowDuration": 0
}
},
"cordova": {}
"webDir": "www"
}
7 changes: 5 additions & 2 deletions example/ionic-angular/capacitor.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
"appId": "io.ionic.starter",
"appName": "ionic-angular",
"bundledWebRuntime": false,
"cordova": {},
"includePlugins": [
"../../"
],
"npmClient": "npm",
"webDir": "www",
"plugins": {
"SplashScreen": {
"launchShowDuration": 0
}
},
"cordova": {}
"webDir": "www"
}
28 changes: 14 additions & 14 deletions example/ionic-angular/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
{
"name": "ionic-angular",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/common": "~10.0.0",
"@angular/core": "~10.0.0",
Expand All @@ -24,12 +12,14 @@
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.0.0",
"@ionic/angular": "^5.0.0",
"@sentry/capacitor": "file:../../",
"@sentry/angular": "5.27.3",
"@sentry/capacitor": "file:../..",
"@sentry/tracing": "5.27.3",
"rxjs": "~6.5.5",
"tslib": "^2.0.0",
"zone.js": "~0.10.3"
},
"description": "An Ionic project",
"devDependencies": {
"@angular-devkit/build-angular": "~0.1000.0",
"@angular/cli": "~10.0.5",
Expand All @@ -54,5 +44,15 @@
"tslint": "~6.1.0",
"typescript": "~3.9.5"
},
"description": "An Ionic project"
"name": "ionic-angular",
"private": true,
"scripts": {
"build": "ng build",
"e2e": "ng e2e",
"lint": "ng lint",
"ng": "ng",
"start": "ng serve",
"test": "ng test"
},
"version": "0.0.1"
}
52 changes: 31 additions & 21 deletions example/ionic-angular/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NgModule } from '@angular/core';
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

Expand All @@ -7,30 +7,35 @@ import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

import * as Sentry from '@sentry/capacitor';
import { init as sentryAngularInit, createErrorHandler } from '@sentry/angular';
import { Integrations } from '@sentry/tracing';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

// ATTENTION: Change the DSN below with your own to see the events in Sentry. Get one at sentry.io
Sentry.init({
dsn:
'https://[email protected]/5522756',
// An array of strings or regexps that'll be used to ignore specific errors based on their type/message
ignoreErrors: [/MiddleEarth_\d\d/, 'RangeError'],
// Debug mode with valuable initialization/lifecycle information
debug: true,
// Whether SDK should be enabled or not
enabled: true,
integrations: [new Integrations.BrowserTracing()],
// A release identifier
release: '1537345109360',
// An environment identifier
environment: 'staging',
// We recommend adjusting this value in production, or using tracesSampler
// for finer control
tracesSampleRate: 1.0,
});
Sentry.init(
{
dsn:
'https://[email protected]/5522756',
// An array of strings or regexps that'll be used to ignore specific errors based on their type/message
ignoreErrors: [/MiddleEarth_\d\d/, 'RangeError'],
// Debug mode with valuable initialization/lifecycle information
debug: true,
// Whether SDK should be enabled or not
enabled: true,
integrations: [new Integrations.BrowserTracing()],
// A release identifier
release: '1.0.0',
dist: '1.0.0.1',
// An environment identifier
environment: 'staging',
// We recommend adjusting this value in production, or using tracesSampler
// for finer control
tracesSampleRate: 1.0,
},
sentryAngularInit,
);

@NgModule({
declarations: [AppComponent],
Expand All @@ -39,8 +44,13 @@ Sentry.init({
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
/* Provide the @sentry/angular error handler */
{
provide: ErrorHandler,
useValue: createErrorHandler(),
},
],
bootstrap: [AppComponent]
bootstrap: [AppComponent],
})
export class AppModule {}
15 changes: 11 additions & 4 deletions example/ionic-angular/src/app/tab3/tab3.page.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<ion-header [translucent]="true">
<ion-toolbar>
<ion-title>
Tab 3
</ion-title>
<ion-title> Crashes </ion-title>
</ion-toolbar>
</ion-header>

<ion-content [fullscreen]="true">
<ion-header collapse="condense">
<ion-toolbar>
<ion-title size="large">Tab 3</ion-title>
<ion-title size="large">Crashes</ion-title>
</ion-toolbar>
</ion-header>

<section class="button-container">
<label>
Native Crash
<ion-button (click)="nativeCrash()"
>Crash</ion-button
>
</label>

</section>
</ion-content>
8 changes: 6 additions & 2 deletions example/ionic-angular/src/app/tab3/tab3.page.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Component } from '@angular/core';

import * as Sentry from '@sentry/capacitor';

@Component({
selector: 'app-tab3',
templateUrl: 'tab3.page.html',
styleUrls: ['tab3.page.scss']
styleUrls: ['tab3.page.scss'],
})
export class Tab3Page {

constructor() {}

public nativeCrash(): void {
Sentry.nativeCrash();
}
}
9 changes: 7 additions & 2 deletions example/ionic-angular/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
"lib": [
"es2018",
"dom"
]
],
"paths": {
"@sentry/capacitor": [
"../../"
]
}
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
}
Loading