bump: @sentry/electron (#7561)

* bump: @sentry/electron

* bump: @sentry/electron

* sentry config user

* resolve conflict
This commit is contained in:
Curry Yang 2024-07-04 11:08:55 +08:00 committed by GitHub
parent 2ccc2326ab
commit b6c9bb9d46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 912 additions and 159 deletions

995
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -45,7 +45,6 @@
"@jest/globals": "^29.7.0",
"@seald-io/nedb": "^4.0.4",
"@segment/analytics-node": "2.1.0",
"@sentry/electron": "^3.0.7",
"apiconnect-wsdl": "1.8.31",
"aws4": "^1.12.0",
"chai": "^4.3.4",
@ -83,10 +82,6 @@
"yaml-source-map": "^2.1.1"
},
"devDependencies": {
"@stoplight/spectral-core": "^1.18.3",
"@stoplight/spectral-formats": "^1.6.0",
"@stoplight/spectral-rulesets": "^1.18.1",
"@stoplight/spectral-ruleset-bundler": "1.5.2",
"@develohpanda/fluent-builder": "^2.1.2",
"@faker-js/faker": "8.4.1",
"@fortawesome/fontawesome-svg-core": "^6.5.2",
@ -95,6 +90,10 @@
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@getinsomnia/api-client": "0.0.4",
"@stoplight/spectral-core": "^1.18.3",
"@stoplight/spectral-formats": "^1.6.0",
"@stoplight/spectral-ruleset-bundler": "1.5.2",
"@stoplight/spectral-rulesets": "^1.18.1",
"@tailwindcss/typography": "^0.5.12",
"@tanstack/react-virtual": "3.2.0",
"@testing-library/dom": "^9.3.4",
@ -185,7 +184,8 @@
"vkbeautify": "^0.99.3",
"ws": "^8.17.1",
"xmldom": "^0.6.0",
"xpath": "0.0.34"
"xpath": "0.0.34",
"@sentry/electron": "^5.1.0"
},
"dev": {
"dev-server-port": 3334

View File

@ -1,8 +1,8 @@
import type { ElectronOptions } from '@sentry/electron';
import { ClientOptions } from '@sentry/types';
import { getAppEnvironment, getAppVersion, getSentryDsn } from './constants';
export const SENTRY_OPTIONS: Partial<ElectronOptions> = {
export const SENTRY_OPTIONS: Partial<ClientOptions> = {
sampleRate: 0.5,
dsn: getSentryDsn(),
environment: getAppEnvironment(),

View File

@ -27,6 +27,12 @@ import { Project, RemoteProject } from './models/project';
import type { Stats } from './models/stats';
import type { ToastNotification } from './ui/components/toast';
// Override the Electron userData path
// This makes Chromium use this folder for eg localStorage
// ensure userData dir change is made before configure sentry SDK (https://docs.sentry.io/platforms/javascript/guides/electron/#app-userdata-directory)
const dataPath = process.env.INSOMNIA_DATA_PATH || path.join(app.getPath('userData'), '../', isDevelopment() ? 'insomnia-app' : userDataFolder);
app.setPath('userData', dataPath);
initializeSentry();
registerInsomniaProtocols();
@ -39,11 +45,6 @@ if (checkIfRestartNeeded()) {
initializeLogging();
log.info(`Running version ${getAppVersion()}`);
// Override the Electron userData path
// This makes Chromium use this folder for eg localStorage
const dataPath = process.env.INSOMNIA_DATA_PATH || path.join(app.getPath('userData'), '../', isDevelopment() ? 'insomnia-app' : userDataFolder);
app.setPath('userData', dataPath);
// So if (window) checks don't throw
global.window = global.window || undefined;

View File

@ -1,5 +1,4 @@
import * as Sentry from '@sentry/electron/main';
import type { SentryRequestType } from '@sentry/types';
import * as session from '../account/session';
import { ChangeBufferEvent, database as db } from '../common/database';
@ -33,21 +32,27 @@ export function sentryWatchAnalyticsEnabled() {
});
}
// TODO(johnwchadwick): We are vendoring ElectronOfflineNetTransport just to be able to control whether or not sending is allowed, because we don't have a choice right now. We should work with the upstream library to get similar functionality upstream. See getsentry/sentry-electron#489.
// some historical context:
// At beginning We are vendoring ElectronOfflineNetTransport just to be able to control whether or not sending is allowed
// https://github.com/getsentry/sentry-electron/issues/489
class ElectronSwitchableTransport extends Sentry.ElectronOfflineNetTransport {
protected _isRateLimited(requestType: SentryRequestType) {
if (!enabled) {
return true;
}
return super._isRateLimited(requestType);
}
}
// After the official support. Now we could use the transportOptions.shouldSend to control whether or not sending is allowed
// https://github.com/getsentry/sentry-electron/pull/889
// docs: https://docs.sentry.io/platforms/javascript/guides/electron/
export function initializeSentry() {
Sentry.init({
...SENTRY_OPTIONS,
transport: ElectronSwitchableTransport,
transportOptions: {
/**
* Called before we attempt to send an envelope to Sentry.
*
* If this function returns false, `shouldStore` will be called to determine if the envelope should be stored.
*
* Default: () => true
*
* @param envelope The envelope that will be sent.
* @returns Whether we should attempt to send the envelope
*/
shouldSend: () => enabled,
},
});
}

View File

@ -1,18 +1,16 @@
import * as Sentry from '@sentry/electron';
import * as Sentry from '@sentry/electron/renderer';
import { getAccountId, onLoginLogout } from '../account/session';
import { SENTRY_OPTIONS } from '../common/sentry';
/** Configures user info in Sentry scope. */
function sentryConfigureUserInfo() {
Sentry.configureScope(async scope => {
const id = await getAccountId();
if (id) {
scope.setUser({ id });
} else {
scope.setUser(null);
}
});
async function sentryConfigureUserInfo() {
const id = await getAccountId();
if (id) {
Sentry.getCurrentScope().setUser({ id });
} else {
Sentry.getCurrentScope().setUser(null);
}
}
/** Watches user info for changes. */