Skip to content

Commit e65bf4e

Browse files
fix(integrations): No screenshots when the SDK is disabled (#3333)
1 parent 69931fa commit e65bf4e

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
- Change log output to show what paths are considered when collecting modules ([#3316](https://github.com/getsentry/sentry-react-native/pull/3316))
5858
- `Sentry.wrap` doesn't enforce any keys on the wrapped component props ([#3332](https://github.com/getsentry/sentry-react-native/pull/3332))
5959
- Ignore defaults when warning about duplicate definition of trace propagation targets ([#3327](https://github.com/getsentry/sentry-react-native/pull/3327))
60+
- Screenshots are not taken when the SDK is disabled ([#3333](https://github.com/getsentry/sentry-react-native/pull/3333))
6061
- Use deprecated `ReactNativeTracingOptions.tracingOrigins` if set in the options ([#3331](https://github.com/getsentry/sentry-react-native/pull/3331))
6162

6263
### Dependencies

src/js/client.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { dateTimestampInSeconds, logger, SentryError } from '@sentry/utils';
1616
import { Alert } from 'react-native';
1717

1818
import { createIntegration } from './integrations/factory';
19-
import { Screenshot } from './integrations/screenshot';
2019
import { defaultSdkInfo } from './integrations/sdkinfo';
2120
import type { ReactNativeClientOptions } from './options';
2221
import { ReactNativeTracing } from './tracing';
@@ -52,9 +51,7 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
5251
* @inheritDoc
5352
*/
5453
public eventFromException(exception: unknown, hint: EventHint = {}): PromiseLike<Event> {
55-
return Screenshot.attachScreenshotToEventHint(hint, this._options).then(hintWithScreenshot =>
56-
eventFromException(this._options.stackParser, exception, hintWithScreenshot, this._options.attachStacktrace),
57-
);
54+
return eventFromException(this._options.stackParser, exception, hint, this._options.attachStacktrace);
5855
}
5956

6057
/**

src/js/integrations/screenshot.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { EventHint, Integration } from '@sentry/types';
1+
import type { Event, EventHint, EventProcessor, Integration } from '@sentry/types';
22
import { resolvedSyncPromise } from '@sentry/utils';
33

4+
import type { Screenshot as ScreenshotAttachment } from '../wrapper';
45
import { NATIVE } from '../wrapper';
56

67
/** Adds screenshots to error events */
@@ -17,6 +18,8 @@ export class Screenshot implements Integration {
1718

1819
/**
1920
* If enabled attaches a screenshot to the event hint.
21+
*
22+
* @deprecated Screenshots are now added in global event processor.
2023
*/
2124
public static attachScreenshotToEventHint(
2225
hint: EventHint,
@@ -37,6 +40,19 @@ export class Screenshot implements Integration {
3740
/**
3841
* @inheritDoc
3942
*/
40-
// eslint-disable-next-line @typescript-eslint/no-empty-function
41-
public setupOnce(): void {}
43+
public setupOnce(addGlobalEventProcessor: (e: EventProcessor) => void): void {
44+
addGlobalEventProcessor(async (event: Event, hint: EventHint) => {
45+
const hasException = event.exception && event.exception.values && event.exception.values.length > 0;
46+
if (!hasException) {
47+
return event;
48+
}
49+
50+
const screenshots: ScreenshotAttachment[] | null = await NATIVE.captureScreenshot();
51+
if (screenshots && screenshots.length > 0) {
52+
hint.attachments = [...screenshots, ...(hint?.attachments || [])];
53+
}
54+
55+
return event;
56+
});
57+
}
4258
}

0 commit comments

Comments
 (0)