Skip to content

Commit

Permalink
Merge f446700 into f629168
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich authored Feb 5, 2024
2 parents f629168 + f446700 commit 56d9dcc
Show file tree
Hide file tree
Showing 22 changed files with 284 additions and 383 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = {
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/unbound-method': 'off',
'deprecation/deprecation': 'off',
},
},
{
Expand Down Expand Up @@ -66,6 +67,5 @@ module.exports = {
'@sentry-internal/sdk/no-nullish-coalescing': 'off',
'@sentry-internal/sdk/no-unsupported-es6-methods': 'off',
'@sentry-internal/sdk/no-class-field-initializers': 'off',
'deprecation/deprecation': 'off',
},
};
12 changes: 6 additions & 6 deletions src/js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Alert } from 'react-native';
import { createIntegration } from './integrations/factory';
import { defaultSdkInfo } from './integrations/sdkinfo';
import type { ReactNativeClientOptions } from './options';
import { ReactNativeTracing } from './tracing';
import type { ReactNativeTracing } from './tracing';
import { createUserFeedbackEnvelope, items } from './utils/envelope';
import { ignoreRequireCycleLogs } from './utils/ignorerequirecyclelogs';
import { mergeOutcomes } from './utils/outcome';
Expand Down Expand Up @@ -107,12 +107,12 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
}

