Skip to content

Commit

Permalink
fix(frames): remove non absolute non url frame.abs_path coming from d…
Browse files Browse the repository at this point in the history
…efault stack parser (#2891)
  • Loading branch information
krystofwoldrich authored Mar 14, 2023
1 parent 8a53c0d commit 15c80ab
Show file tree
Hide file tree
Showing 4 changed files with 756 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- Remove non URL `frame.abs_path` which was causing source maps to fail ([#2891](https://github.com/getsentry/sentry-react-native/pull/2891))

### Dependencies

- Bump Cocoa SDK from v8.2.0 to v8.3.0 ([#2876](https://github.com/getsentry/sentry-react-native/pull/2876))
Expand Down
34 changes: 34 additions & 0 deletions src/js/integrations/rewriteframes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { RewriteFrames } from '@sentry/integrations';
import type { StackFrame } from '@sentry/types';

/**
* Creates React Native default rewrite frames integration
* which appends app:// to the beginning of the filename
* and removes file://, 'address at' prefixes and CodePush postfix.
*/
export function createReactNativeRewriteFrames(): RewriteFrames {
return new RewriteFrames({
iteratee: (frame: StackFrame) => {
if (frame.filename) {
frame.filename = frame.filename
.replace(/^file:\/\//, '')
.replace(/^address at /, '')
.replace(/^.*\/[^.]+(\.app|CodePush|.*(?=\/))/, '');

if (
frame.filename !== '[native code]' &&
frame.filename !== 'native'
) {
const appPrefix = 'app://';
// We always want to have a triple slash
frame.filename =
frame.filename.indexOf('/') === 0
? `${appPrefix}${frame.filename}`
: `${appPrefix}/${frame.filename}`;
}
delete frame.abs_path;
}
return frame;
},
});
}
28 changes: 3 additions & 25 deletions src/js/sdk.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { Scope } from '@sentry/core';
import { getIntegrationsToSetup, Hub, initAndBind, makeMain, setExtra } from '@sentry/core';
import { RewriteFrames } from '@sentry/integrations';
import {
defaultIntegrations as reactDefaultIntegrations,
defaultStackParser,
getCurrentHub,
makeFetchTransport,
} from '@sentry/react';
import type { Integration, StackFrame, UserFeedback } from '@sentry/types';
import type { Integration, UserFeedback } from '@sentry/types';
import { logger, stackParserFromStackParserOptions } from '@sentry/utils';
import * as React from 'react';

Expand All @@ -22,6 +21,7 @@ import {
Release,
SdkInfo,
} from './integrations';
import { createReactNativeRewriteFrames } from './integrations/rewriteframes';
import { Screenshot } from './integrations/screenshot';
import { ViewHierarchy } from './integrations/viewhierarchy';
import type { ReactNativeClientOptions, ReactNativeOptions, ReactNativeWrapperOptions } from './options';
Expand Down Expand Up @@ -107,29 +107,7 @@ export function init(passedOptions: ReactNativeOptions): void {
defaultIntegrations.push(new DebugSymbolicator());
}

defaultIntegrations.push(new RewriteFrames({
iteratee: (frame: StackFrame) => {
if (frame.filename) {
frame.filename = frame.filename
.replace(/^file:\/\//, '')
.replace(/^address at /, '')
.replace(/^.*\/[^.]+(\.app|CodePush|.*(?=\/))/, '');

if (
frame.filename !== '[native code]' &&
frame.filename !== 'native'
) {
const appPrefix = 'app://';
// We always want to have a triple slash
frame.filename =
frame.filename.indexOf('/') === 0
? `${appPrefix}${frame.filename}`
: `${appPrefix}/${frame.filename}`;
}
}
return frame;
},
}));
defaultIntegrations.push(createReactNativeRewriteFrames());
if (options.enableNative) {
defaultIntegrations.push(new DeviceContext());
}
Expand Down
Loading

0 comments on commit 15c80ab

Please sign in to comment.