Repository: getsentry/sentry-capacitor
Pull request #365 (2023-05-02 13:34:39)

add stale.yml
After reviewing some Issues I noticed that some old issues didn't have any stale warning.

So I just added the missing Github integration that Sentry uses on other Projects.

In this case, it's basically the same implementation as the one done on React Native: https://github.com/getsentry/sentry-react-native/blob/main/.github/workflows/stale.yml

#skip-changelog


Patch:
diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml
new file mode 100644
index 0000000..b950815
--- /dev/null
+++ b/.github/workflows/stale.yml
@@ -0,0 +1,46 @@
+name: "close stale issues/PRs"
+on:
+  schedule:
+    - cron: "0 0 * * *"
+  workflow_dispatch:
+jobs:
+  stale:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/stale@1160a2240286f5da8ec72b1c0816ce2481aabf84
+        with:
+          repo-token: ${{ github.token }}
+          days-before-stale: 21
+          days-before-close: 7
+          only-labels: ""
+          operations-per-run: 100
+          remove-stale-when-updated: true
+          debug-only: false
+          ascending: false
+
+          exempt-issue-labels: "Status: Backlog,Status: In Progress"
+          stale-issue-label: "Status: Stale"
+          stale-issue-message: |-
+            This issue has gone three weeks without activity. In another week, I will close it.
+
+            But! If you comment or otherwise update it, I will reset the clock, and if you label it `Status: Backlog` or `Status: In Progress`, I will leave it alone ... forever!
+
+            ----
+
+            "A weed is but an unloved flower." ― _Ella Wheeler Wilcox_ 🥀
+          close-issue-label: ""
+          close-issue-message: ""
+
+          exempt-pr-labels: "Status: Backlog,Status: In Progress"
+          stale-pr-label: "Status: Stale"
+          stale-pr-message: |-
+            This pull request has gone three weeks without activity. In another week, I will close it.
+
+            But! If you comment or otherwise update it, I will reset the clock, and if you label it `Status: Backlog` or `Status: In Progress`, I will leave it alone ... forever!
+
+            ----
+
+            "A weed is but an unloved flower." ― _Ella Wheeler Wilcox_ 🥀
+          skip-stale-pr-message: false
+          close-pr-label:
+          close-pr-message: ""
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5a87089..68cac1b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
 # Changelog
 
