Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Report as app context what's the current screen during the error #3339

Merged
merged 12 commits into from
Nov 13, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features

- Current screen is now repoted on the error's app context ([#3339](https://github.com/getsentry/sentry-react-native/pull/3339))
- Export New JS Performance API ([#3371](https://github.com/getsentry/sentry-react-native/pull/3371))

```js
Expand Down
3 changes: 3 additions & 0 deletions src/js/integrations/devicecontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export class DeviceContext implements Integration {
}
if (nativeContexts) {
event.contexts = { ...nativeContexts, ...event.contexts };
if (nativeContexts.app) {
event.contexts.app = { ...nativeContexts.app, ...event.contexts.app };
}
}

const nativeTags = native.tags;
Expand Down
5 changes: 4 additions & 1 deletion src/js/tracing/reactnativetracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ export class ReactNativeTracing implements Integration {
},
});
}

scope.setContext('app', { view_names: [context.name] });
lucas-zimerman marked this conversation as resolved.
Show resolved Hide resolved
/**
* @deprecated tag routing.route.name will be removed in the future.
*/
scope.setTag('routing.route.name', context.name);
});
}
Expand Down
41 changes: 41 additions & 0 deletions test/integrations/devicecontext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,47 @@ describe('Device Context Integration', () => {
).expectEvent.toStrictEqualMockEvent();
});

it('do not overwrite event app context', async () => {
(
await executeIntegrationWith({
nativeContexts: { app: { view_names: ['native view'] } },
mockEvent: { contexts: { app: { view_names: ['Home'] } } },
})
).expectEvent.toStrictEqualMockEvent();
});

it('merge event context app', async () => {
const { processedEvent } = await executeIntegrationWith({
nativeContexts: { contexts: { app: { native: 'value' } } },
mockEvent: { contexts: { app: { event_app: 'value' } } },
});
expect(processedEvent).toStrictEqual({
contexts: {
app: {
event_app: 'value',
native: 'value',
},
},
});
});

it('merge event context app even when event app doesnt exist', async () => {
const { processedEvent } = await executeIntegrationWith({
nativeContexts: { contexts: { app: { native: 'value' } } },
mockEvent: { contexts: { keyContext: { key: 'value' } } },
});
expect(processedEvent).toStrictEqual({
contexts: {
keyContext: {
key: 'value',
},
app: {
native: 'value',
},
},
});
});

it('merge event and native contexts', async () => {
const { processedEvent } = await executeIntegrationWith({
nativeContexts: { contexts: { duplicate: { context: 'native-value' }, native: { context: 'value' } } },
Expand Down
3 changes: 3 additions & 0 deletions test/tracing/gesturetracing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const getMockScope = () => {
setTag(_tag: unknown) {
// Placeholder
},
setContext(_context: unknown) {
// Placeholder
},
addBreadcrumb(_breadcrumb: unknown) {
// Placeholder
},
Expand Down
10 changes: 9 additions & 1 deletion test/tracing/reactnativetracing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ const getMockScope = () => {
setTag(_tag: any) {
// Placeholder
},
setContext(_context: any) {
// Placeholder
},
addBreadcrumb(_breadcrumb: any) {
// Placeholder
},
Expand Down Expand Up @@ -678,7 +681,7 @@ describe('ReactNativeTracing', () => {

describe('Routing Instrumentation', () => {
describe('_onConfirmRoute', () => {
it('Sets tag and adds breadcrumb', () => {
it('Sets context,tag and adds breadcrumb', () => {
const routing = new RoutingInstrumentation();
const integration = new ReactNativeTracing({
routingInstrumentation: routing,
Expand All @@ -687,6 +690,7 @@ describe('ReactNativeTracing', () => {
const mockScope = {
addBreadcrumb: jest.fn(),
setTag: jest.fn(),
setContext: jest.fn(),

// Not relevant to test
setSpan: () => {},
Expand Down Expand Up @@ -724,6 +728,10 @@ describe('ReactNativeTracing', () => {
};
routing.onRouteWillChange(routeContext);

expect(mockScope.setContext).toBeCalledWith('app', { view_names: [routeContext.name] });
lucas-zimerman marked this conversation as resolved.
Show resolved Hide resolved
/**
* @deprecated tag routing.route.name will be removed in the future.
*/
expect(mockScope.setTag).toBeCalledWith('routing.route.name', routeContext.name);
expect(mockScope.addBreadcrumb).toBeCalledWith({
type: 'navigation',
Expand Down
Loading