Skip to content

Commit c1a45af

Browse files
committed
fix: move to latest SDKs
1 parent 1145ec3 commit c1a45af

File tree

20 files changed

+1795
-836
lines changed

20 files changed

+1795
-836
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ Pods
2121
*.xcuserdatad
2222
/plugin/README.md
2323
pnpm-lock.yaml
24+
/plugin/platforms/android/sentry.aar

plugin/platforms/android/include.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ android {
77
}
88
}
99
dependencies {
10-
def sentryVersion = project.hasProperty("sentryVersion") ? project.sentryVersion : "4.2.0"
10+
def sentryVersion = project.hasProperty("sentryVersion") ? project.sentryVersion : "5.2.0"
1111
implementation "io.sentry:sentry-android:$sentryVersion"
1212
}

plugin/platforms/android/sentry.aar

-11.9 KB
Binary file not shown.

plugin/platforms/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '6.2.0'
1+
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '7.3.0'

plugin/platforms/ios/src/Info.plist

235 Bytes
Binary file not shown.

plugin/platforms/ios/src/NSSentry.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#import <Sentry/Sentry.h>
2+
3+
4+
@interface NSSentrySDK: SentrySDK
5+
6+
+ (void)captureEnvelope:(SentryEnvelope *)envelope;
7+
8+
+ (void)storeEnvelope:(SentryEnvelope *)envelope;
9+
10+
11+
@end

plugin/platforms/ios/src/NSSentry.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import "NSSentry.h"
2+
#import <Sentry/Sentry.h>
3+
4+
@implementation NSSentrySDK
5+
@end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module NSSentry {
2+
header "NSSentry.h"
3+
export *
4+
}

src/backend.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ export interface NativescriptOptions extends BrowserOptions {
3535

3636
sessionTrackingIntervalMillis?: number;
3737

38+
/** Enable scope sync from Java to NDK on Android */
39+
enableNdkScopeSync?: boolean;
40+
41+
/** When enabled, all the threads are automatically attached to all logged events on Android */
42+
attachThreads?: boolean;
43+
44+
/**
45+
* When enabled, certain personally identifiable information (PII) is added by active integrations.
46+
*
47+
* @default false
48+
* */
49+
sendDefaultPii?: boolean;
50+
3851
/** Should the native nagger alert be shown or not. */
3952
// enableNativeNagger?: boolean;
4053
/**
@@ -53,6 +66,11 @@ export interface NativescriptOptions extends BrowserOptions {
5366
sentry?: boolean;
5467
xhr?: boolean;
5568
};
69+
70+
/** Enable auto performance tracking by default. */
71+
enableAutoPerformanceTracking?: boolean;
72+
73+
flushSendEvent?: boolean;
5674
}
5775

