Skip to content

Commit 19ec12a

Browse files
committed
fix: improving integration
1 parent 5dc56bc commit 19ec12a

File tree

13 files changed

+755
-379
lines changed

13 files changed

+755
-379
lines changed

plugin/platforms/ios/src/NSSentry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010

1111
@property (class, nonatomic, assign, readonly) SentryScreenFrames *currentScreenFrames;
1212
@property (class, nullable, nonatomic, readonly) SentryAppStartMeasurement *appStartMeasurement;
13+
@property (class, nonatomic, assign) BOOL appStartMeasurementHybridSDKMode;
14+
@property (class, nonatomic, assign) BOOL framesTrackingMeasurementHybridSDKMode;
1315

1416
@end

plugin/platforms/ios/src/NSSentry.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
@implementation NSSentrySDK
55

6+
+ (void)captureEnvelope:(SentryEnvelope *)envelope
7+
{
8+
return [PrivateSentrySDKOnly captureEnvelope:envelope];
9+
}
10+
+ (void)storeEnvelope:(SentryEnvelope *)envelope
11+
{
12+
return [PrivateSentrySDKOnly storeEnvelope:envelope];
13+
}
614
+ (nullable SentryEnvelope *)envelopeWithData:(NSData *)data
715
{
816
return [PrivateSentrySDKOnly envelopeWithData:data];
@@ -27,5 +35,12 @@ + (BOOL)isFramesTrackingRunning
2735
{
2836
return [PrivateSentrySDKOnly isFramesTrackingRunning];
2937
}
30-
38+
+ (void)setAppStartMeasurementHybridSDKMode:(BOOL)appStartMeasurementHybridSDKMode
39+
{
40+
[PrivateSentrySDKOnly setAppStartMeasurementHybridSDKMode:appStartMeasurementHybridSDKMode];
41+
}
42+
+ (void)setFramesTrackingMeasurementHybridSDKMode:(BOOL)framesTrackingMeasurementHybridSDKMode
43+
{
44+
[PrivateSentrySDKOnly setFramesTrackingMeasurementHybridSDKMode:framesTrackingMeasurementHybridSDKMode];
45+
}
3146
@end

src/client.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ export class NativescriptClient extends BaseClient<NativescriptClientOptions> {
105105
this._sendEnvelope(envelope);
106106
}
107107

108+
/**
109+
* @inheritDoc
110+
*/
111+
// sendEvent(event: Event, hint = {}) {
112+
// if (this._dsn) {
113+
// if (NATIVE.sendEvent) {
114+
// NATIVE.sendEvent(event, hint);
115+
// } else {
116+
// super.sendEvent(event, hint);
117+
// }
118+
// }
119+
// }
120+
108121
/**
109122
* @inheritdoc
110123
*/

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ export {
1616
captureException,
1717
captureEvent,
1818
captureMessage,
19-
configureScope,
2019
getHubFromCarrier,
2120
getCurrentHub,
2221
Hub,
2322
Scope,
2423
setContext,
2524
setExtra,
2625
setExtras,
26+
withScope,
27+
configureScope,
2728
setTag,
2829
setTags,
2930
setUser,
30-
startTransaction,
31-
withScope,
31+
startTransaction
3232
} from '@sentry/core';
3333

3434
// We need to import it so we patch the hub with global functions

src/integrations/devicecontext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class DeviceContext implements Integration {
2525
}
2626

2727
try {
28+
console.log('about to fetchNativeDeviceContexts');
2829
const contexts = await NATIVE.fetchNativeDeviceContexts();
2930

3031
const context = contexts['context'] as Contexts ?? {};

src/integrations/nativescripterrorhandlers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export class NativescriptErrorHandlers implements Integration {
9393
handlingFatal = false;
9494

9595
private async globalHander(error: any, isFatal?: boolean) {
96+
console.log('globalHander', error, isFatal);
9697
// We want to handle fatals, but only in production mode.
9798
const shouldHandleFatal = isFatal && !__DEV__;
9899
if (shouldHandleFatal) {

src/scope.ts

Lines changed: 93 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,109 @@
1-
import { Scope } from '@sentry/hub';
1+
import { Scope } from '@sentry/core';
22
import { Attachment, Breadcrumb, User } from '@sentry/types';
33

44
import { NATIVE } from './wrapper';
55

66
/**
77
* Extends the scope methods to set scope on the Native SDKs
88
*/
9-
export class NativescriptScope extends Scope {
10-
/**
11-
* @inheritDoc
12-
*/
13-
public setUser(user: User | null): this {
14-
NATIVE.setUser(user);
15-
return super.setUser(user);
16-
}
179

18-
/**
19-
* @inheritDoc
20-
*/
21-
public setTag(key: string, value: string): this {
22-
NATIVE.setTag(key, value);
23-
return super.setTag(key, value);
24-
}
10+
const methods = ['addBreadcrumb', 'addAttachment'];
2511

26-
/**
27-
* @inheritDoc
28-
*/
29-
public setTags(tags: { [key: string]: string }): this {
30-
// As native only has setTag, we just loop through each tag key.
31-
Object.keys(tags).forEach((key) => {
32-
NATIVE.setTag(key, tags[key]);
33-
});
34-
return super.setTags(tags);
35-
}
12+
// methods.forEach(m=>{
13+
// const originalMethod =Scope.prototype[m] as Function;
14+
// Scope.prototype[m] = function(...args) {
15+
// NATIVE[m](...args);
16+
// return originalMethod.call(this, ...args);
17+
// };
18+
// });
3619

37-
/**
38-
* @inheritDoc
39-
*/
40-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
41-
public setExtras(extras: { [key: string]: any }): this {
42-
Object.keys(extras).forEach((key) => {
43-
NATIVE.setExtra(key, extras[key]);
44-
});
45-
return super.setExtras(extras);
46-
}
20+
// export class NativescriptScope extends Scope {
21+
// /**
22+
// * @inheritDoc
23+
// */
24+
// public setUser(user: User | null): this {
25+
// NATIVE.setUser(user);
26+
// return super.setUser(user);
27+
// }
4728

48-
/**
49-
* @inheritDoc
50-
*/
51-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types,@typescript-eslint/no-explicit-any
52-
public setExtra(key: string, extra: any): this {
53-
NATIVE.setExtra(key, extra);
54-
return super.setExtra(key, extra);
55-
}
29+
// /**
30+
// * @inheritDoc
31+
// */
32+
// public setTag(key: string, value: string): this {
33+
// NATIVE.setTag(key, value);
34+
// return super.setTag(key, value);
35+
// }
5636

57-
/**
58-
* @inheritDoc
59-
*/
60-
public addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): this {
61-
NATIVE.addBreadcrumb(breadcrumb);
62-
return super.addBreadcrumb(breadcrumb, maxBreadcrumbs);
63-
}
37+
// /**
38+
// * @inheritDoc
39+
// */
40+
// public setTags(tags: { [key: string]: string }): this {
41+
// // As native only has setTag, we just loop through each tag key.
42+
// Object.keys(tags).forEach((key) => {
43+
// NATIVE.setTag(key, tags[key]);
44+
// });
45+
// return super.setTags(tags);
46+
// }
6447

65-
/**
66-
* @inheritDoc
67-
*/
68-
public clearBreadcrumbs(): this {
69-
NATIVE.clearBreadcrumbs();
70-
return super.clearBreadcrumbs();
71-
}
48+
// /**
49+
// * @inheritDoc
50+
// */
51+
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
52+
// public setExtras(extras: { [key: string]: any }): this {
53+
// Object.keys(extras).forEach((key) => {
54+
// NATIVE.setExtra(key, extras[key]);
55+
// });
56+
// return super.setExtras(extras);
57+
// }
7258

73-
/**
74-
* @inheritDoc
75-
*/
76-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
77-
public setContext(key: string, context: { [key: string]: any } | null): this {
78-
NATIVE.setContext(key, context);
79-
return super.setContext(key, context);
80-
}
59+
// /**
60+
// * @inheritDoc
61+
// */
62+
// // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types,@typescript-eslint/no-explicit-any
63+
// public setExtra(key: string, extra: any): this {
64+
// NATIVE.setExtra(key, extra);
65+
// return super.setExtra(key, extra);
66+
// }
8167

82-
/**
83-
* @inheritDoc
84-
*/
85-
public addAttachment(attachment: Attachment): this {
86-
return super.addAttachment(attachment);
87-
}
68+
// /**
69+
// * @inheritDoc
70+
// */
71+
// public addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): this {
72+
// NATIVE.addBreadcrumb(breadcrumb);
73+
// return super.addBreadcrumb(breadcrumb, maxBreadcrumbs);
74+
// }
8875

89-
/**
90-
* @inheritDoc
91-
*/
92-
public clearAttachments(): this {
93-
return super.clearAttachments();
94-
}
95-
}
76+
// /**
77+
// * @inheritDoc
78+
// */
79+
// public clearBreadcrumbs(): this {
80+
// NATIVE.clearBreadcrumbs();
81+
// return super.clearBreadcrumbs();
82+
// }
83+
84+
// /**
85+
// * @inheritDoc
86+
// */
87+
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
88+
// public setContext(key: string, context: { [key: string]: any } | null): this {
89+
// NATIVE.setContext(key, context);
90+
// return this;
91+
// // return super.setContext(key, context);
92+
// }
93+
94+
// /**
95+
// * @inheritDoc
96+
// */
97+
// public addAttachment(attachment: Attachment): this {
98+
// console.log('test addAttachment', attachment);
99+
// NATIVE.addAttachment(attachment);
100+
// return super.addAttachment(attachment);
101+
// }
102+
103+
// /**
104+
// * @inheritDoc
105+
// */
106+
// public clearAttachments(): this {
107+
// return super.clearAttachments();
108+
// }
109+
// }

src/sdk.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import { Integrations, defaultStackParser, getCurrentHub, defaultIntegrations as sentryDefaultIntegrations } from '@sentry/browser';
2-
import { getIntegrationsToSetup, initAndBind, setExtra } from '@sentry/core';
3-
import { Hub, makeMain } from '@sentry/hub';
2+
import { Hub, Scope, getIntegrationsToSetup, initAndBind, makeMain, setExtra } from '@sentry/core';
43
import { RewriteFrames } from '@sentry/integrations';
5-
import { Integration, Scope, StackFrame, UserFeedback } from '@sentry/types';
6-
import { getGlobalObject, logger, stackParserFromStackParserOptions } from '@sentry/utils';
4+
import { Integration, StackFrame, UserFeedback } from '@sentry/types';
5+
import { logger, stackParserFromStackParserOptions } from '@sentry/utils';
76

8-
import { NativescriptClientOptions, NativescriptOptions, NativescriptWrapperOptions } from './options';
7+
import { NativescriptClientOptions, NativescriptOptions } from './options';
98

109
import { NativescriptClient } from './client';
11-
import { NativescriptScope } from './scope';
12-
import { DebugSymbolicator, DeviceContext, NativescriptErrorHandlers, Release } from './integrations';
10+
import { DeviceContext, NativescriptErrorHandlers, Release } from './integrations';
1311
import { EventOrigin } from './integrations/eventorigin';
12+
import { NativescriptErrorHandlersOptions } from './integrations/nativescripterrorhandlers';
1413
import { SdkInfo } from './integrations/sdkinfo';
14+
// import { NativescriptScope } from './scope';
15+
import { NativescriptTracing } from './tracing';
1516
import { makeNativescriptTransport } from './transports/native';
16-
import { NativescriptErrorHandlersOptions } from './integrations/nativescripterrorhandlers';
1717
import { makeUtf8TextEncoder } from './transports/TextEncoder';
1818
import { safeFactory, safeTracesSampler } from './utils/safe';
19-
import { NativescriptTracing } from './tracing';
19+
import { NATIVE } from './wrapper';
2020

2121
const IGNORED_DEFAULT_INTEGRATIONS = [
2222
'GlobalHandlers', // We will use the react-native internal handlers
@@ -46,9 +46,9 @@ export let rewriteFrameIntegration: {
4646
*/
4747
export function init(passedOptions: NativescriptOptions): void {
4848

49-
const NativescriptHub = new Hub(undefined, new NativescriptScope());
49+
const NativescriptHub = new Hub(undefined, new Scope());
50+
// const NativescriptHub = new Hub(undefined, new NativescriptScope());
5051
makeMain(NativescriptHub);
51-
5252
const options: NativescriptClientOptions & NativescriptOptions = {
5353
...DEFAULT_OPTIONS,
5454
...passedOptions,
@@ -111,6 +111,7 @@ export function init(passedOptions: NativescriptOptions): void {
111111
new EventOrigin(),
112112
new SdkInfo()
113113
]);
114+
console.log('test', options.enableNative);
114115
if (!!options.enableNative) {
115116
defaultIntegrations.push(new DeviceContext());
116117
}
@@ -211,7 +212,9 @@ export function captureUserFeedback(feedback: UserFeedback): void {
211212
export function withScope(callback: (scope: Scope) => void): ReturnType<Hub['withScope']> {
212213
const safeCallback = (scope: Scope): void => {
213214
try {
214-
callback(scope);
215+
NATIVE.withScope(nscope=>{
216+
callback(scope);
217+
});
215218
} catch (e) {
216219
logger.error('Error while running withScope callback', e);
217220
}

src/tracing/nstracing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class NativescriptTracing implements Integration {
147147
} = this.options;
148148

149149
this._getCurrentHub = getCurrentHub;
150-
150+
console.log('NativescriptTracing', this.options);
151151
if (enableAppStartTracking) {
152152
void this._instrumentAppStart();
153153
}

src/typings/ns.ios.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ declare class NSSentrySDK extends SentrySDK {
1818
static readonly installationID: string;
1919

2020
static readonly isFramesTrackingRunning: boolean;
21+
static appStartMeasurementHybridSDKMode: boolean;
22+
static framesTrackingMeasurementHybridSDKMode: boolean;
2123
}

0 commit comments

Comments
 (0)