Repository: getsentry/sentry-capacitor
Pull request #585 (2024-02-29 22:32:06)

Feat: Add enable capture failed requests
This flag is enabled by default on iOS where it should be defaulted by false.

This flag will reduce error noises from clients since it'll stop recording Http errors that came from the Native side.
Users should only enable this flag if they do made Native code that does Http Requests.


TEST:

When this flag wasn't set, if a native Http Request error happened, the native SDK creates an event for it.
https://sentry-sdks.sentry.io/issues/5025177828/events/959b6258d9eb4931b196139436996011/?project=5522756

When disabled (the new behaviour), the same event will not be created.

github-actions[bot]: 
<!--
  1 failure:  Please consider a...
  0 warning: 
  
  1 markdown notices
  DangerID: danger-id-Danger;
-->

<table>
  <thead>
    <tr>
      <th width="50"></th>
      <th width="100%" data-danger-table="true">Fails</th>
    </tr>
  </thead>
  <tbody><tr>
      <td>:no_entry_sign:</td>
      <td>Please consider adding a changelog entry for the next release.</td>
    </tr>
  </tbody>
</table>




### Instructions and example for changelog
Please add an entry to `CHANGELOG.md` to the "Unreleased" section. Make sure the entry includes this PR's number.
Example:
```markdown
## Unreleased

### Fixes/Features

- Add enable capture failed requests ([#585](https://github.com/getsentry/sentry-capacitor/pull/585))
```
If none of the above apply, you can opt out of this check by adding `#skip-changelog` to the PR description.

<p align="right">
  Generated by :no_entry_sign: <a href="https://danger.systems/js">dangerJS</a> against 1dcf5df78ea995d76f06471eb3ae3d2f3d9f6be0
</p>


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 166d0e1..76299ee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
 # Changelog
 
+## Unreleased
+
+### Features
+
+- Add option for iOS: enableCaptureFailedRequests. Allowing users to ignore native Http Request errors. ([#585](https://github.com/getsentry/sentry-capacitor/pull/585))
+
 ## 0.15.1
 
 ### Fixes
diff --git a/src/nativeOptions.ts b/src/nativeOptions.ts
index 7429d1d..d166e89 100644
--- a/src/nativeOptions.ts
+++ b/src/nativeOptions.ts
@@ -33,5 +33,6 @@ export function FilterNativeOptions(options: CapacitorOptions): CapacitorOptions
     sessionTrackingIntervalMillis: options.sessionTrackingIntervalMillis,
     tracesSampleRate: options.tracesSampleRate,
     // tunnel: options.tunnel: Only handled on the JavaScript Layer.
+    enableCaptureFailedRequests: options.enableCaptureFailedRequests,
   };
 }
diff --git a/src/options.ts b/src/options.ts
index 39d7415..70bcb60 100644
--- a/src/options.ts
+++ b/src/options.ts
@@ -54,4 +54,11 @@ export interface CapacitorOptions
   * @deprecated The method will be removed on a major update, instead, use enableWatchdogTerminationTracking for the same result.
   * */
   enableOutOfMemoryTracking?: boolean;
+
+  /**
+   * When enabled, Sentry will capture failed XHR/Fetch requests. This option also enabled HTTP Errors on iOS.
+   *
+   * @default false
+   */
+  enableCaptureFailedRequests?: boolean;
 }
diff --git a/src/sdk.ts b/src/sdk.ts
index c00330f..d615538 100644
--- a/src/sdk.ts
+++ b/src/sdk.ts
@@ -25,6 +25,7 @@ export function init<T>(
   const finalOptions = {
     enableAutoSessionTracking: true,
     enableWatchdogTerminationTracking: true,
+    enableCaptureFailedRequests: false,
     ...passedOptions,
   };
   if (finalOptions.enabled === false ||


Test patch:
diff --git a/test/nativeOptions.test.ts b/test/nativeOptions.test.ts
index e03d357..ab1823d 100644
--- a/test/nativeOptions.test.ts
+++ b/test/nativeOptions.test.ts
@@ -28,6 +28,14 @@ describe('nativeOptions', () => {
     expect(nativeOptions.enableWatchdogTerminationTracking).toBeTruthy();
   });
 
+  test('enableCaptureFailedRequests is set when defined', async () => {
+    const nativeOptions = FilterNativeOptions(
+      {
+        enableCaptureFailedRequests: true
+      });
+    expect(nativeOptions.enableCaptureFailedRequests).toBeTruthy();
+  });
+
   test('invalid types not included', async () => {
     const nativeOptions = FilterNativeOptions(
       {
@@ -52,6 +60,7 @@ describe('nativeOptions', () => {
         enableNdkScopeSync: true,
         enableOutOfMemoryTracking: true,
         enableTracing: true,
+        enableCaptureFailedRequests: true,
         environment: 'Prod',
         ignoreErrors: ['test'],
         ignoreTransactions: ['test'],