@nativescript-community/sentry 2.0.8 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +88 -4
  3. package/backend.d.ts +28 -0
  4. package/backend.js +18 -3
  5. package/backend.js.map +1 -1
  6. package/client.d.ts +8 -10
  7. package/client.js +11 -18
  8. package/client.js.map +1 -1
  9. package/index.d.ts +9 -4
  10. package/index.js +11 -5
  11. package/index.js.map +1 -1
  12. package/integrations/devicecontext.js +0 -1
  13. package/integrations/devicecontext.js.map +1 -1
  14. package/integrations/eventorigin.d.ts +16 -0
  15. package/integrations/eventorigin.js +26 -0
  16. package/integrations/eventorigin.js.map +1 -0
  17. package/integrations/nativescripterrorhandlers.js +0 -22
  18. package/integrations/nativescripterrorhandlers.js.map +1 -1
  19. package/integrations/release.js +24 -14
  20. package/integrations/release.js.map +1 -1
  21. package/integrations/sdkinfo.d.ts +17 -0
  22. package/integrations/sdkinfo.js +48 -0
  23. package/integrations/sdkinfo.js.map +1 -0
  24. package/nssentry.android.d.ts +20 -8
  25. package/nssentry.android.js +264 -202
  26. package/nssentry.android.js.map +1 -1
  27. package/nssentry.d.ts +25 -2
  28. package/nssentry.ios.d.ts +22 -5
  29. package/nssentry.ios.js +176 -72
  30. package/nssentry.ios.js.map +1 -1
  31. package/package.json +10 -9
  32. package/platforms/android/buildscript.gradle +1 -2
  33. package/platforms/android/include.gradle +1 -1
  34. package/platforms/android/sentry.aar +0 -0
  35. package/platforms/ios/Podfile +1 -1
  36. package/platforms/ios/src/Info.plist +0 -0
  37. package/platforms/ios/src/NSSentry.h +11 -0
  38. package/platforms/ios/src/NSSentry.m +5 -0
  39. package/platforms/ios/src/module.modulemap +4 -0
  40. package/pnpm-lock.yaml +74 -43
  41. package/scope.d.ts +45 -0
  42. package/scope.js +72 -0
  43. package/scope.js.map +1 -0
  44. package/sdk.d.ts +9 -0
  45. package/sdk.js +46 -12
  46. package/sdk.js.map +1 -1
  47. package/tracing/index.d.ts +1 -0
  48. package/tracing/index.js +8 -0
  49. package/tracing/index.js.map +1 -0
  50. package/tracing/nstracing.d.ts +65 -0
  51. package/tracing/nstracing.js +92 -0
  52. package/tracing/nstracing.js.map +1 -0
  53. package/tracing/utils.d.ts +6 -0
  54. package/tracing/utils.js +21 -0
  55. package/tracing/utils.js.map +1 -0
  56. package/version.d.ts +1 -1
  57. package/version.js +1 -1
  58. package/version.js.map +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdkinfo.js","sourceRoot":"","sources":["../../src/integrations/sdkinfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,sCAAsC;AACtC,MAAM,OAAO,OAAO;IAApB;QAME;;WAEG;QACI,SAAI,GAAW,OAAO,CAAC,EAAE,CAAC;QAEzB,mBAAc,GAAmB,IAAI,CAAC;IAuChD,CAAC;IArCC;;OAEG;IACI,SAAS,CAAC,uBAAoD;QACnE,uBAAuB,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;;YACtC,2GAA2G;YAC3G,+FAA+F;YAC/F,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,cAAc,KAAK,IAAI,EAAE;gBAChD,IAAI;oBACF,IAAI,CAAC,cAAc,GAAG,MAAM,QAAQ,CAAC,kBAAkB,EAAE,CAAC;iBAC3D;gBAAC,OAAO,CAAC,EAAE;oBACV,qGAAqG;oBACrG,MAAM,CAAC,IAAI,CACT,sGAAsG,CACvG,CAAC;oBACF,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;iBAChB;aACF;YAED,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,YAAY,CAAC;YAChD,KAAK,CAAC,GAAG,mCACJ,OAAC,KAAK,CAAC,GAAG,mCAAI,EAAE,CAAC,KACpB,IAAI,EAAE,QAAQ,EACd,QAAQ,EAAE;oBACR,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;oBAC5C,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,EAAE,CAAC;oBACzD;wBACE,IAAI,EAAE,oCAAoC;wBAC1C,OAAO,EAAE,WAAW;qBACrB;iBACF,EACD,OAAO,EAAE,WAAW,GACrB,CAAC;YAEF,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;;AAhDD;;GAEG;AACW,UAAE,GAAW,SAAS,CAAC"}
