Skip to content

Commit 5f4e3eb

Browse files
committed
fix: update to latest sdk
1 parent 3db2d65 commit 5f4e3eb

23 files changed

+1995
-1384
lines changed

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@
1818
"devDependencies": {
1919
"@commitlint/cli": "^17.3.0",
2020
"@commitlint/config-conventional": "^17.3.0",
21-
"@nativescript/core": "8.4.1",
22-
"@nativescript/types-android": "8.4.0",
23-
"@nativescript/types-ios": "8.4.0",
24-
"@sentry/browser": "^7.88.0",
25-
"@sentry/core": "^7.88.0",
26-
"@sentry/hub": "^7.88.0",
27-
"@sentry/integrations": "^7.88.0",
28-
"@sentry/tracing": "^7.88.0",
29-
"@sentry/types": "^7.88.0",
30-
"@sentry/utils": "^7.88.0",
21+
"@nativescript/core": "8.6.2",
22+
"@nativescript/types-android": "8.6.1",
23+
"@nativescript/types-ios": "8.6.1",
24+
"@sentry/browser": "^7.102.1",
25+
"@sentry/core": "^7.102.1",
26+
"@sentry/hub": "^7.102.1",
27+
"@sentry/integrations": "^7.102.1",
28+
"@sentry/tracing": "^7.102.1",
29+
"@sentry/types": "^7.102.1",
30+
"@sentry/utils": "^7.102.1",
3131
"@types/node": "^18.11.11",
32-
"@typescript-eslint/eslint-plugin": "5.46.0",
33-
"@typescript-eslint/parser": "5.46.0",
34-
"eslint": "8.29.0",
35-
"husky": "^8.0.2",
36-
"lerna": "^6.1.0",
32+
"@typescript-eslint/eslint-plugin": "7.0.2",
33+
"@typescript-eslint/parser": "7.0.2",
34+
"eslint": "8.57.0",
35+
"husky": "^8.0.3",
36+
"lerna": "^6.6.2",
3737
"rimraf": "^3.0.2",
3838
"stacktrace-parser": "^0.1.10",
3939
"typescript": "~4.8.4"

plugin/platforms/ios/Podfile

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

plugin/platforms/ios/src/NSSentry.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#import <Sentry/Sentry.h>
2+
#import <Sentry/SentryEnvelope.h>
3+
#import <Sentry/SentryScreenFrames.h>
4+
#import <Sentry/SentryAppStartMeasurement.h>
25

36
@interface NSSentrySDK: SentrySDK
47
+ (void)captureEnvelope:(SentryEnvelope *)envelope;
@@ -13,4 +16,4 @@
1316
@property (class, nonatomic, assign) BOOL appStartMeasurementHybridSDKMode;
1417
@property (class, nonatomic, assign) BOOL framesTrackingMeasurementHybridSDKMode;
1518

16-
@end
19+
@end

src/breadcrumb.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { Breadcrumb, SeverityLevel } from '@sentry/types';
2+
import { severityLevelFromString } from '@sentry/utils';
3+
4+
export const DEFAULT_BREADCRUMB_LEVEL: SeverityLevel = 'info';
5+
6+
type BreadcrumbCandidate = {
7+
[K in keyof Partial<Breadcrumb>]: unknown;
8+
};
9+
10+
/**
11+
* Convert plain object to a valid Breadcrumb
12+
*/
13+
export function breadcrumbFromObject(candidate: BreadcrumbCandidate): Breadcrumb {
14+
const breadcrumb: Breadcrumb = {};
15+
16+
if (typeof candidate.type === 'string') {
17+
breadcrumb.type = candidate.type;
18+
}
19+
if (typeof candidate.level === 'string') {
20+
breadcrumb.level = severityLevelFromString(candidate.level);
21+
}
22+
if (typeof candidate.event_id === 'string') {
23+
breadcrumb.event_id = candidate.event_id;
24+
}
25+
if (typeof candidate.category === 'string') {
26+
breadcrumb.category = candidate.category;
27+
}
28+
if (typeof candidate.message === 'string') {
29+
breadcrumb.message = candidate.message;
30+
}
31+
if (typeof candidate.data === 'object' && candidate.data !== null) {
32+
breadcrumb.data = candidate.data;
33+
}
34+
if (typeof candidate.timestamp === 'string') {
35+
const timestampSeconds = Date.parse(candidate.timestamp) / 1000; // breadcrumb timestamp is in seconds
36+
if (!isNaN(timestampSeconds)) {
37+
breadcrumb.timestamp = timestampSeconds;
38+
}
39+
}
40+
41+
return breadcrumb;
42+
}

src/client.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import { ClientReportEnvelope, ClientReportItem, Envelope, Event, EventHint, Exc
66
import { SentryError, dateTimestampInSeconds, logger } from '@sentry/utils';
77

88
import { alert } from '@nativescript/core';
9+
import { createIntegration } from './integrations/factory';
910
import { defaultSdkInfo } from './integrations/sdkinfo';
1011
import { NativescriptClientOptions } from './options';
1112
import { NativeTransport } from './transports/native';
1213
import { createUserFeedbackEnvelope, items } from './utils/envelope';
1314
import { mergeOutcomes } from './utils/outcome';
1415
import { NATIVE } from './wrapper';
1516
import { Screenshot } from './integrations/screenshot';
16-
import { rewriteFrameIntegration } from './sdk';
17+
import { NativescriptTracing } from './tracing';
18+
import { rewriteFrameIntegration } from './integrations/default';
1719

1820

1921
/**
@@ -44,16 +46,6 @@ export class NativescriptClient extends BaseClient<NativescriptClientOptions> {
4446
super(options);
4547

4648
this._outcomesBuffer = [];
47-
48-
// this._browserClient = new BrowserClient({
49-
// dsn: options.dsn,
50-
// transport: options.transport,
51-
// transportOptions: options.transportOptions,
52-
// stackParser: options.stackParser,
53-
// integrations: [],
54-
// _metadata: options._metadata,
55-
// });
56-
5749
this._initNativeSdk();
5850
}
5951

@@ -153,6 +145,22 @@ export class NativescriptClient extends BaseClient<NativescriptClientOptions> {
153145
// }
154146
// }
155147

148+
/**
149+
* Sets up the integrations
150+
*/
151+
public setupIntegrations(): void {
152+
super.setupIntegrations();
153+
const tracing = this.getIntegration(NativescriptTracing);
154+
const routingName = tracing?.options.routingInstrumentation?.name;
155+
if (routingName) {
156+
this.addIntegration(createIntegration(routingName));
157+
}
158+
const enableUserInteractionTracing = tracing?.options.enableUserInteractionTracing;
159+
if (enableUserInteractionTracing) {
160+
this.addIntegration(createIntegration('ReactNativeUserInteractionTracing'));
161+
}
162+
}
163+
156164
/**
157165
* @inheritdoc
158166
*/
@@ -165,7 +173,8 @@ export class NativescriptClient extends BaseClient<NativescriptClientOptions> {
165173
}
166174

167175
let shouldClearOutcomesBuffer = true;
168-
if (this._transport && this._dsn) {
176+
if (this._isEnabled() && this._transport && this._dsn) {
177+
this.emit('beforeEnvelope', envelope);
169178
this._transport.send(envelope)
170179
.then(null, reason => {
171180
if (reason instanceof SentryError) { // SentryError is thrown by SyncPromise

src/index.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ export {
3131
startTransaction
3232
} from '@sentry/core';
3333

34-
// We need to import it so we patch the hub with global functions
35-
// aka. this has side effects
36-
import '@sentry/tracing';
37-
38-
// Add the React Native SDK's own tracing extensions, this needs to happen AFTER @sentry/tracing's
39-
import { _addTracingExtensions } from './measurements';
34+
import { _addTracingExtensions } from './tracing/addTracingExtensions';
4035
_addTracingExtensions();
4136

4237
// export {
@@ -65,16 +60,16 @@ export {
6560
} from './sdk';
6661
// export { TouchEventBoundary, withTouchEventBoundary } from './touchevents';
6762

68-
// export {
69-
// NativescriptTracing,
63+
export {
64+
NativescriptTracing,
7065
// ReactNavigationV4Instrumentation,
7166
// // eslint-disable-next-line deprecation/deprecation
7267
// ReactNavigationV5Instrumentation,
7368
// ReactNavigationInstrumentation,
7469
// NativescriptNavigationInstrumentation,
7570
// RoutingInstrumentation,
7671
// ReactNavigationTransactionContext,
77-
// } from './tracing';
72+
} from './tracing';
7873

7974
export { Integrations, SDK_NAME, SDK_VERSION };
8075

src/integrations/default.ts

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import { HttpClient, RewriteFrames } from '@sentry/integrations';
2+
// import { Integrations as BrowserReactIntegrations } from '@sentry/react';
3+
import type { Integration, StackFrame } from '@sentry/types';
4+
5+
import type { NativescriptClientOptions, NativescriptOptions } from '../options';
6+
// import { HermesProfiling } from '../profiling/integration';
7+
import { NativescriptTracing } from '../tracing';
8+
// import { isExpoGo, notWeb } from '../utils/environment';
9+
import { DeviceContext } from './devicecontext';
10+
import { EventOrigin } from './eventorigin';
11+
// import { ExpoContext } from './expocontext';
12+
// import { ModulesLoader } from './modulesloader';
13+
// import { NativeLinkedErrors } from './nativelinkederrors';
14+
import { NativescriptErrorHandlers } from './nativescripterrorhandlers';
15+
// import { ReactNativeInfo } from './reactnativeinfo';
16+
import { Release } from './release';
17+
// import { createReactNativeRewriteFrames } from './rewriteframes';
18+
import { Screenshot } from './screenshot';
19+
import { SdkInfo } from './sdkinfo';
20+
// import { Spotlight } from './spotlight';
21+
// import { ViewHierarchy } from './viewhierarchy';
22+
23+
export let rewriteFrameIntegration: {
24+
_iteratee: (frame: StackFrame) => StackFrame;
25+
};
26+
/**
27+
* Returns the default ReactNative integrations based on the current environment.
28+
*
29+
* Native integrations are only returned when native is enabled.
30+
*
31+
* Web integrations are only returned when running on web.
32+
*/
33+
export function getDefaultIntegrations(options: NativescriptClientOptions & NativescriptOptions): Integration[] {
34+
const integrations: Integration[] = [];
35+
36+
rewriteFrameIntegration = new RewriteFrames({
37+
iteratee: (frame: StackFrame) => {
38+
if (frame.platform === 'javascript' && frame.filename) {
39+
let filename = frame.filename
40+
.replace(/^file\:\/\//, '')
41+
.replace(/^address at /, '')
42+
.replace(/^.*\/[^\.]+(\.app|CodePush|.*(?=\/))/, '');
43+
44+
if (frame.filename.indexOf('[native code]') === -1) {
45+
const appPrefix = options.appPrefix ?? '~/';
46+
if (appPrefix.endsWith('//') && !appPrefix.endsWith('///')) {
47+
filename = filename.indexOf('/') === 0 ? `${appPrefix}${filename}` : `${appPrefix}/${filename}`;
48+
} else {
49+
filename = filename.indexOf('/') === 0 ? `${appPrefix}${filename.slice(1)}` : `${appPrefix}${filename}`;
50+
}
51+
}
52+
53+
frame.filename = filename;
54+
if (options.colnoOffset) {
55+
frame.colno += options.colnoOffset;
56+
}
57+
// We always want to have a tripple slash
58+
}
59+
return frame;
60+
}
61+
}) as any;
62+
63+
// if (notWeb()) {
64+
integrations.push(
65+
new NativescriptErrorHandlers(options),
66+
);
67+
// integrations.push(new NativeLinkedErrors());
68+
// } else {
69+
// integrations.push(new BrowserReactIntegrations.TryCatch());
70+
// integrations.push(new BrowserReactIntegrations.GlobalHandlers());
71+
// integrations.push(new BrowserReactIntegrations.LinkedErrors());
72+
// }
73+
74+
// @sentry/react default integrations
75+
// integrations.push(new BrowserReactIntegrations.InboundFilters());
76+
// integrations.push(new BrowserReactIntegrations.FunctionToString());
77+
// integrations.push(new BrowserReactIntegrations.Breadcrumbs());
78+
// integrations.push(new BrowserReactIntegrations.Dedupe());
79+
// integrations.push(new BrowserReactIntegrations.HttpContext());
80+
// end @sentry/react-native default integrations
81+
82+
integrations.push(new Release());
83+
integrations.push(new EventOrigin());
84+
integrations.push(new SdkInfo());
85+
// integrations.push(new ReactNativeInfo());
86+
87+
// if (__DEV__ && notWeb()) {
88+
// integrations.push(new DebugSymbolicator());
89+
// }
90+
91+
integrations.push(rewriteFrameIntegration as any);
92+
93+
if (options.enableNative) {
94+
integrations.push(new DeviceContext());
95+
// integrations.push(new ModulesLoader());
96+
if (options.attachScreenshot) {
97+
integrations.push(new Screenshot());
98+
}
99+
// if (options.attachViewHierarchy) {
100+
// integrations.push(new ViewHierarchy());
101+
// }
102+
// if (options._experiments && typeof options._experiments.profilesSampleRate === 'number') {
103+
// integrations.push(new HermesProfiling());
104+
// }
105+
}
106+
107+
// hasTracingEnabled from `@sentry/core` only check if tracesSampler or tracesSampleRate keys are present
108+
// that's different from prev imp here and might lead misconfiguration
109+
// `tracesSampleRate: undefined` should not enable tracing
110+
const hasTracingEnabled =
111+
options.enableTracing ||
112+
typeof options.tracesSampleRate === 'number' ||
113+
typeof options.tracesSampler === 'function';
114+
if (hasTracingEnabled && options.enableAutoPerformanceTracing) {
115+
integrations.push(new NativescriptTracing());
116+
}
117+
if (options.enableCaptureFailedRequests) {
118+
integrations.push(new HttpClient());
119+
}
120+
121+
// if (isExpoGo()) {
122+
// integrations.push(new ExpoContext());
123+
// }
124+
125+
// if (options.enableSpotlight) {
126+
// integrations.push(
127+
// Spotlight({
128+
// sidecarUrl: options.spotlightSidecarUrl,
129+
// }),
130+
// );
131+
// }
132+
133+
return integrations;
134+
}

0 commit comments

Comments
 (0)