5876
/** The Sentry Nativescript SDK Backend. */
@@ -65,9 +83,10 @@ export class NativescriptBackend extends BaseBackend<BrowserOptions> {
6583
this._browserBackend = new BrowserBackend(_options);
6684

6785
if (_options.enableNative !== false) {
68-
NSSentry.startWithDsnString(_options.dsn, _options).then(() => {
69-
NSSentry.setLogLevel(_options.debug ? 2 : 1);
70-
});
86+
NSSentry.startWithDsnString(_options.dsn, _options);
87+
// .then(() => {
88+
// // NSSentry.setLogLevel(_options.debug ? 2 : 1);
89+
// });
7190
} else {
7291
// if (__DEV__ && _options.enableNativeNagger) {
7392
// Alert.alert(
@@ -89,7 +108,7 @@ export class NativescriptBackend extends BaseBackend<BrowserOptions> {
89108

90109
const transportOptions = {
91110
...this._options.transportOptions,
92-
dsn: this._options.dsn,
111+
dsn: this._options.dsn
93112
};
94113

95114
if (this._options.transport) {
@@ -136,12 +155,11 @@ export class NativescriptBackend extends BaseBackend<BrowserOptions> {
136155
}
137156
}
138157

139-
140158
/**
141-
* Convert js severity level which has critical and log to more widely supported levels.
142-
* @param level
143-
* @returns More widely supported Severity level strings
144-
*/
159+
* Convert js severity level which has critical and log to more widely supported levels.
160+
* @param level
161+
* @returns More widely supported Severity level strings
162+
*/
145163
export function _processLevel(level: Severity): Severity {
146164
if (level === Severity.Critical) {
147165
return Severity.Fatal;

src/client.ts

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { BaseClient, Scope } from '@sentry/core';
2-
import { Event, EventHint } from '@sentry/types';
3-
import { SyncPromise } from '@sentry/utils';
42

53
import { NativescriptBackend, NativescriptOptions } from './backend';
6-
import { SDK_NAME, SDK_VERSION } from './version';
4+
import { NSSentry } from './nssentry';
75

86
/**
97
* The Sentry React Native SDK Client.
@@ -21,31 +19,20 @@ export class NativescriptClient extends BaseClient<NativescriptBackend, Nativesc
2119
}
2220

2321
/**
24-
* @inheritDoc
25-
*/
26-
protected _prepareEvent(event: Event, scope?: Scope, hint?: EventHint): SyncPromise<Event | null> {
27-
event.platform = event.platform || 'javascript';
28-
event.sdk = {
29-
...event.sdk,
30-
name: SDK_NAME,
31-
packages: [
32-
...((event.sdk && event.sdk.packages) || []),
33-
{
34-
name: 'npm:@nativescript-community/sentry',
35-
version: SDK_VERSION
36-
}
37-
],
38-
version: SDK_VERSION
39-
};
40-
41-
return super._prepareEvent(event, scope, hint) as any;
42-
}
22+
* If native client is available it will trigger a native crash.
23+
* Use this only for testing purposes.
24+
*/
25+
public nativeCrash(): void {
26+
this._getBackend().nativeCrash();
27+
}
4328

44-
/**
45-
* If native client is available it will trigger a native crash.
46-
* Use this only for testing purposes.
47-
*/
48-
public nativeCrash(): void {
49-
this._getBackend().nativeCrash();
50-
}
51-
}
29+
/**
30+
* @inheritDoc
31+
*/
32+
public close(): PromiseLike<boolean> {
33+
// As super.close() flushes queued events, we wait for that to finish before closing the native SDK.
34+
return super.close().then((result: boolean) => {
35+
return NSSentry.closeNativeSdk().then(() => result) as PromiseLike<boolean>;
36+
});
37+
}
38+
}

src/integrations/eventorigin.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { EventProcessor, Integration } from "@sentry/types";
2+
3+
/** Default EventOrigin instrumentation */
4+
export class EventOrigin implements Integration {
5+
/**
6+
* @inheritDoc
7+
*/
8+
public static id: string = "EventOrigin";
9+
10+
/**
11+
* @inheritDoc
12+
*/
13+
public name: string = EventOrigin.id;
14+
15+
/**
16+
* @inheritDoc
17+
*/
18+
public setupOnce(addGlobalEventProcessor: (e: EventProcessor) => void): void {
19+
addGlobalEventProcessor((event) => {
20+
event.tags = event.tags ?? {};
21+
22+
event.tags["event.origin"] = "javascript";
23+
event.tags["event.environment"] = "javascript";
24+
25+
return event;
26+
});
27+
}
28+
}

src/integrations/release.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,39 @@ export class Release implements Integration {
2222
if (!self) {
2323
return event;
2424
}
25+
const options = getCurrentHub().getClient()?.getOptions();
26+
/*
27+
__sentry_release and __sentry_dist is set by the user with setRelease and setDist. If this is used then this is the strongest.
28+
Otherwise we check for the release and dist in the options passed on init, as this is stronger than the release/dist from the native build.
29+
*/
30+
if (typeof event.extra?.__sentry_release === 'string') {
31+
event.release = `${event.extra.__sentry_release}`;
32+
} else if (typeof options?.release === 'string') {
33+
event.release = options.release;
34+
}
2535

36+
if (typeof event.extra?.__sentry_dist === 'string') {
37+
event.dist = `${event.extra.__sentry_dist}`;
38+
} else if (typeof options?.dist === 'string') {
39+
event.dist = options.dist;
40+
}
41+
42+
if (event.release && event.dist) {
43+
return event;
44+
}
2645
try {
27-
const release = (await NSSentry.fetchRelease()) as {
46+
const release = (await NSSentry.fetchNativeRelease()) as {
2847
build: string;
2948
id: string;
3049
version: string;
3150
};
3251
if (release) {
33-
if (!event.release) {
34-
event.release = `${release.id}-${release.version}`;
35-
}
36-
if (!event.dist) {
37-
event.dist = `${release.build}`;
38-
}
52+
event.release = `${release.id}@${release.version}+${release.build}`;
53+
event.dist = `${release.build}`;
3954
}
4055
} catch (_Oo) {
4156
// Something went wrong, we just continue
4257
}
43-
44-
// If __sentry_release or __sentry_dist it should be stronger because the user set it
45-
if (event.extra && event.extra.__sentry_release) {
46-
event.release = `${event.extra.__sentry_release}`;
47-
}
48-
if (event.extra && event.extra.__sentry_dist) {
49-
event.dist = `${event.extra.__sentry_dist}`;
50-
}
51-
5258
return event;
5359
});
5460
}

src/integrations/sdkinfo.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { EventProcessor, Integration, Package } from "@sentry/types";
2+
import { logger } from "@sentry/utils";
3+
4+
import { SDK_NAME, SDK_VERSION } from "../version";
5+
import { NSSentry } from '../nssentry';
6+
7+
/** Default SdkInfo instrumentation */
8+
export class SdkInfo implements Integration {
9+
/**
10+
* @inheritDoc
11+
*/
12+
public static id: string = "SdkInfo";
13+
14+
/**
15+
* @inheritDoc
16+
*/
17+
public name: string = SdkInfo.id;
18+
19+
private _nativeSdkInfo: Package | null = null;
20+
21+
/**
22+
* @inheritDoc
23+
*/
24+
public setupOnce(addGlobalEventProcessor: (e: EventProcessor) => void): void {
25+
addGlobalEventProcessor(async (event) => {
26+
// The native SDK info package here is only used on iOS as `beforeSend` is not called on `captureEnvelope`.
27+
// this._nativeSdkInfo should be defined a following time so this call won't always be awaited.
28+
if (global.isIOS && this._nativeSdkInfo === null) {
29+
try {
30+
this._nativeSdkInfo = await NSSentry.fetchNativeSdkInfo();
31+
} catch (e) {
32+
// If this fails, go ahead as usual as we would rather have the event be sent with a package missing.
33+
logger.warn(
34+
"[SdkInfo] Native SDK Info retrieval failed...something could be wrong with your Sentry installation:"
35+
);
36+
logger.warn(e);
37+
}
38+
}
39+
40+
event.platform = event.platform || "javascript";
41+
event.sdk = {
42+
...(event.sdk ?? {}),
43+
name: SDK_NAME,
44+
packages: [
45+
...((event.sdk && event.sdk.packages) || []),
46+
...((this._nativeSdkInfo && [this._nativeSdkInfo]) || []),
47+
{
48+
name: "npm:@nativescript-community/sentry",
49+
version: SDK_VERSION,
50+
},
51+
],
52+
version: SDK_VERSION,
53+
};
54+
55+
return event;
56+
});
57+
}
58+
}

0 commit comments

Comments
 (0)