Skip to content

Commit

Permalink
Feat: Support for Sentry Replay (#281)
Browse files Browse the repository at this point in the history
* Bump Sentry Javascript

* update changelog

* refactor wrapper, refactor android bridge

* add utf8toBytes code

* update tests

* Add changes to iOS

* Add changelog and update yarn.lock

* Update changelog

* Ignore java files from prettier, PR cleanup

* Nit

* Update android/build.gradle
  • Loading branch information
lucas-zimerman committed Jan 10, 2023
1 parent 9b434ea commit d8c2d02
Show file tree
Hide file tree
Showing 21 changed files with 548 additions and 316 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ captures/

# yalc
yalc.lock

android/gradle/wrapper/gradle-wrapper.properties
example/ionic-angular/android/capacitor.settings.gradle
example/ionic-angular/android/app/capacitor.build.gradle
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
dist
coverage
*.java
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

### Features

- Support for Sentry Replay ([#281](https://github.com/getsentry/sentry-capacitor/pull/281))
- Add sibling check ([#248](https://github.com/getsentry/sentry-capacitor/pull/248))

### Fixes

- Removed JCenter reference ([#281](https://github.com/getsentry/sentry-capacitor/pull/281))
- Avoid duplicating Breadcrumbs on Android ([#254](https://github.com/getsentry/sentry-capacitor/pull/254))

### Dependencies

- Bump Sentry JavaScript SDK to `7.24.2` ([#277](https://github.com/getsentry/sentry-capacitor/pull/277))
- [changelog](https://github.com/getsentry/sentry-javascript/releases/tag/7.24.2)
- [diff](https://github.com/getsentry/sentry-javascript/compare/7.13.0...7.24.2)
- Bump Sentry JavaScript SDK to `7.25.0` ([#281](https://github.com/getsentry/sentry-capacitor/pull/281))
- [changelog](https://github.com/getsentry/sentry-javascript/releases/tag/7.25.0)
- [diff](https://github.com/getsentry/sentry-javascript/compare/7.13.0...7.25.0)
- Bump Sentry iOS SDK to `7.30.2` ([#259](https://github.com/getsentry/sentry-capacitor/pull/259))
- [changelog](https://github.com/getsentry/sentry-cocoa/releases/tag/7.30.2)
- [diff](https://github.com/getsentry/sentry-cocoa/compare/7.23.0...7.30.2)
Expand Down
5 changes: 2 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ext {
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
Expand Down Expand Up @@ -44,15 +44,14 @@ android {

repositories {
google()
jcenter()
mavenCentral()
}


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':capacitor-android')
implementation 'io.sentry:sentry-android:6.4.3'
implementation 'io.sentry:sentry-android:6.11.0'
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
Expand Down
62 changes: 30 additions & 32 deletions android/src/main/java/io/sentry/capacitor/SentryCapacitor.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package io.sentry.capacitor;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.util.Log;
import com.getcapacitor.JSArray;
import com.getcapacitor.JSObject;
import com.getcapacitor.NativePlugin;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.NativePlugin;

import io.sentry.Breadcrumb;
import io.sentry.HubAdapter;
import io.sentry.Integration;
import io.sentry.Sentry;
import io.sentry.SentryLevel;
import io.sentry.SentryEvent;
import io.sentry.SentryLevel;
import io.sentry.UncaughtExceptionHandlerIntegration;
import io.sentry.android.core.AnrIntegration;
import io.sentry.android.core.NdkIntegration;
import io.sentry.android.core.SentryAndroid;
import io.sentry.protocol.SdkVersion;
import io.sentry.protocol.SentryPackage;
import io.sentry.protocol.User;

import java.io.File;
import java.io.FileOutputStream;
import java.io.UnsupportedEncodingException;
Expand All @@ -28,18 +30,14 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.UUID;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.util.Log;

@NativePlugin
public class SentryCapacitor extends Plugin {

final static Logger logger = Logger.getLogger("capacitor-sentry");
static final Logger logger = Logger.getLogger("capacitor-sentry");
private Context context;
private static PackageInfo packageInfo;

Expand Down Expand Up @@ -204,7 +202,12 @@ public void fetchNativeRelease(PluginCall call) {
@PluginMethod
public void captureEnvelope(PluginCall call) {
try {
String envelope = call.getString("envelope");
JSArray rawIntegers = call.getArray("envelope");
byte[] bytes = new byte[rawIntegers.length()];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) rawIntegers.getInt(i);
}

final String outboxPath = HubAdapter.getInstance().getOptions().getOutboxPath();

if (outboxPath == null || outboxPath.isEmpty()) {
Expand All @@ -213,22 +216,17 @@ public void captureEnvelope(PluginCall call) {
return;
}

final File installation = new File(outboxPath, UUID.randomUUID().toString());
final File installation = new File(outboxPath, UUID.randomUUID().toString());

try (FileOutputStream out = new FileOutputStream(installation)) {
out.write(envelope.getBytes(Charset.forName("UTF-8")));
out.write(bytes);
logger.info("Successfully captured envelope.");

JSObject resp = new JSObject();
resp.put("value", envelope);
call.resolve(resp);
} catch (Exception e) {
logger.info("Error writing envelope.");
call.reject(String.valueOf(e));
return;
}
}
catch (Exception e) {
} catch (Exception e) {
logger.info("Error reading envelope.");
call.reject(String.valueOf(e));
return;
Expand Down Expand Up @@ -342,19 +340,19 @@ public void setTag(PluginCall call) {
public void setEventOriginTag(SentryEvent event) {
SdkVersion sdk = event.getSdk();
if (sdk != null) {
switch (sdk.getName()) {
// If the event is from capacitor js, it gets set there and we do not handle it here.
case "sentry.native":
setEventEnvironmentTag(event, "android", "native");
break;
case "sentry.java.android":
setEventEnvironmentTag(event, "android", "java");
break;
default:
break;
}
switch (sdk.getName()) {
// If the event is from capacitor js, it gets set there and we do not handle it here.
case "sentry.native":
setEventEnvironmentTag(event, "android", "native");
break;
case "sentry.java.android":
setEventEnvironmentTag(event, "android", "java");
break;
default:
break;
}
}
}
}

private void setEventEnvironmentTag(SentryEvent event, String origin, String environment) {
event.setTag("event.origin", origin);
Expand All @@ -380,5 +378,5 @@ public void addPackages(SentryEvent event, SdkVersion sdk) {

event.setSdk(eventSdk);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,5 @@ public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Initializes the Bridge
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
add(SentryCapacitor.class);
}});
}
}
4 changes: 2 additions & 2 deletions example/ionic-angular/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {

repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
Expand All @@ -20,7 +20,7 @@ apply from: "variables.gradle"
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
2 changes: 1 addition & 1 deletion example/ionic-angular/android/variables.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ ext {
junitVersion = '4.12'
androidxJunitVersion = '1.1.1'
androidxEspressoCoreVersion = '3.2.0'
cordovaAndroidVersion = '7.0.0'
cordovaAndroidVersion = '10.0.0'
}
11 changes: 6 additions & 5 deletions example/ionic-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
"@angular/platform-browser": "~13.3.0",
"@angular/platform-browser-dynamic": "~13.3.0",
"@angular/router": "~13.3.0",
"@capacitor/android": "3.0.1",
"@capacitor/core": "3.0.1",
"@capacitor/ios": "3.0.1",
"@capacitor/android": "4.0.0",
"@capacitor/core": "4.0.0",
"@capacitor/ios": "4.0.0",
"@ionic-native/core": "^5.0.0",
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.0.0",
"@ionic/angular": "^5.0.0",
"@sentry/angular": "7.24.2",
"@sentry/angular": "7.25.0",
"@sentry/capacitor": "file:.yalc/@sentry/capacitor",
"@sentry/replay": "7.25.0",
"rxjs": "~6.5.5",
"tslib": "^2.0.0",
"zone.js": "~0.11.4"
Expand All @@ -27,7 +28,7 @@
"@angular/compiler": "~13.3.0",
"@angular/compiler-cli": "~13.3.0",
"@angular/language-service": "~13.3.0",
"@capacitor/cli": "3.0.1",
"@capacitor/cli": "3.9.0",
"@ionic/angular-toolkit": "^2.3.0",
"@ionic/cli": "^6.16.3",
"@types/jasmine": "~3.6.0",
Expand Down
9 changes: 8 additions & 1 deletion example/ionic-angular/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Integrations } from '@sentry/tracing';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { Replay } from "@sentry/replay";

// ATTENTION: Change the DSN below with your own to see the events in Sentry. Get one at sentry.io
Sentry.init(
Expand All @@ -23,7 +24,13 @@ Sentry.init(
// Whether SDK should be enabled or not
enabled: true,
// Use the tracing integration to see traces and add performance monitoring
integrations: [new Integrations.BrowserTracing()],
integrations: [
new Integrations.BrowserTracing(),
new Replay({
maskAllText: false,
blockAllMedia: true,
}),
],
// A release identifier
release: '1.0.0',
// A dist identifier
Expand Down

0 comments on commit d8c2d02

Please sign in to comment.