diff --git a/CHANGELOG.md b/CHANGELOG.md index c7fec7c654..3e22a82970 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ > make sure you follow our [migration guide](https://docs.sentry.io/platforms/react-native/migration/) first. +## Unreleased + +### Fixes + +- Populate the Hermes runtime version on JS profiles instead of sending an empty value ([#6817](https://github.com/getsentry/sentry-react-native/pull/6817)) + ## 8.29.0 ### Features diff --git a/packages/core/src/js/profiling/utils.ts b/packages/core/src/js/profiling/utils.ts index cc4154ce3c..a29ec43f9f 100644 --- a/packages/core/src/js/profiling/utils.ts +++ b/packages/core/src/js/profiling/utils.ts @@ -12,7 +12,7 @@ import type { RawThreadCpuProfile, } from './types'; -import { getDefaultEnvironment } from '../utils/environment'; +import { getDefaultEnvironment, getHermesVersion } from '../utils/environment'; import { getDebugMetadata } from './debugid'; /** @@ -95,7 +95,7 @@ export function enrichCombinedProfileWithEventContext( event_id: profile_id, runtime: { name: 'hermes', - version: '', // TODO: get hermes version + version: getHermesVersion() ?? '', }, timestamp: profilingStartTimestampNs ? new Date(profilingStartTimestampNs / 1e6).toISOString() diff --git a/packages/core/test/profiling/utils.test.ts b/packages/core/test/profiling/utils.test.ts index ab8d427e1f..de264a0331 100644 --- a/packages/core/test/profiling/utils.test.ts +++ b/packages/core/test/profiling/utils.test.ts @@ -10,7 +10,7 @@ import { enrichAndroidProfileWithEventContext, enrichCombinedProfileWithEventContext, } from '../../src/js/profiling/utils'; -import { getDefaultEnvironment } from '../../src/js/utils/environment'; +import { getDefaultEnvironment, getHermesVersion } from '../../src/js/utils/environment'; import { createMockMinimalValidAndroidProfile, createMockMinimalValidHermesProfileEvent } from './fixtures'; describe('enrichCombinedProfileWithEventContext', () => { @@ -19,6 +19,29 @@ describe('enrichCombinedProfileWithEventContext', () => { (getDebugMetadata as jest.Mock).mockReturnValue([]); }); + test('should set the hermes runtime version from getHermesVersion', () => { + // OSS Hermes reports the version it was built against, e.g. `for RN 0.76.0`, not a semver. + (getHermesVersion as jest.Mock).mockReturnValue('for RN 0.76.0'); + const profile: CombinedProfileEvent = createMockMinimalValidHermesProfileEvent(); + const event = createMockEvent(); + + const result = enrichCombinedProfileWithEventContext('profile-id', profile, event); + + expect(result).not.toBeNull(); + expect(result!.runtime).toEqual({ name: 'hermes', version: 'for RN 0.76.0' }); + }); + + test('should fall back to an empty runtime version when the hermes version is unavailable', () => { + (getHermesVersion as jest.Mock).mockReturnValue(undefined); + const profile: CombinedProfileEvent = createMockMinimalValidHermesProfileEvent(); + const event = createMockEvent(); + + const result = enrichCombinedProfileWithEventContext('profile-id', profile, event); + + expect(result).not.toBeNull(); + expect(result!.runtime).toEqual({ name: 'hermes', version: '' }); + }); + function createMockEvent(overrides?: Partial): Event { return { event_id: 'test-event-id',