@@ -1,17 +1,29 @@
1
- import { Event, Response } from '@sentry/types';
1
+ import { Breadcrumb, Event, Response, User } from '@sentry/types';
2
2
  import { NativescriptOptions } from './backend';
3
+ import { UserFeedback } from './nssentry';
3
4
  export declare namespace NSSentry {
4
5
  const nativeClientAvailable = true;
5
6
  const nativeTransport = true;
6
- function fetchRelease(): {
7
- id: string;
8
- version: string;
9
- build: number;
10
- };
11
7
  function sendEvent(event: Event): Promise<Response>;
8
+ function captureEnvelope(envelope: string): Promise<void>;
12
9
  function flush(timeout: number): void;
13
- function startWithDsnString(dsnString: string, options: NativescriptOptions): Promise<Response>;
14
- function setLogLevel(level: number): void;
10
+ function startWithDsnString(dsnString: string, options?: NativescriptOptions): Promise<Response>;
11
+ function fetchNativeSdkInfo(): {};
12
+ function fetchNativeRelease(): {
13
+ id: any;
14
+ version: any;
15
+ build: string;
16
+ };
17
+ function closeNativeSdk(): void;
15
18
  function crash(): void;
16
19
  function deviceContexts(): Promise<any>;
20
+ function captureUserFeedback(feedback: UserFeedback): void;
21
+ function setUser(user: User | null, otherUserKeys: any): void;
22
+ function setTag(key: string, value: string): void;
23
+ function setExtra(key: string, extra: string): void;
24
+ function addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): void;
25
+ function clearBreadcrumbs(): void;
26
+ function setContext(key: string, context: {
27
+ [key: string]: any;
28
+ } | null): void;
17
29
  }
@@ -1,35 +1,26 @@
1
1
  import { Application } from '@nativescript/core';
2
+ import { android as androidApp } from '@nativescript/core/application';
2
3
  import { Status } from '@sentry/types';
3
- import { rewriteFrameIntegration } from './sdk';
4
+ import { _processLevel } from './backend';
4
5
  import { convertNativescriptFramesToSentryFrames, parseErrorStack } from './integrations/debugsymbolicator';
6
+ import { rewriteFrameIntegration } from './sdk';
5
7
  export var NSSentry;
6
8
  (function (NSSentry) {
7
9
  NSSentry.nativeClientAvailable = true;
8
10
  NSSentry.nativeTransport = true;
9
- function fetchRelease() {
10
- const ctx = Application.android.context;
11
- const packageInfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0);
12
- return {
13
- id: packageInfo.packageName,
14
- version: packageInfo.versionName,
15
- build: packageInfo.versionCode,
16
- };
17
- }
18
- NSSentry.fetchRelease = fetchRelease;
19
11
  function eventLevel(level) {
20
12
  switch (level) {
21
13
  case 'fatal':
22
- return io.sentry.core.SentryLevel.FATAL;
14
+ return io.sentry.SentryLevel.FATAL;
23
15
  case 'warning':
24
- return io.sentry.core.SentryLevel.WARNING;
16
+ return io.sentry.SentryLevel.WARNING;
25
17
  case 'info':
26
- return io.sentry.core.SentryLevel.INFO;
27
18
  case 'log':
28
- return io.sentry.core.SentryLevel.LOG;
19
+ return io.sentry.SentryLevel.INFO;
29
20
  case 'debug':
30
- return io.sentry.core.SentryLevel.DEBUG;
21
+ return io.sentry.SentryLevel.DEBUG;
31
22
  default:
32
- return io.sentry.core.SentryLevel.ERROR;
23
+ return io.sentry.SentryLevel.ERROR;
33
24
  }
34
25
  }
35
26
  function getNativeHashMap(obj) {
@@ -69,7 +60,7 @@ export var NSSentry;
69
60
  return result;
70
61
  }
71
62
  function getUser(user) {
72
- const nUser = new io.sentry.core.protocol.User();
63
+ const nUser = new io.sentry.protocol.User();
73
64
  if (user.email) {
74
65
  nUser.setEmail(user.email);
75
66
  }
@@ -90,10 +81,10 @@ export var NSSentry;
90
81
  }
91
82
  return nUser;
92
83
  }