/**
* Sets up the integrations
* @inheritdoc
*/
public setupIntegrations(): void {
super.setupIntegrations();
const tracing = this.getIntegration(ReactNativeTracing);
const routingName = tracing?.options.routingInstrumentation?.name;
protected _setupIntegrations(): void {
super._setupIntegrations();
const tracing = this.getIntegrationByName('ReactNativeTracing') as ReactNativeTracing;
const routingName = tracing?.options?.routingInstrumentation?.name;
if (routingName) {
this.addIntegration(createIntegration(routingName));
}
Expand Down
6 changes: 6 additions & 0 deletions src/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ export type {
} from '@sentry/types';

export {
// eslint-disable-next-line deprecation/deprecation
addGlobalEventProcessor,
addBreadcrumb,
captureException,
captureEvent,
captureMessage,
getHubFromCarrier,
// eslint-disable-next-line deprecation/deprecation
getCurrentHub,
Hub,
Scope,
Expand All @@ -27,6 +29,7 @@ export {
setTag,
setTags,
setUser,
// eslint-disable-next-line deprecation/deprecation
startTransaction,
startInactiveSpan,
startSpan,
Expand All @@ -38,6 +41,7 @@ import { _addTracingExtensions } from './tracing/addTracingExtensions';
_addTracingExtensions();

export {
// eslint-disable-next-line deprecation/deprecation
Integrations as BrowserIntegrations,
ErrorBoundary,
withErrorBoundary,
Expand All @@ -47,6 +51,7 @@ export {
withProfiler,
} from '@sentry/react';

// eslint-disable-next-line deprecation/deprecation
export { lastEventId } from '@sentry/browser';

import * as Integrations from './integrations';
Expand All @@ -66,6 +71,7 @@ export {
close,
captureUserFeedback,
withScope,
// eslint-disable-next-line deprecation/deprecation
configureScope,
} from './sdk';
export { TouchEventBoundary, withTouchEventBoundary } from './touchevents';
Expand Down
56 changes: 28 additions & 28 deletions src/js/integrations/debugsymbolicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,40 @@ export class DebugSymbolicator implements Integration {

/**
* @inheritDoc
* @deprecated
*/
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
addGlobalEventProcessor(async (event: Event, hint: EventHint) => {
const self = getCurrentHub().getIntegration(DebugSymbolicator);
public setupOnce(_addGlobalEventProcessor: (callback: EventProcessor) => void, _getCurrentHub: () => Hub): void {
// nothing to do here
}

if (!self) {
return event;
}
/**
* @inheritdoc
*/
public async processEvent(event: Event, hint: EventHint): Promise<Event> {
if (event.exception && isErrorLike(hint.originalException)) {
// originalException is ErrorLike object
const symbolicatedFrames = await this._symbolicate(
hint.originalException.stack,
getFramesToPop(hint.originalException as Error),
);
symbolicatedFrames && this._replaceExceptionFramesInEvent(event, symbolicatedFrames);
} else if (hint.syntheticException && isErrorLike(hint.syntheticException)) {
// syntheticException is Error object
const symbolicatedFrames = await this._symbolicate(
hint.syntheticException.stack,
getFramesToPop(hint.syntheticException),
);

if (event.exception && isErrorLike(hint.originalException)) {
// originalException is ErrorLike object
const symbolicatedFrames = await this._symbolicate(
hint.originalException.stack,
getFramesToPop(hint.originalException as Error),
);
if (event.exception) {
symbolicatedFrames && this._replaceExceptionFramesInEvent(event, symbolicatedFrames);
} else if (hint.syntheticException && isErrorLike(hint.syntheticException)) {
// syntheticException is Error object
const symbolicatedFrames = await this._symbolicate(
hint.syntheticException.stack,
getFramesToPop(hint.syntheticException),
);

if (event.exception) {
symbolicatedFrames && this._replaceExceptionFramesInEvent(event, symbolicatedFrames);
} else if (event.threads) {
// RN JS doesn't have threads
// syntheticException is used for Sentry.captureMessage() threads
symbolicatedFrames && this._replaceThreadFramesInEvent(event, symbolicatedFrames);
}
} else if (event.threads) {
// RN JS doesn't have threads
// syntheticException is used for Sentry.captureMessage() threads
symbolicatedFrames && this._replaceThreadFramesInEvent(event, symbolicatedFrames);
}
}

return event;
});
return event;
}

/**
Expand Down
31 changes: 20 additions & 11 deletions src/js/integrations/default.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { HttpClient } from '@sentry/integrations';
import { Integrations as BrowserReactIntegrations } from '@sentry/react';
import { httpClientIntegration } from '@sentry/integrations';
import {
breadcrumbsIntegration,
browserApiErrorsIntegration,
dedupeIntegration,
functionToStringIntegration,
globalHandlersIntegration as browserGlobalHandlersIntegration,
httpContextIntegration,
inboundFiltersIntegration,
linkedErrorsIntegration as browserLinkedErrorsIntegration,
} from '@sentry/react';
import type { Integration } from '@sentry/types';

import type { ReactNativeClientOptions } from '../options';
Expand Down Expand Up @@ -39,17 +48,17 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ
);
integrations.push(new NativeLinkedErrors());
} else {
integrations.push(new BrowserReactIntegrations.TryCatch());
integrations.push(new BrowserReactIntegrations.GlobalHandlers());
integrations.push(new BrowserReactIntegrations.LinkedErrors());
integrations.push(browserApiErrorsIntegration());
integrations.push(browserGlobalHandlersIntegration());
integrations.push(browserLinkedErrorsIntegration());
}

// @sentry/react default integrations
integrations.push(new BrowserReactIntegrations.InboundFilters());
integrations.push(new BrowserReactIntegrations.FunctionToString());
integrations.push(new BrowserReactIntegrations.Breadcrumbs());
integrations.push(new BrowserReactIntegrations.Dedupe());
integrations.push(new BrowserReactIntegrations.HttpContext());
integrations.push(inboundFiltersIntegration());
integrations.push(functionToStringIntegration());
integrations.push(breadcrumbsIntegration());
integrations.push(dedupeIntegration());
integrations.push(httpContextIntegration());
// end @sentry/react-native default integrations

integrations.push(new Release());
Expand Down Expand Up @@ -88,7 +97,7 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ
integrations.push(new ReactNativeTracing());
}
if (options.enableCaptureFailedRequests) {
integrations.push(new HttpClient());
integrations.push(httpClientIntegration());
}

if (isExpoGo()) {
Expand Down
125 changes: 63 additions & 62 deletions src/js/integrations/devicecontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,80 +21,81 @@ export class DeviceContext implements Integration {

/**
* @inheritDoc
* @deprecated
*/
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
addGlobalEventProcessor(async (event: Event) => {
const self = getCurrentHub().getIntegration(DeviceContext);
if (!self) {
return event;
}
public setupOnce(_addGlobalEventProcessor: (callback: EventProcessor) => void, _getCurrentHub: () => Hub): void {
// nothing to do here
}

let native: NativeDeviceContextsResponse | null = null;
try {
native = await NATIVE.fetchNativeDeviceContexts();
} catch (e) {
logger.log(`Failed to get device context from native: ${e}`);
}
/**
* @inheritDoc
*/
public async processEvent(event: Event): Promise<Event> {
let native: NativeDeviceContextsResponse | null = null;
try {
native = await NATIVE.fetchNativeDeviceContexts();
} catch (e) {
logger.log(`Failed to get device context from native: ${e}`);
}

if (!native) {
return event;
}
if (!native) {
return event;
}

const nativeUser = native.user;
if (!event.user && nativeUser) {
event.user = nativeUser;
}
const nativeUser = native.user;
if (!event.user && nativeUser) {
event.user = nativeUser;
}

let nativeContexts = native.contexts;
if (AppState.currentState !== 'unknown') {
nativeContexts = nativeContexts || {};
nativeContexts.app = {
...nativeContexts.app,
in_foreground: AppState.currentState === 'active',
};
}
if (nativeContexts) {
event.contexts = { ...nativeContexts, ...event.contexts };
if (nativeContexts.app) {
event.contexts.app = { ...nativeContexts.app, ...event.contexts.app };
}
let nativeContexts = native.contexts;
if (AppState.currentState !== 'unknown') {
nativeContexts = nativeContexts || {};
nativeContexts.app = {
...nativeContexts.app,
in_foreground: AppState.currentState === 'active',
};
}
if (nativeContexts) {
event.contexts = { ...nativeContexts, ...event.contexts };
if (nativeContexts.app) {
event.contexts.app = { ...nativeContexts.app, ...event.contexts.app };
}
}

const nativeTags = native.tags;
if (nativeTags) {
event.tags = { ...nativeTags, ...event.tags };
}
const nativeTags = native.tags;
if (nativeTags) {
event.tags = { ...nativeTags, ...event.tags };
}

const nativeExtra = native.extra;
if (nativeExtra) {
event.extra = { ...nativeExtra, ...event.extra };
}
const nativeExtra = native.extra;
if (nativeExtra) {
event.extra = { ...nativeExtra, ...event.extra };
}

const nativeFingerprint = native.fingerprint;
if (nativeFingerprint) {
event.fingerprint = (event.fingerprint ?? []).concat(
nativeFingerprint.filter(item => (event.fingerprint ?? []).indexOf(item) < 0),
);
}
const nativeFingerprint = native.fingerprint;
if (nativeFingerprint) {
event.fingerprint = (event.fingerprint ?? []).concat(
nativeFingerprint.filter(item => (event.fingerprint ?? []).indexOf(item) < 0),
);
}

const nativeLevel = typeof native['level'] === 'string' ? severityLevelFromString(native['level']) : undefined;
if (!event.level && nativeLevel) {
event.level = nativeLevel;
}
const nativeLevel = typeof native['level'] === 'string' ? severityLevelFromString(native['level']) : undefined;
if (!event.level && nativeLevel) {
event.level = nativeLevel;
}

const nativeEnvironment = native['environment'];
if (!event.environment && nativeEnvironment) {
event.environment = nativeEnvironment;
}
const nativeEnvironment = native['environment'];
if (!event.environment && nativeEnvironment) {
event.environment = nativeEnvironment;
}

const nativeBreadcrumbs = Array.isArray(native['breadcrumbs'])
? native['breadcrumbs'].map(breadcrumbFromObject)
: undefined;
if (nativeBreadcrumbs) {
event.breadcrumbs = nativeBreadcrumbs;
}
const nativeBreadcrumbs = Array.isArray(native['breadcrumbs'])
? native['breadcrumbs'].map(breadcrumbFromObject)
: undefined;
if (nativeBreadcrumbs) {
event.breadcrumbs = nativeBreadcrumbs;
}

return event;
});
return event;
}
}
Loading

0 comments on commit 56d9dcc

Please sign in to comment.