Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Add `textComponentNames` option to `annotateReactComponents` for custom text components ([#6169](https://github.com/getsentry/sentry-react-native/pull/6169))
- Expose `addConsoleInstrumentationFilter` from `@sentry/core` ([#6180](https://github.com/getsentry/sentry-react-native/pull/6180))
- Expose experimental `captureSurfaceViews` option for Android Session Replay ([#6175](https://github.com/getsentry/sentry-react-native/pull/6175))
- Add OTA SDK version to native `sdk.packages` when JS bundle version differs from built-in version ([#6191](https://github.com/getsentry/sentry-react-native/pull/6191))

### Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ static void startWithOptions(
@Nullable Activity currentActivity,
@NotNull Sentry.OptionsConfiguration<SentryAndroidOptions> configuration,
@NotNull ILogger logger) {
@Nullable
String jsSdkVersion = rnOptions.hasKey("sdkVersion") ? rnOptions.getString("sdkVersion") : null;
Sentry.OptionsConfiguration<SentryAndroidOptions> defaults =
options -> updateWithReactDefaults(options, currentActivity);
options -> updateWithReactDefaults(options, currentActivity, jsSdkVersion);
Sentry.OptionsConfiguration<SentryAndroidOptions> rnConfigurationOptions =
options -> getSentryAndroidOptions(options, rnOptions, logger);
RNSentryCompositeOptionsConfiguration compositeConfiguration =
Expand Down Expand Up @@ -319,6 +321,13 @@ private static void configureAndroidProfiling(
*/
static void updateWithReactDefaults(
@NotNull SentryAndroidOptions options, @Nullable Activity currentActivity) {
updateWithReactDefaults(options, currentActivity, null);
}

static void updateWithReactDefaults(
@NotNull SentryAndroidOptions options,
@Nullable Activity currentActivity,
@Nullable String jsSdkVersion) {
@Nullable SdkVersion sdkVersion = options.getSdkVersion();
if (sdkVersion == null) {
sdkVersion = new SdkVersion(RNSentryVersion.ANDROID_SDK_NAME, BuildConfig.VERSION_NAME);
Expand All @@ -328,6 +337,10 @@ static void updateWithReactDefaults(
sdkVersion.addPackage(
RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_NAME,
RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_VERSION);
if (jsSdkVersion != null
&& !jsSdkVersion.equals(RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_VERSION)) {
sdkVersion.addPackage(RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_NAME + ":ota", jsSdkVersion);
}

options.setSentryClientName(sdkVersion.getName() + "/" + sdkVersion.getVersion());
options.setNativeSdkName(RNSentryVersion.NATIVE_SDK_NAME);
Expand Down
17 changes: 16 additions & 1 deletion packages/core/ios/RNSentryStart.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,31 @@ + (void)startWithOptions:(NSDictionary *_Nonnull)javascriptOptions
error:errorPointer];
[self updateWithReactDefaults:options];
[self updateWithReactFinals:options];
[self startWithOptions:options];
NSString *jsSdkVersion = nil;
id jsSdkVersionValue = javascriptOptions[@"sdkVersion"];
if ([jsSdkVersionValue isKindOfClass:[NSString class]]) {
jsSdkVersion = jsSdkVersionValue;
}
[self startWithOptions:options jsSdkVersion:jsSdkVersion];
}

+ (void)startWithOptions:(SentryOptions *)options NS_SWIFT_NAME(start(options:))
{
[self startWithOptions:options jsSdkVersion:nil];
}

+ (void)startWithOptions:(SentryOptions *)options jsSdkVersion:(NSString *_Nullable)jsSdkVersion
{
NSString *sdkVersion = [PrivateSentrySDKOnly getSdkVersionString];
[PrivateSentrySDKOnly setSdkName:NATIVE_SDK_NAME andVersionString:sdkVersion];
[PrivateSentrySDKOnly addSdkPackage:REACT_NATIVE_SDK_PACKAGE_NAME
version:REACT_NATIVE_SDK_PACKAGE_VERSION];

if (jsSdkVersion != nil && ![jsSdkVersion isEqualToString:REACT_NATIVE_SDK_PACKAGE_VERSION]) {
NSString *otaPackageName = [REACT_NATIVE_SDK_PACKAGE_NAME stringByAppendingString:@":ota"];
[PrivateSentrySDKOnly addSdkPackage:otaPackageName version:jsSdkVersion];
}

[SentrySDK startWithOptions:options];

#if SENTRY_TARGET_REPLAY_SUPPORTED
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/js/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { isTurboModuleEnabled } from './utils/environment';
import { convertToNormalizedObject } from './utils/normalize';
import { ReactNativeLibraries } from './utils/rnlibraries';
import { base64StringFromByteArray } from './vendor';
import { SDK_VERSION } from './version';

/**
* Returns the RNSentry module. Dynamically resolves if NativeModule or TurboModule is used.
Expand All @@ -60,6 +61,7 @@ export type NativeSdkOptions = Partial<ReactNativeClientOptions> & {
ignoreErrorsRegex?: string[] | undefined;
} & {
mobileReplayOptions: MobileReplayOptions | undefined;
sdkVersion?: string | undefined;
profilingOptions?: ProfilingOptions | undefined;
/** @deprecated Use `profilingOptions` instead. */
androidProfilingOptions?: ProfilingOptions | undefined;
Expand Down Expand Up @@ -317,6 +319,8 @@ export const NATIVE: SentryNativeWrapper = {
};
}

filteredOptions.sdkVersion = SDK_VERSION;

const nativeIsReady = await RNSentry.initNativeSdk(filteredOptions);

this.nativeIsReady = nativeIsReady;
Expand Down
17 changes: 17 additions & 0 deletions packages/core/test/wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,23 @@ describe('Tests Native Wrapper', () => {
expect(NATIVE.enableNative).toBe(true);
});

test('passes sdkVersion to native SDK', async () => {
await NATIVE.initNativeSdk({
dsn: VALID_DSN,
enableNative: true,
autoInitializeNativeSdk: true,
devServerUrl: undefined,
defaultSidecarUrl: undefined,
mobileReplayOptions: undefined,
});

expect(RNSentry.initNativeSdk).toHaveBeenCalled();
// @ts-expect-error mock value
const initParameter = RNSentry.initNativeSdk.mock.calls[0][0];
expect(initParameter).toHaveProperty('sdkVersion');
expect(typeof initParameter.sdkVersion).toBe('string');
});

test('passes attachAllThreads to native SDK', async () => {
await NATIVE.initNativeSdk({
dsn: VALID_DSN,
Expand Down
Loading