93
- const mJsModuleIdPattern = new RegExp('(?:^|[/\\\\])(\\d+\\.js)$').compile();
84
+ const mJsModuleIdPattern = new RegExp('(?:^|[/\\\\])(\\d+\\.js)$');
94
85
  function stackFrameToModuleId(frame) {
95
86
  if (!!frame.file) {
96
- const matcher = frame.file.match(mJsModuleIdPattern);
87
+ const matcher = mJsModuleIdPattern.exec(frame.file);
97
88
  if (matcher) {
98
89
  return matcher[1] + ':';
99
90
  }
@@ -101,7 +92,7 @@ export var NSSentry;
101
92
  return '';
102
93
  }
103
94
  function convertToNativeStacktrace(stack) {
104
- const nStackTrace = new io.sentry.core.protocol.SentryStackTrace();
95
+ const nStackTrace = new io.sentry.protocol.SentryStackTrace();
105
96
  const frames = new java.util.ArrayList();
106
97
  for (let i = 0; i < stack.length; i++) {
107
98
  const frame = stack[i];
@@ -109,7 +100,7 @@ export var NSSentry;
109
100
  const methodName = frame.methodName || frame.function || '';
110
101
  const lineNumber = frame.lineNumber || frame.lineno || 0;
111
102
  const column = frame.column || frame.colno || 0;
112
- const stackFrame = new io.sentry.core.protocol.SentryStackFrame();
103
+ const stackFrame = new io.sentry.protocol.SentryStackFrame();
113
104
  stackFrame.setModule('');
114
105
  stackFrame.setFunction(methodName.length > 0 ? methodName.split('.').pop() : methodName);
115
106
  stackFrame.setFilename(stackFrameToModuleId(frame));
@@ -125,7 +116,7 @@ export var NSSentry;
125
116
  }
126
117
  function addExceptionInterface(nEvent, type, value, stack) {
127
118
  const exceptions = nEvent.getExceptions() || new java.util.ArrayList();
128
- const nException = new io.sentry.core.protocol.SentryException();
119
+ const nException = new io.sentry.protocol.SentryException();
129
120
  nException.setType(type);
130
121
  nException.setValue(value);
131
122
  nException.setModule('');
@@ -137,158 +128,81 @@ export var NSSentry;
137
128
  }
138
129
  function sendEvent(event) {
139
130
  return new Promise((resolve) => {
140
- const nEvent = new io.sentry.core.SentryEvent();
141
- if (event.event_id) {
142
- nEvent.setEventId(new io.sentry.core.protocol.SentryId(event.event_id));
143
- }
144
- if (event.breadcrumbs) {
145
- const breadcrumbs = event.breadcrumbs;
146
- const eventBreadcrumbs = new java.util.ArrayList();
147
- for (let i = 0; i < breadcrumbs.length; i++) {
148
- const breadcrumb = breadcrumbs[i];
149
- const nBreadcumb = new io.sentry.core.Breadcrumb();
150
- if (breadcrumb.category) {
151
- nBreadcumb.setCategory(breadcrumb.category);
152
- }
153
- if (breadcrumb.type) {
154
- const typeString = breadcrumb.type.toUpperCase();
155
- try {
156
- nBreadcumb.setType(typeString);
157
- }
158
- catch (e) {
159
- // don't copy over invalid breadcrumb 'type' value
160
- }
161
- }
162
- if (breadcrumb.level) {
163
- nBreadcumb.setLevel(eventLevel(breadcrumb.level));
164
- }
165
- try {
166
- if (breadcrumb.data) {
167
- Object.keys(breadcrumb.data).forEach((k) => {
168
- const value = breadcrumb.data[k];
169
- // in case a `status_code` entry got accidentally stringified as a float
170
- if (k === 'status_code') {
171
- nBreadcumb.setData(k, value && value.endsWith('.0') ? value.replace('.0', '') : value);
172
- }
173
- else {
174
- nBreadcumb.setData(k, value);
175
- }
176
- });
177
- }
178
- }
179
- catch (e) {
180
- console.warn('Discarded breadcrumb.data since it was not an object');
181
- }
182
- if (breadcrumb.message) {
183
- nBreadcumb.setMessage(breadcrumb.message);
184
- }
185
- else {
186
- nBreadcumb.setMessage('');
187
- }
188
- eventBreadcrumbs.add(i, nBreadcumb);
189
- }
190
- if (eventBreadcrumbs.size() > 0) {
191
- nEvent.setBreadcrumbs(eventBreadcrumbs);
192
- }
193
- }
194
- if (event.message) {
195
- const nMsg = new io.sentry.core.protocol.Message();
196
- nMsg.setMessage(event.message || '');
197
- nEvent.setMessage(nMsg);
198
- }
199
- if (event.logger) {
200
- nEvent.setLogger(event.logger);
201
- }
202
- if (event.user) {
203
- nEvent.setUser(getUser(event.user));
204
- }
205
- if (event.extra) {
206
- Object.keys(event.extra).forEach((k) => {
207
- const value = event.extra[k];
208
- nEvent.setExtra(k, typeof value === 'string' ? value : JSON.stringify(value));
209
- });
131
+ var _a;
132
+ // Process and convert deprecated levels
133
+ event.level = event.level ? _processLevel(event.level) : undefined;
134
+ const header = {
135
+ event_id: event.event_id,
136
+ sdk: event.sdk,
137
+ };
138
+ const payload = Object.assign(Object.assign({}, event), { message: {
139
+ message: event.message,
140
+ } });
141
+ const headerString = JSON.stringify(header);
142
+ const payloadString = JSON.stringify(payload);
143
+ const length = payloadString.length;
144
+ // try {
145
+ // // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
146
+ // length = await RNSentry.getStringBytesLength(payloadString);
147
+ // } catch {
148
+ // // The native call failed, we do nothing, we have payload.length as a fallback
149
+ // }
150
+ const item = {
151
+ content_type: 'application/json',
152
+ length,
153
+ type: (_a = payload.type) !== null && _a !== void 0 ? _a : 'event',
154
+ };
155
+ const itemString = JSON.stringify(item);
156
+ const envelopeString = `${headerString}\n${itemString}\n${payloadString}`;
157
+ captureEnvelope(envelopeString);
158
+ if (sentryOptions.flushSendEvent === true) {
159
+ io.sentry.Sentry.flush(0);
210
160
  }
211
- if (event.fingerprint) {
212
- const fingerprint = event.fingerprint;
213
- const print = new java.util.ArrayList();
214
- for (let i = 0; i < fingerprint.length; ++i) {
215
- print.add(fingerprint[i]);
216
- }
217
- nEvent.setFingerprints(print);
218
- }
219
- if (event.tags) {
220
- Object.keys(event.tags).forEach((k) => {
221
- const value = event.tags[k];
222
- nEvent.setTag(k, value || 'INVALID_TAG');
223
- });
224
- }
225
- if (event.exception) {
226
- const exceptionValues = event.exception.values;
227
- const exception = exceptionValues[0];
228
- if (exception.stacktrace) {
229
- const stacktrace = exception.stacktrace;
230
- const frames = stacktrace.frames;
231
- if (exception.value) {
232
- addExceptionInterface(nEvent, exception.type, exception.value, frames);
233
- }
234
- else {
235
- // We use type/type here since this indicates an Unhandled Promise Rejection
236
- // https://github.com/getsentry/react-native-sentry/issues/353
237
- addExceptionInterface(nEvent, exception.type, exception.type, frames);
238
- }
239
- }
240
- }
241
- if (event.environment) {
242
- nEvent.setEnvironment(event.environment);
243
- }
244
- if (event.platform) {
245
- nEvent.setPlatform(event.platform);
246
- }
247
- if (event.release) {
248
- nEvent.setRelease(event.release);
249
- }
250
- if (event.dist) {
251
- nEvent.setDist(event.dist);
252
- }
253
- if (event.level) {
254
- nEvent.setLevel(eventLevel(event.level));
255
- }
256
- if (event.contexts) {
257
- Object.keys(event.contexts).forEach((k) => {
258
- // const value = event.contexts[k];
259
- // const context = new io.sentry.core.protocol.Contexts();
260
- // nEvent.setTag(k, value || 'INVALID_TAG');
261
- });
262
- }
263
- if (event.sdk) {
264
- const sdk = event.sdk;
265
- const nSdk = new io.sentry.core.protocol.SdkVersion();
266
- nSdk.setName(sdk.name);
267
- nSdk.setVersion(sdk.version);
268
- if (sdk.integrations) {
269
- const integrations = sdk.integrations;
270
- for (let i = 0; i < integrations.length; ++i) {
271
- nSdk.addIntegration(integrations[i]);
272
- }
273
- }
274
- nEvent.setSdk(nSdk);
275
- }
276
- const id = io.sentry.core.Sentry.captureEvent(nEvent);
277
- // io.sentry.core.Sentry.flush(0);
278
- resolve({ status: Status.Success, id });
161
+ resolve({ status: Status.Success });
279
162
  }).catch((err) => {
280
163
  console.error('error sending sentry event', err, err.stack);
281
164
  return Promise.reject(err);
282
165
  });
283
166
  }
284
167
  NSSentry.sendEvent = sendEvent;
168
+ async function captureEnvelope(envelope) {
169
+ const installation = new java.io.File(nSentryOptions.getOutboxPath(), java.util.UUID.randomUUID().toString());
170
+ try {
171
+ const out = new java.io.FileOutputStream(installation);
172
+ out.write(new java.lang.String(envelope).getBytes(java.nio.charset.Charset.forName('UTF-8')));
173
+ }
174
+ catch (err) {
175
+ console.error('captureEnvelope error', err);
176
+ }
177
+ }
178
+ NSSentry.captureEnvelope = captureEnvelope;
285
179
  function flush(timeout) {
286
- console.log('native flush', timeout);
287
- io.sentry.core.Sentry.flush(timeout);
180
+ io.sentry.Sentry.flush(timeout);
288
181
  }
289
182
  NSSentry.flush = flush;
290
183
  let initialized = false;
291
- function startWithDsnString(dsnString, options) {
184
+ let sentryOptions;
185
+ let nSentryOptions;
186
+ function addPackages(event, sdk) {
187
+ const eventSdk = event.getSdk();
188
+ if (eventSdk != null && eventSdk.getName() === 'sentry.javascript.react-native' && sdk != null) {
189
+ const sentryPackages = sdk.getPackages();
190
+ if (sentryPackages != null) {
191
+ for (let index = 0; index < sentryPackages.size(); index++) {
192
+ const sentryPackage = sentryPackages.get(index);
193
+ eventSdk.addPackage(sentryPackage.getName(), sentryPackage.getVersion());
194
+ }
195
+ }
196
+ const integrations = sdk.getIntegrations();
197
+ if (integrations != null) {
198
+ for (let index = 0; index < integrations.size(); index++) {
199
+ eventSdk.addIntegration(integrations.get(index));
200
+ }
201
+ }
202
+ event.setSdk(eventSdk);
203
+ }
204
+ }
205
+ function startWithDsnString(dsnString, options = {}) {
292
206
  return new Promise((resolve, reject) => {
293
207
  if (initialized) {
294
208
  console.info('Already started, use existing client', dsnString);
@@ -296,16 +210,18 @@ export var NSSentry;
296
210
  return;
297
211
  }
298
212
  try {
299
- io.sentry.android.core.SentryAndroid.init(Application.android.context, new io.sentry.core.Sentry.OptionsConfiguration({
213
+ io.sentry.android.core.SentryAndroid.init(Application.android.context, new io.sentry.Sentry.OptionsConfiguration({
300
214
  configure(config) {
301
- config.setLogger(new io.sentry.core.SystemOutLogger());
302
- // config.setDiagnosticLevel(io.sentry.core.SentryLevel.DEBUG);
303
- // io.sentry.core.Sentry.setLevel(io.sentry.core.SentryLevel.DEBUG);
215
+ // config.setLogger(new io.sentry.SystemOutLogger());
216
+ // config.setDiagnosticLevel(io.sentry.SentryLevel.DEBUG);
217
+ io.sentry.Sentry.setLevel(io.sentry.SentryLevel.DEBUG);
304
218
  config.setDsn(dsnString);
305
- config.setEnvironment('javascript');
306
219
  if (!!options.environment) {
307
220
  config.setEnvironment(options.environment);
308
221
  }
222
+ else {
223
+ config.setEnvironment('javascript');
224
+ }
309
225
  if (!!options.debug) {
310
226
  config.setDebug(options.debug);
311
227
  }
@@ -318,20 +234,37 @@ export var NSSentry;
318
234
  if (options.enableAutoSessionTracking !== undefined) {
319
235
  config.setEnableSessionTracking(options.enableAutoSessionTracking);
320
236
  }
321
- config.setEnableNdk(true);
237
+ if (options.sessionTrackingIntervalMillis !== undefined) {
238
+ config.setSessionTrackingIntervalMillis(options.sessionTrackingIntervalMillis);
239
+ }
240
+ if (options.enableNdkScopeSync !== undefined) {
241
+ config.setEnableScopeSync(options.enableNdkScopeSync);
242
+ }
243
+ if (options.attachStacktrace !== undefined) {
244
+ config.setAttachStacktrace(options.attachStacktrace);
245
+ }
246
+ if (options.attachThreads !== undefined) {
247
+ // JS use top level stacktraces and android attaches Threads which hides them so
248
+ // by default we hide.
249
+ config.setAttachThreads(options.attachThreads);
250
+ }
251
+ if (options.sendDefaultPii !== undefined) {
252
+ config.setSendDefaultPii(options.sendDefaultPii);
253
+ }
254
+ // config.setEnableNdk(true);
322
255
  const integrations = config.getIntegrations();
323
256
  const size = integrations.size();
324
257
  if (options.enableNativeCrashHandling === false) {
325
258
  for (let index = size - 1; index >= 0; index--) {
326
259
  const inte = integrations.get(index);
327
- if (inte instanceof io.sentry.core.UncaughtExceptionHandlerIntegration ||
260
+ if (inte instanceof io.sentry.UncaughtExceptionHandlerIntegration ||
328
261
  inte instanceof io.sentry.android.core.AnrIntegration ||
329
262
  inte instanceof io.sentry.android.core.NdkIntegration) {
330
263
  integrations.remove(index);
331
264
  }
332
265
  }
333
266
  }
334
- config.setBeforeSend(new io.sentry.core.SentryOptions.BeforeSendCallback({
267
+ config.setBeforeSend(new io.sentry.SentryOptions.BeforeSendCallback({
335
268
  execute(event, hint) {
336
269
  if (options.beforeSend) {
337
270
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
@@ -346,27 +279,39 @@ export var NSSentry;
346
279
  try {
347
280
  const ex = event.getExceptions().get(0);
348
281
  if (ex && ex.getType() === 'NativeScriptException') {
349
- const privateMethod = io.sentry.core.SentryEvent.class.getDeclaredMethod('getThrowable', null);
350
- privateMethod.setAccessible(true);
351
- const returnValue = privateMethod.invoke(event, null);
352
- if (returnValue instanceof io.sentry.core.exception.ExceptionMechanismException) {
353
- const throwable = returnValue.getThrowable();
354
- if (throwable instanceof com.tns.NativeScriptException) {
355
- const jsStackTrace = throwable.getIncomingStackTrace();
356
- if (jsStackTrace) {
357
- const stack = parseErrorStack({ stack: jsStackTrace });
358
- const convertedFrames = convertNativescriptFramesToSentryFrames(stack);
359
- convertedFrames.forEach((frame) => rewriteFrameIntegration._iteratee(frame));
360
- addExceptionInterface(event, 'Error', throwable.getMessage(), convertedFrames.reverse());
361
- }
282
+ let mechanism = event.getThrowable && event.getThrowable();
283
+ if (!mechanism) {
284
+ const privateMethod = io.sentry.SentryEvent.class.getDeclaredMethod('getThrowable', null);
285
+ privateMethod.setAccessible(true);
286
+ mechanism = privateMethod.invoke(event, null);
287
+ }
288
+ let throwable;
289
+ if (mechanism instanceof io.sentry.exception.ExceptionMechanismException) {
290
+ throwable = mechanism.getThrowable();
291
+ }
292
+ else if (mechanism instanceof com.tns.NativeScriptException) {
293
+ throwable = mechanism;
294
+ }
295
+ if (throwable) {
296
+ const jsStackTrace = (throwable).getIncomingStackTrace();
297
+ if (jsStackTrace) {
298
+ const stack = parseErrorStack({ stack: jsStackTrace });
299
+ const convertedFrames = convertNativescriptFramesToSentryFrames(stack);
300
+ convertedFrames.forEach((frame) => rewriteFrameIntegration._iteratee(frame));
301
+ addExceptionInterface(event, 'Error', throwable.getMessage(), convertedFrames.reverse());
362
302
  }
363
303
  }
364
304
  }
365
305
  }
366
306
  catch (e) { }
307
+ event.setTag('event.origin', 'android');
308
+ event.setTag('event.environment', 'nativescript');
309
+ addPackages(event, config.getSdkVersion());
367
310
  return event;
368
311
  },
369
312
  }));
313
+ nSentryOptions = config;
314
+ sentryOptions = options;
370
315
  },
371
316
  }));
372
317
  initialized = true;
@@ -380,30 +325,47 @@ export var NSSentry;
380
325
  });
381
326
  }
382
327
  NSSentry.startWithDsnString = startWithDsnString;
383
- function setLogLevel(level) {
384
- switch (level) {
385
- case 1:
386
- io.sentry.core.Sentry.setLevel(null);
387
- break;
388
- case 2:
389
- io.sentry.core.Sentry.setLevel(io.sentry.core.SentryLevel.ERROR);
390
- break;
391
- case 3:
392
- io.sentry.core.Sentry.setLevel(io.sentry.core.SentryLevel.DEBUG);
393
- break;
394
- case 4:
395
- io.sentry.core.Sentry.setLevel(io.sentry.core.SentryLevel.LOG);
396
- break;
397
- }
328
+ // export function setLogLevel(level: number) {
329
+ // switch (level) {
330
+ // case 1:
331
+ // io.sentry.Sentry.setLevel(null);
332
+ // break;
333
+ // case 2:
334
+ // io.sentry.Sentry.setLevel(io.sentry.SentryLevel.ERROR);
335
+ // break;
336
+ // case 3:
337
+ // io.sentry.Sentry.setLevel(io.sentry.SentryLevel.DEBUG);
338
+ // break;
339
+ // case 4:
340
+ // io.sentry.Sentry.setLevel(io.sentry.SentryLevel.INFO);
341
+ // break;
342
+ // }
343
+ // }
344
+ function fetchNativeSdkInfo() {
345
+ return {};
346
+ }
347
+ NSSentry.fetchNativeSdkInfo = fetchNativeSdkInfo;
348
+ function fetchNativeRelease() {
349
+ const context = androidApp.context;
350
+ const packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
351
+ return {
352
+ 'id': packageInfo.packageName,
353
+ 'version': packageInfo.versionName,
354
+ 'build': packageInfo.versionCode + ''
355
+ };
356
+ }
357
+ NSSentry.fetchNativeRelease = fetchNativeRelease;
358
+ function closeNativeSdk() {
359
+ io.sentry.Sentry.close();
398
360
  }
399
- NSSentry.setLogLevel = setLogLevel;
361
+ NSSentry.closeNativeSdk = closeNativeSdk;
400
362
  function crash() {
401
363
  throw new java.lang.RuntimeException('TEST - Sentry Client Crash');
402
364
  }
403
365
  NSSentry.crash = crash;
404
366
  function deviceContexts() {
405
367
  return new Promise((resolve) => {
406
- const nEvent = new io.sentry.core.SentryEvent();
368
+ const nEvent = new io.sentry.SentryEvent();
407
369
  const params = {};
408
370
  const it = nEvent.getContexts().entrySet().iterator();
409
371
  let value, pair, key;
@@ -417,5 +379,105 @@ export var NSSentry;
417
379
  });
418
380
  }
419
381
  NSSentry.deviceContexts = deviceContexts;
382
+ function captureUserFeedback(feedback) {
383
+ const userFeedback = new io.sentry.UserFeedback(new io.sentry.protocol.SentryId(feedback.eventId));
384
+ if (feedback.comments) {
385
+ userFeedback.setComments(feedback.comments);
386
+ }
387
+ if (feedback.email) {
388
+ userFeedback.setEmail(feedback.email);
389
+ }
390
+ if (feedback.name) {
391
+ userFeedback.setName(feedback.name);
392
+ }
393
+ io.sentry.Sentry.captureUserFeedback(userFeedback);
394
+ }
395
+ NSSentry.captureUserFeedback = captureUserFeedback;
396
+ function setUser(user, otherUserKeys) {
397
+ io.sentry.Sentry.configureScope(new io.sentry.ScopeCallback({
398
+ run(scope) {
399
+ if (user == null && otherUserKeys == null) {
400
+ scope.setUser(null);
401
+ }
402
+ else {
403
+ const userInstance = new io.sentry.protocol.User();
404
+ if (user) {
405
+ if (user.email) {
406
+ userInstance.setEmail(user.email);
407
+ }
408
+ if (user.id) {
409
+ userInstance.setId(user.id);
410
+ }
411
+ if (user.username) {
412
+ userInstance.setUsername(user.username);
413
+ }
414
+ if (user.ip_address) {
415
+ userInstance.setIpAddress(user.ip_address);
416
+ }
417
+ }
418
+ if (otherUserKeys) {
419
+ userInstance.setOthers(getNativeHashMap(otherUserKeys));
420
+ }
421
+ scope.setUser(userInstance);
422
+ }
423
+ }
424
+ }));
425
+ }
426
+ NSSentry.setUser = setUser;
427
+ function setTag(key, value) {
428
+ io.sentry.Sentry.configureScope(new io.sentry.ScopeCallback({
429
+ run(scope) {
430
+ scope.setTag(key, value);
431
+ }
432
+ }));
433
+ }
434
+ NSSentry.setTag = setTag;
435
+ function setExtra(key, extra) {
436
+ io.sentry.Sentry.configureScope(new io.sentry.ScopeCallback({
437
+ run(scope) {
438
+ scope.setExtra(key, extra);
439
+ }
440
+ }));
441
+ }
442
+ NSSentry.setExtra = setExtra;
443
+ function addBreadcrumb(breadcrumb, maxBreadcrumbs) {
444
+ io.sentry.Sentry.configureScope(new io.sentry.ScopeCallback({
445
+ run(scope) {
446
+ const breadcrumbInstance = new io.sentry.Breadcrumb();
447
+ if (breadcrumb.message) {
448
+ breadcrumbInstance.setMessage(breadcrumb.message);
449
+ }
450
+ if (breadcrumb.type) {
451
+ breadcrumbInstance.setType(breadcrumb.type);
452
+ }
453
+ if (breadcrumb.category) {
454
+ breadcrumbInstance.setCategory(breadcrumb.category);
455
+ }
456
+ if (breadcrumb.level) {
457
+ breadcrumbInstance.setLevel(eventLevel(breadcrumb.level));
458
+ }
459
+ if (breadcrumb.data) {
460
+ Object.keys(breadcrumb.data).forEach(key => {
461
+ breadcrumbInstance.setData(key, breadcrumb.data[key]);
462
+ });
463
+ }
464
+ scope.addBreadcrumb(breadcrumbInstance);
465
+ }
466
+ }));
467
+ }
468
+ NSSentry.addBreadcrumb = addBreadcrumb;
469
+ function clearBreadcrumbs() {
470
+ io.sentry.Sentry.configureScope(new io.sentry.ScopeCallback({
471
+ run(scope) {
472
+ scope.clearBreadcrumbs();
473
+ }
474
+ }));
475
+ }
476
+ NSSentry.clearBreadcrumbs = clearBreadcrumbs;
477
+ function setContext(key, context) {
478
+ // setContext not available on the Android SDK yet.
479
+ setExtra(key, context ? JSON.stringify(context) : null);
480
+ }
481
+ NSSentry.setContext = setContext;
420
482
  })(NSSentry || (NSSentry = {}));
421
483
  //# sourceMappingURL=nssentry.android.js.map