Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(macos): Only include screenshots and view hierarchy for iOS and Mac Catalyst builds #3007

Merged
merged 3 commits into from
Apr 25, 2023
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 @@ -11,6 +11,7 @@

- Allow disabling native on RNNA ([#2978](https://github.com/getsentry/sentry-react-native/pull/2978))
- iOS Autolinking for RN 0.68 and older ([#2980](https://github.com/getsentry/sentry-react-native/pull/2980))
- Only include Screenshots and View Hierarchy for iOS and Mac Catalyst builds ([#3007](https://github.com/getsentry/sentry-react-native/pull/3007))
- Breadcrumbs from Native SDKs are created with timestamps in seconds ([#2997](https://github.com/getsentry/sentry-react-native/pull/2997))
- `addBreadcrumb` converts converts non object data to `{ value: data }` ([#2997](https://github.com/getsentry/sentry-react-native/pull/2997))

Expand Down
9 changes: 9 additions & 0 deletions ios/RNSentry.mm
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ - (void)setEventEnvironmentTag:(SentryEvent *)event
RCT_EXPORT_METHOD(captureScreenshot: (RCTPromiseResolveBlock)resolve
rejecter: (RCTPromiseRejectBlock)reject)
{
#if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST
NSArray<NSData *>* rawScreenshots = [PrivateSentrySDKOnly captureScreenshots];
NSMutableArray *screenshotsArray = [NSMutableArray arrayWithCapacity:[rawScreenshots count]];

Expand All @@ -354,11 +355,15 @@ - (void)setEventEnvironmentTag:(SentryEvent *)event
}

resolve(screenshotsArray);
#else
resolve(nil);
#endif
}

RCT_EXPORT_METHOD(fetchViewHierarchy: (RCTPromiseResolveBlock)resolve
rejecter: (RCTPromiseRejectBlock)reject)
{
#if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST
NSData * rawViewHierarchy = [PrivateSentrySDKOnly captureViewHierarchy];

NSMutableArray *viewHierarchy = [NSMutableArray arrayWithCapacity:rawViewHierarchy.length];
Expand All @@ -368,8 +373,12 @@ - (void)setEventEnvironmentTag:(SentryEvent *)event
}

resolve(viewHierarchy);
#else
resolve(nil);
#endif
}


RCT_EXPORT_METHOD(setUser:(NSDictionary *)userKeys
otherUserKeys:(NSDictionary *)userDataKeys
)
Expand Down
2 changes: 1 addition & 1 deletion src/js/NativeRNSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Spec extends TurboModule {
store: boolean;
},
): Promise<boolean>;
captureScreenshot(): Promise<NativeScreenshot[]>;
captureScreenshot(): Promise<NativeScreenshot[] | undefined | null>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question, we don't set screenshots and VH for transactions, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double check and yes, only for errors.

clearBreadcrumbs(): void;
crash(): void;
closeNativeSdk(): Promise<void>;
Expand Down
11 changes: 8 additions & 3 deletions src/js/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,14 +466,19 @@ export const NATIVE: SentryNativeWrapper = {
return null;
}

let raw: NativeScreenshot[] | null | undefined;
try {
const raw = await RNSentry.captureScreenshot();
raw = await RNSentry.captureScreenshot();
} catch (e) {
logger.warn('Failed to capture screenshot', e);
}

if (raw) {
return raw.map((item: NativeScreenshot) => ({
...item,
data: new Uint8Array(item.data),
}));
} catch (e) {
logger.warn('Failed to capture screenshot', e);
} else {
return null;
}
},
Expand Down