Skip to content

Commit 21465bc

Browse files
fix(profiling): Add actual activeThreadId to Profiles (#3338)
1 parent 3737f85 commit 21465bc

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Add actual `activeThreadId` to Profiles ([#3338](https://github.com/getsentry/sentry-react-native/pull/3338))
8+
39
## 5.11.1
410

511
### Fixes

src/js/profiling/convertHermesProfile.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { parseHermesStackFrameFunctionName } from './hermes';
88
import { MAX_PROFILE_DURATION_MS } from './integration';
99
import type { RawThreadCpuProfile } from './types';
1010

11+
const PLACEHOLDER_THREAD_ID_STRING = '0';
1112
const MS_TO_NS = 1e6;
1213
const MAX_PROFILE_DURATION_NS = MAX_PROFILE_DURATION_MS * MS_TO_NS;
1314
const ANONYMOUS_FUNCTION_NAME = 'anonymous';
@@ -61,12 +62,14 @@ export function convertToSentryProfile(hermesProfile: Hermes.Profile): RawThread
6162
priority: JS_THREAD_PRIORITY,
6263
};
6364
}
65+
const active_thread_id = Object.keys(thread_metadata)[0] || PLACEHOLDER_THREAD_ID_STRING;
6466

6567
return {
6668
samples,
6769
frames,
6870
stacks,
6971
thread_metadata,
72+
active_thread_id,
7073
};
7174
}
7275

src/js/profiling/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import type { ThreadCpuProfile } from '@sentry/types';
22

33
export interface RawThreadCpuProfile extends ThreadCpuProfile {
44
profile_id?: string;
5+
active_thread_id: string;
56
}

src/js/profiling/utils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { forEachEnvelopeItem, logger } from '@sentry/utils';
33

44
import type { RawThreadCpuProfile } from './types';
55

6-
const ACTIVE_THREAD_ID_STRING = '0';
7-
86
/**
97
*
108
*/
@@ -163,7 +161,7 @@ function createProfilePayload(
163161
name: transaction,
164162
id: event_id,
165163
trace_id: trace_id || '',
166-
active_thread_id: ACTIVE_THREAD_ID_STRING,
164+
active_thread_id: cpuProfile.active_thread_id,
167165
},
168166
};
169167

test/profiling/convertHermesProfile.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { ThreadCpuProfile, ThreadCpuSample } from '@sentry/types';
1+
import type { ThreadCpuSample } from '@sentry/types';
22

33
import { convertToSentryProfile, mapSamples } from '../../src/js/profiling/convertHermesProfile';
44
import type * as Hermes from '../../src/js/profiling/hermes';
5+
import type { RawThreadCpuProfile } from '../../src/js/profiling/types';
56

67
describe('convert hermes profile to sentry profile', () => {
78
it('simple test profile', async () => {
@@ -79,7 +80,7 @@ describe('convert hermes profile to sentry profile', () => {
7980
},
8081
},
8182
};
82-
const expectedSentryProfile: ThreadCpuProfile = {
83+
const expectedSentryProfile: RawThreadCpuProfile = {
8384
frames: [
8485
{
8586
colno: undefined,
@@ -135,6 +136,7 @@ describe('convert hermes profile to sentry profile', () => {
135136
priority: 1,
136137
},
137138
},
139+
active_thread_id: '14509472',
138140
};
139141
expect(convertToSentryProfile(hermesProfile)).toStrictEqual(expectedSentryProfile);
140142
});

0 commit comments

Comments
 (0)