Skip to content

Commit 10896ec

Browse files
Merge 102f1f1 into 81c2acb
2 parents 81c2acb + 102f1f1 commit 10896ec

File tree

5 files changed

+56
-5
lines changed

5 files changed

+56
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Send debug information with Profiles for symbolicated stack traces ([#3338](https://github.com/getsentry/sentry-react-native/pull/3338))
8+
59
### Fixes
610

711
- Add actual `activeThreadId` to Profiles ([#3338](https://github.com/getsentry/sentry-react-native/pull/3338))

src/js/profiling/hermes.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ export interface ParsedHermesStackFrame {
5858
file?: string;
5959
lineno?: number;
6060
colno?: number;
61+
in_app?: boolean;
6162
}
6263

63-
const DEFAULT_BUNDLE_NAME =
64+
export const DEFAULT_BUNDLE_NAME =
6465
Platform.OS === 'android' ? ANDROID_DEFAULT_BUNDLE_NAME : Platform.OS === 'ios' ? IOS_DEFAULT_BUNDLE_NAME : undefined;
6566
const ANONYMOUS_FUNCTION_NAME = 'anonymous';
6667

@@ -71,6 +72,9 @@ const ANONYMOUS_FUNCTION_NAME = 'anonymous';
7172
export function parseHermesJSStackFrame(frame: StackFrame): ParsedHermesStackFrame {
7273
if (frame.category !== 'JavaScript') {
7374
// Native
75+
if (frame.name === '[root]') {
76+
return { function: frame.name, in_app: false };
77+
}
7478
return { function: frame.name };
7579
}
7680

src/js/profiling/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import type { ThreadCpuProfile } from '@sentry/types';
1+
import type { ThreadCpuFrame as SentryThreadCpuFrame, ThreadCpuProfile } from '@sentry/types';
2+
3+
export interface ThreadCpuFrame extends SentryThreadCpuFrame {
4+
in_app?: boolean;
5+
}
26

37
export interface RawThreadCpuProfile extends ThreadCpuProfile {
8+
frames: ThreadCpuFrame[];
49
profile_id?: string;
510
active_thread_id: string;
611
}

src/js/profiling/utils.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { Envelope, Event, Profile } from '@sentry/types';
2-
import { forEachEnvelopeItem, logger } from '@sentry/utils';
1+
import type { DebugImage, Envelope, Event, Profile } from '@sentry/types';
2+
import { forEachEnvelopeItem, GLOBAL_OBJ, logger } from '@sentry/utils';
33

4+
import { DEFAULT_BUNDLE_NAME } from './hermes';
45
import type { RawThreadCpuProfile } from './types';
56

67
/**
@@ -136,7 +137,7 @@ function createProfilePayload(
136137
const profile: Profile = {
137138
event_id: profile_id,
138139
timestamp: new Date(start_timestamp).toISOString(),
139-
platform: 'node',
140+
platform: 'javascript',
140141
version: '1',
141142
release: release,
142143
environment: environment,
@@ -163,11 +164,47 @@ function createProfilePayload(
163164
trace_id: trace_id || '',
164165
active_thread_id: cpuProfile.active_thread_id,
165166
},
167+
debug_meta: {
168+
images: getDebugMetadata(),
169+
},
166170
};
167171

168172
return profile;
169173
}
170174

175+
/**
176+
* Returns debug meta images of the loaded bundle.
177+
*/
178+
export function getDebugMetadata(): DebugImage[] {
179+
if (!DEFAULT_BUNDLE_NAME) {
180+
return [];
181+
}
182+
183+
const debugIdMap = GLOBAL_OBJ._sentryDebugIds;
184+
if (!debugIdMap) {
185+
return [];
186+
}
187+
188+
const debugIdsKeys = Object.keys(debugIdMap);
189+
if (!debugIdsKeys.length) {
190+
return [];
191+
}
192+
193+
if (debugIdsKeys.length > 1) {
194+
logger.warn(
195+
'[Profiling] Multiple debug images found, but only one one bundle is supported. Using the first one...',
196+
);
197+
}
198+
199+
return [
200+
{
201+
code_file: DEFAULT_BUNDLE_NAME,
202+
debug_id: debugIdMap[debugIdsKeys[0]],
203+
type: 'sourcemap',
204+
},
205+
];
206+
}
207+
171208
/**
172209
* Adds items to envelope if they are not already present - mutates the envelope.
173210
* @param envelope

test/profiling/convertHermesProfile.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ describe('convert hermes profile to sentry profile', () => {
8484
frames: [
8585
{
8686
function: '[root]',
87+
in_app: false,
8788
},
8889
{
8990
colno: 33,

0 commit comments

Comments
 (0)