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
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@
> make sure you follow our [migration guide](https://docs.sentry.io/platforms/react-native/migration/) first.
<!-- prettier-ignore-end -->

## Unreleased

### Important Changes

- The `_experiments.enableLogs` and `_experiments.beforeSendLog` options were removed, use the top-level `enableLogs` and `beforeSendLog` options instead. ([#5122](https://github.com/getsentry/sentry-react-native/pull/5122))

```js
// before
Sentry.init({
_experiments: {
enableLogs: true,
beforeSendLog: log => {
return log;
},
},
});

// after
Sentry.init({
enableLogs: true,
beforeSendLog: log => {
return log;
},
});
```

## 7.0.0-rc.2

### Important Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,8 @@ protected void getSentryAndroidOptions(
if (rnOptions.hasKey("enableNdk")) {
options.setEnableNdk(rnOptions.getBoolean("enableNdk"));
}
if (rnOptions.hasKey("_experiments")) {
ReadableMap experiments = rnOptions.getMap("_experiments");
if (experiments.hasKey("enableLogs")) {
options.getLogs().setEnabled(experiments.getBoolean("enableLogs"));
}
if (rnOptions.hasKey("enableLogs")) {
options.getLogs().setEnabled(rnOptions.getBoolean("enableLogs"));
}
if (rnOptions.hasKey("spotlight")) {
if (rnOptions.getType("spotlight") == ReadableType.Boolean) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class ReactNativeClient extends Client<ReactNativeClientOptions> {
this.on('beforeSendSession', addAutoIpAddressToSession);
}

if (options._experiments?.enableLogs) {
if (options.enableLogs) {
this.on('flush', () => {
Comment on lines +67 to 68
Copy link

Choose a reason for hiding this comment

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

Potential bug: The refactoring to a top-level enableLogs option is incomplete. The property is missing from the BaseReactNativeOptions type, which will cause build failures and disable logging.
  • Description: The code was updated to access options.enableLogs instead of the experimental options._experiments?.enableLogs. However, the enableLogs property was not added to the BaseReactNativeOptions interface. Consequently, TypeScript projects using this option will fail to compile. For other projects, options.enableLogs will resolve to undefined at runtime, which disables the logs integration and prevents logs from being captured. This makes the feature non-functional for users following the migration path documented in the changelog.

  • Suggested fix: Add the optional enableLogs?: boolean property to the BaseReactNativeOptions interface in packages/core/src/js/options.ts. This will correctly type the new top-level option and ensure the logs integration can be enabled as intended by the refactor.
    severity: 0.75, confidence: 0.95

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

enableLogs comes from @sentry/core options. BaseReactNativeOptions only contains React Native exclusive options. Users use ReactNativeOptions instead of BaseReactNativeOptions.
ReactNativeOptions only server as an extension of BaseReactNativeOptions and Options from @sentry/core so the mentioned error will not happen.

_INTERNAL_flushLogsBuffer(this);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/integrations/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ
if (options.enableNative) {
integrations.push(deviceContextIntegration());
integrations.push(modulesLoaderIntegration());
if (options._experiments?.enableLogs) {
if (options.enableLogs) {
integrations.push(logEnricherIntegration());
}
if (options.attachScreenshot) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ProfilerProps = React.ComponentProps<typeof Profiler>;
type BrowserTransportOptions = Parameters<typeof makeFetchTransport>[0];

type BrowserExperiments = NonNullable<BrowserOptions['_experiments']>;
type SharedExperimentsSubset = Pick<BrowserExperiments, 'enableLogs' | 'beforeSendLog'>;
type SharedExperimentsSubset = BrowserExperiments;

export interface BaseReactNativeOptions {
/**
Expand Down
8 changes: 4 additions & 4 deletions samples/react-native/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ Sentry.init({
);
},
_experiments: {
enableLogs: true,
beforeSendLog: (log) => {
return log;
},
enableUnhandledCPPExceptionsV2: true,
},
enableLogs: true,
beforeSendLog: (log) => {
return log;
},
enableUserInteractionTracing: true,
integrations(integrations) {
integrations.push(
Expand Down
Loading