Skip to content

Commit eb07ba3

Browse files
sharifhhantonis
andauthored
Support New Hermes Runtime Access Pattern (#5051)
* Update sentry_utils.rb * Update RNSentry.mm * Update RNSentry.podspec * lint clang and add changelog * PR review comments * Update CHANGELOG.md --------- Co-authored-by: Antonis Lilis <[email protected]>
1 parent e06c7cf commit eb07ba3

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

CHANGELOG.md

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

1111
### Features
1212

13+
- Support for React Native 0.81 ([#5051](https://github.com/getsentry/sentry-react-native/pull/5051))
14+
15+
- Support New Hermes Runtime Access Pattern ([#5051](https://github.com/getsentry/sentry-react-native/pull/5051))
16+
1317
- Support Metro 0.83 ([#5035](https://github.com/getsentry/sentry-react-native/pull/5035))
1418

1519
### Dependencies

packages/core/RNSentry.podspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ rn_package = parse_rn_package_json()
66
rn_version = get_rn_version(rn_package)
77
is_hermes_default = is_hermes_default(rn_version)
88
is_profiling_supported = is_profiling_supported(rn_version)
9+
is_new_hermes_runtime = is_new_hermes_runtime(rn_version)
910

1011
# Use different Folly configuration for RN 0.80.0+
1112
if should_use_folly_flags(rn_version)
@@ -21,7 +22,8 @@ is_new_arch_enabled = ENV["RCT_NEW_ARCH_ENABLED"] == "1"
2122
is_using_hermes = (ENV['USE_HERMES'] == nil && is_hermes_default) || ENV['USE_HERMES'] == '1'
2223
new_arch_enabled_flag = (is_new_arch_enabled ? folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED" : "")
2324
sentry_profiling_supported_flag = (is_profiling_supported ? " -DSENTRY_PROFILING_SUPPORTED=1" : "")
24-
other_cflags = "$(inherited)" + new_arch_enabled_flag + sentry_profiling_supported_flag
25+
new_hermes_runtime_flag = (is_new_hermes_runtime ? " -DNEW_HERMES_RUNTIME" : "")
26+
other_cflags = "$(inherited)" + new_arch_enabled_flag + sentry_profiling_supported_flag + new_hermes_runtime_flag
2527

2628
Pod::Spec.new do |s|
2729
s.name = 'RNSentry'

packages/core/ios/RNSentry.mm

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,15 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys
832832
{
833833
#if SENTRY_PROFILING_ENABLED
834834
try {
835+
# ifdef NEW_HERMES_RUNTIME
836+
auto *hermesAPI = facebook::jsi::castInterface<facebook::hermes::IHermesRootAPI>(
837+
facebook::hermes::makeHermesRootAPI());
838+
if (hermesAPI) {
839+
hermesAPI->enableSamplingProfiler();
840+
}
841+
# else
835842
facebook::hermes::HermesRuntime::enableSamplingProfiler();
843+
# endif
836844
if (nativeProfileTraceId == nil && nativeProfileStartTime == 0 && platformProfilers) {
837845
# if SENTRY_TARGET_PROFILING_SUPPORTED
838846
nativeProfileTraceId = [RNSentryId newId];
@@ -892,10 +900,19 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys
892900
nativeProfileTraceId = nil;
893901
nativeProfileStartTime = 0;
894902

895-
facebook::hermes::HermesRuntime::disableSamplingProfiler();
896903
std::stringstream ss;
904+
# ifdef NEW_HERMES_RUNTIME
905+
auto *hermesAPI = facebook::jsi::castInterface<facebook::hermes::IHermesRootAPI>(
906+
facebook::hermes::makeHermesRootAPI());
907+
if (hermesAPI) {
908+
hermesAPI->disableSamplingProfiler();
909+
hermesAPI->dumpSampledTraceToStream(ss);
910+
}
911+
# else
912+
facebook::hermes::HermesRuntime::disableSamplingProfiler();
897913
// Before RN 0.69 Hermes used llvh::raw_ostream (profiling is supported for 0.69 and newer)
898914
facebook::hermes::HermesRuntime::dumpSampledTraceToStream(ss);
915+
# endif
899916

900917
std::string s = ss.str();
901918
NSString *data = [NSString stringWithCString:s.c_str()

packages/core/scripts/sentry_utils.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ def is_profiling_supported(rn_version)
3636
def should_use_folly_flags(rn_version)
3737
return (rn_version[:major] == 0 && rn_version[:minor] < 80)
3838
end
39+
40+
def is_new_hermes_runtime(rn_version)
41+
return (rn_version[:major] >= 1 || (rn_version[:major] == 0 && rn_version[:minor] >= 81))
42+
end

0 commit comments

Comments
 (0)