+## 0.11.4
+
+### Fixes
+
+- Fix Deprecated references to Sdk Info ([#376](https://github.com/getsentry/sentry-capacitor/pull/376))
+- Fix iOS not Sending events ([#370](https://github.com/getsentry/sentry-capacitor/pull/370))
+
 ## 0.11.3
 
 ### Fixes
diff --git a/ios/Plugin/Plugin.swift b/ios/Plugin/Plugin.swift
index 99afdc3..7fb8a25 100644
--- a/ios/Plugin/Plugin.swift
+++ b/ios/Plugin/Plugin.swift
@@ -119,13 +119,9 @@ public class SentryCapacitor: CAPPlugin {
     }
 
     @objc func fetchNativeSdkInfo(_ call: CAPPluginCall) {
-        guard let options = self.sentryOptions else {
-            return call.reject("Called fetchSdkInfo without initializing cocoa SDK.")
-        }
-
         call.resolve([
-            "name": options.sdkInfo.name,
-            "version": options.sdkInfo.version
+            "name": PrivateSentrySDKOnly.getSdkName(),
+            "version": PrivateSentrySDKOnly.getSdkVersionString()
         ])
     }
 
diff --git a/package.json b/package.json
index 76faf0f..e76dff7 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,7 @@
     "type": "git",
     "url": "https://github.com/getsentry/sentry-capacitor"
   },
-  "version": "0.11.3",
+  "version": "0.11.4",
   "description": "Official Sentry SDK for Capacitor",
   "types": "dist/esm/index.d.ts",
   "main": "dist/build/index.js",
diff --git a/src/nativeOptions.ts b/src/nativeOptions.ts
new file mode 100644
index 0000000..473b11b
--- /dev/null
+++ b/src/nativeOptions.ts
@@ -0,0 +1,36 @@
+import type { CapacitorOptions } from './options';
+
+/**
+ * Create a new CapacitorOption without any parameter that could crash the bridge (in short, not being a string, number or boolean).
+ * some of the excluded parameters are: Integrations, app, vue, beforeSend, beforeBreadcrumb, integrations, defaultIntegrations, transport, tracesSampler.
+ * @param options CapacitorOptions
+ */
+export function FilterNativeOptions(options: CapacitorOptions): CapacitorOptions {
+  return {
+    // allowUrls: Only available on the JavaScript Layer.
+    attachStacktrace: options.attachStacktrace,
+    attachThreads: options.attachThreads,
+    debug: options.debug,
+    // denyUrls Only available on the JavaScript Layer.
+    dist: options.dist,
+    dsn: options.dsn,
+    enabled: options.enabled,
+    enableNdkScopeSync: options.enableNdkScopeSync,
+    enableOutOfMemoryTracking: options.enableOutOfMemoryTracking,
+    enableTracing: options.enableTracing,
+    environment: options.environment,
+    // ignoreErrors: Only available on the JavaScript Layer.
+    // ignoreTransactions: Only available on the JavaScript Layer.
+    maxBreadcrumbs: options.maxBreadcrumbs,
+    // maxValueLength: Only available on the JavaScript Layer.
+    release: options.release,
+    // replaysOnErrorSampleRate: Only handled on the JavaScript Layer.
+    // replaysSessionSampleRate: Only handled on the JavaScript Layer.
+    sampleRate: options.sampleRate,
+    sendClientReports: options.sendClientReports,
+    sendDefaultPii: options.sendDefaultPii,
+    sessionTrackingIntervalMillis: options.sessionTrackingIntervalMillis,
+    tracesSampleRate: options.tracesSampleRate,
+    // tunnel: options.tunnel: Only handled on the JavaScript Layer.
+  };
+}
diff --git a/src/version.ts b/src/version.ts
index 92f50b2..360befc 100644
--- a/src/version.ts
+++ b/src/version.ts
@@ -1,2 +1,2 @@
 export const SDK_NAME = 'sentry.javascript.capacitor';
-export const SDK_VERSION = '0.11.3';
+export const SDK_VERSION = '0.11.4';
diff --git a/src/wrapper.ts b/src/wrapper.ts
index aeba79a..b6055e7 100644
--- a/src/wrapper.ts
+++ b/src/wrapper.ts
@@ -3,6 +3,7 @@ import type { BaseEnvelopeItemHeaders, Breadcrumb, Envelope, EnvelopeItem, Event
 import { dropUndefinedKeys, logger, SentryError } from '@sentry/utils';
 
 import type { NativeDeviceContextsResponse } from './definitions';
+import { FilterNativeOptions } from './nativeOptions';
 import type { CapacitorOptions } from './options';
 import { SentryCapacitor } from './plugin';
 import { utf8ToBytes } from './vendor';
@@ -96,21 +97,7 @@ export const NATIVE = {
     }
 
     // filter out all options that would crash native
-    /* eslint-disable @typescript-eslint/unbound-method, @typescript-eslint/no-unused-vars */
-    const {
-      // @ts-ignore Vue specific option.
-      app,
-      // @ts-ignore Vue specific option.
-      vue,
-      beforeSend,
-      beforeBreadcrumb,
-      integrations,
-      defaultIntegrations,
-      transport,
-      tracesSampler,
-      ...filteredOptions
-    } = options;
-
+    const filteredOptions = FilterNativeOptions(options);
     return SentryCapacitor.initNativeSdk({ options: filteredOptions });
   },
 


Test patch:
diff --git a/test/nativeOptions.test.ts b/test/nativeOptions.test.ts
new file mode 100644
index 0000000..cd855f3
--- /dev/null
+++ b/test/nativeOptions.test.ts
@@ -0,0 +1,68 @@
+import type { Instrumenter, StackParser } from '@sentry/types';
+
+import { FilterNativeOptions } from '../src/nativeOptions';
+
+describe('nativeOptions', () => {
+  test('invalid types not included', async () => {
+    const nativeOptions = FilterNativeOptions(
+      {
+        _experiments: [true],
+        _metadata: {},
+        allowUrls: ['test'],
+        attachStacktrace: true,
+        attachThreads: true,
+        beforeBreadcrumb: ((bread) => bread),
+        beforeSend: ((evt) => evt),
+        beforeSendTransaction: ((transaction) => transaction),
+        debug: true,
+        defaultIntegrations: [],
+        denyUrls: [],
+        dist: '1',
+        dsn: 'dns',
+        enableAutoSessionTracking: true,
+        enabled: true,
+        enableNative: true,
+        enableNativeCrashHandling: true,
+        enableNativeNagger: true,
+        enableNdkScopeSync: true,
+        enableOutOfMemoryTracking: true,
+        enableTracing: true,
+        environment: 'Prod',
+        ignoreErrors: ['test'],
+        ignoreTransactions: ['test'],
+        initialScope: {},
+        instrumenter: {} as Instrumenter,
+        integrations: [],
+        maxBreadcrumbs: 100,
+        maxValueLength: 100,
+        normalizeDepth: 100,
+        normalizeMaxBreadth: 100,
+        release: '1',
+        replaysOnErrorSampleRate: 1,
+        replaysSessionSampleRate: 1,
+        sampleRate: 1,
+        sendClientReports: true,
+        sendDefaultPii: true,
+        sessionTrackingIntervalMillis: 10,
+        shutdownTimeout: 10,
+        stackParser: {} as StackParser,
+        tracesSampler: ((_) => 1),
+        tracesSampleRate: 1,
+        transportOptions: {},
+        tunnel: 'test',
+      });
+
+    const keys = Object.keys(nativeOptions);
+    const keysFilter = keys.filter(key =>
+      // @ts-ignore allowed for testing.
+      (typeof nativeOptions[key]) !== 'string' &&
+      // @ts-ignore allowed for testing.
+      (typeof nativeOptions[key]) !== 'number' &&
+      // @ts-ignore allowed for testing.
+      (typeof nativeOptions[key]) !== 'boolean' &&
+      // @ts-ignore allowed for testing.
+      (typeof nativeOptions[key]) !== undefined)
+
+    expect(keysFilter.toString()).toBe('');
+  });
+});
diff --git a/test/wrapper.test.ts b/test/wrapper.test.ts
index db68f6c..a056df7 100644
--- a/test/wrapper.test.ts
+++ b/test/wrapper.test.ts
@@ -87,7 +87,7 @@ describe('Tests Native Wrapper', () => {
       expect(SentryCapacitor.initNativeSdk).toBeCalled();
     });
 
-    test('Vue options to be removed', async () => {
+    test('Vue and App options to be removed', async () => {
 
       const initNativeSdk = jest.spyOn(SentryCapacitor, 'initNativeSdk');
 
@@ -104,6 +104,36 @@ describe('Tests Native Wrapper', () => {
       expect(initNativeSdk).toBeCalled();
     });
 
+
+    test('default options to be removed', async () => {
+      const initNativeSdk = jest.spyOn(SentryCapacitor, 'initNativeSdk');
+      await NATIVE.initNativeSdk(
+        {
+          dsn: 'test',
+          enableNative: true,
+          integrations: [],
+          defaultIntegrations: [],
+          beforeSend: ((event) => event),
+          beforeBreadcrumb: ((breadcrumb) => breadcrumb),
+          beforeSendTransaction: (transaction) => transaction,
+          transport: jest.fn(),
+          tracesSampler: jest.fn(),
+        });
+
+      const nativeOption = initNativeSdk.mock.calls[0][0].options;
+      expect(SentryCapacitor.initNativeSdk).toBeCalledTimes(1);
+      // @ts-ignore Not part of Capacitor Options but it is extended by Vue Options.
+      expect(nativeOption.integrations).toBeUndefined();
+      expect(nativeOption.defaultIntegrations).toBeUndefined();
+      expect(nativeOption.beforeSend).toBeUndefined();
+      expect(nativeOption.beforeSendTransaction).toBeUndefined();
+      expect(nativeOption.beforeBreadcrumb).toBeUndefined();
+      expect(nativeOption.transport).toBeUndefined();
+      expect(nativeOption.tracesSampler).toBeUndefined();
+
+      expect(initNativeSdk).toBeCalled();
+    });
+
     test('warns if there is no dsn', async () => {
       SentryCapacitor.initNativeSdk = jest.fn();
       logger.warn = jest.fn();