Skip to content

Commit

Permalink
fix(profiling): Add actual activeThreadId to Profiles (#3338)
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich authored Oct 11, 2023
1 parent 3737f85 commit 21465bc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

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

## 5.11.1

### Fixes
Expand Down
3 changes: 3 additions & 0 deletions src/js/profiling/convertHermesProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { parseHermesStackFrameFunctionName } from './hermes';
import { MAX_PROFILE_DURATION_MS } from './integration';
import type { RawThreadCpuProfile } from './types';

const PLACEHOLDER_THREAD_ID_STRING = '0';
const MS_TO_NS = 1e6;
const MAX_PROFILE_DURATION_NS = MAX_PROFILE_DURATION_MS * MS_TO_NS;
const ANONYMOUS_FUNCTION_NAME = 'anonymous';
Expand Down Expand Up @@ -61,12 +62,14 @@ export function convertToSentryProfile(hermesProfile: Hermes.Profile): RawThread
priority: JS_THREAD_PRIORITY,
};
}
const active_thread_id = Object.keys(thread_metadata)[0] || PLACEHOLDER_THREAD_ID_STRING;

return {
samples,
frames,
stacks,
thread_metadata,
active_thread_id,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/js/profiling/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import type { ThreadCpuProfile } from '@sentry/types';

export interface RawThreadCpuProfile extends ThreadCpuProfile {
profile_id?: string;
active_thread_id: string;
}
4 changes: 1 addition & 3 deletions src/js/profiling/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { forEachEnvelopeItem, logger } from '@sentry/utils';

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

const ACTIVE_THREAD_ID_STRING = '0';

/**
*
*/
Expand Down Expand Up @@ -163,7 +161,7 @@ function createProfilePayload(
name: transaction,
id: event_id,
trace_id: trace_id || '',
active_thread_id: ACTIVE_THREAD_ID_STRING,
active_thread_id: cpuProfile.active_thread_id,
},
};

Expand Down
6 changes: 4 additions & 2 deletions test/profiling/convertHermesProfile.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { ThreadCpuProfile, ThreadCpuSample } from '@sentry/types';
import type { ThreadCpuSample } from '@sentry/types';

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

describe('convert hermes profile to sentry profile', () => {
it('simple test profile', async () => {
Expand Down Expand Up @@ -79,7 +80,7 @@ describe('convert hermes profile to sentry profile', () => {
},
},
};
const expectedSentryProfile: ThreadCpuProfile = {
const expectedSentryProfile: RawThreadCpuProfile = {
frames: [
{
colno: undefined,
Expand Down Expand Up @@ -135,6 +136,7 @@ describe('convert hermes profile to sentry profile', () => {
priority: 1,
},
},
active_thread_id: '14509472',
};
expect(convertToSentryProfile(hermesProfile)).toStrictEqual(expectedSentryProfile);
});
Expand Down

0 comments on commit 21465bc

Please # to comment.