Skip to content

Commit

Permalink
feat: Add spotlight option (#4023)
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich committed Aug 14, 2024
1 parent 8f05739 commit 7b891b1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Unreleased

- Add `spotlight` option ([#4023](https://github.com/getsentry/sentry-react-native/pull/4023))
- Deprecating `enableSpotlight` and `spotlightSidecarUrl`

## 5.29.0

### Features
Expand Down
2 changes: 1 addition & 1 deletion samples/expo/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ process.env.EXPO_SKIP_DURING_EXPORT !== 'true' && Sentry.init({
// replaysOnErrorSampleRate: 1.0,
replaysSessionSampleRate: 1.0,
},
enableSpotlight: true,
spotlight: true,
});

function RootLayout() {
Expand Down
2 changes: 1 addition & 1 deletion samples/react-native/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Sentry.init({
// replaysSessionSampleRate: 1.0,
replaysOnErrorSampleRate: 1.0,
},
enableSpotlight: true,
spotlight: true,
// This should be disabled when manually initializing the native SDK
// Note that options from JS are not passed to the native SDKs when initialized manually
autoInitializeNativeSdk: true,
Expand Down
9 changes: 3 additions & 6 deletions src/js/integrations/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,9 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ
integrations.push(expoContextIntegration());
}

if (options.enableSpotlight) {
integrations.push(
spotlightIntegration({
sidecarUrl: options.spotlightSidecarUrl,
}),
);
if (options.spotlight || options.enableSpotlight) {
const sidecarUrl = (typeof options.spotlight === 'string' && options.spotlight) || options.spotlightSidecarUrl;
integrations.push(spotlightIntegration({ sidecarUrl }));
}

if (
Expand Down
16 changes: 16 additions & 0 deletions src/js/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ export interface BaseReactNativeOptions {
* More details: https://spotlightjs.com/
*
* IMPORTANT: Only set this option to `true` while developing, not in production!
*
* @deprecated Use `spotlight` instead.
*/
enableSpotlight?: boolean;

Expand All @@ -178,9 +180,23 @@ export interface BaseReactNativeOptions {
* More details: https://spotlightjs.com/
*
* @default "http://localhost:8969/stream"
*
* @deprecated Use `spotlight` instead.
*/
spotlightSidecarUrl?: string;

/**
* If you use Spotlight by Sentry during development, use
* this option to forward captured Sentry events to Spotlight.
*
* Either set it to true, or provide a specific Spotlight Sidecar URL.
*
* More details: https://spotlightjs.com/
*
* IMPORTANT: Only set this option to `true` while developing, not in production!
*/
spotlight?: boolean | string;

/**
* Sets a callback which is executed before capturing screenshots. Only
* relevant if `attachScreenshot` is set to true. When false is returned
Expand Down
22 changes: 21 additions & 1 deletion test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ describe('Tests the SDK functionality', () => {
expect(actualIntegrations).toEqual(expect.not.arrayContaining([expect.objectContaining({ name: 'Spotlight' })]));
});

it('adds spotlight integration', () => {
it('adds spotlight integration with enableSpotlight', () => {
init({
enableSpotlight: true,
});
Expand All @@ -442,6 +442,26 @@ describe('Tests the SDK functionality', () => {
expect(actualIntegrations).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'Spotlight' })]));
});

it('adds spotlight integration with spotlight bool', () => {
init({
spotlight: true,
});

const actualOptions = usedOptions();
const actualIntegrations = actualOptions?.integrations;
expect(actualIntegrations).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'Spotlight' })]));
});

it('adds spotlight integration with direct url', () => {
init({
spotlight: 'http://localhost:8969/stream',
});

const actualOptions = usedOptions();
const actualIntegrations = actualOptions?.integrations;
expect(actualIntegrations).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'Spotlight' })]));
});

it('no default integrations', () => {
init({
defaultIntegrations: false,
Expand Down

0 comments on commit 7b891b1

Please sign in to comment.