Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure any scope updates do not clobber the initial async scope read #593

Merged
merged 1 commit into from
Nov 21, 2022
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
8 changes: 6 additions & 2 deletions src/main/integrations/sentry-minidump/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,18 @@ export class SentryMinidump implements Integration {
private _setupScopeListener(): void {
const hubScope = getCurrentHub().getScope();
if (hubScope) {
hubScope.addScopeListener(async (updatedScope) => {
hubScope.addScopeListener((updatedScope) => {
const scope = Scope.clone(updatedScope);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
(scope as any)._eventProcessors = [];
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
(scope as any)._scopeListeners = [];

await this._scopeStore?.set(scope);
// Since the initial scope read is async, we need to ensure that any writes do not beat that
// https://github.com/getsentry/sentry-electron/issues/585
setImmediate(() => {
void this._scopeStore?.set(scope);
});
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/test-apps/native-sentry/main/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"event.environment": "native",
"event.origin": "electron",
"event.process": "browser",
"event_type": "native"
"event_type": "native",
"app-run": "first"
}
},
"attachments": [ { "attachment_type": "event.minidump" } ]
Expand Down
8 changes: 6 additions & 2 deletions test/e2e/test-apps/native-sentry/main/src/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');

const { app, BrowserWindow } = require('electron');
const { init } = require('@sentry/electron');
const { init, configureScope } = require('@sentry/electron');

init({
dsn: '__DSN__',
Expand All @@ -10,6 +10,10 @@ init({
onFatalError: () => {},
});

configureScope((scope) => {
scope.setTag('app-run', process.env.APP_FIRST_RUN ? 'first' : 'second');
});

app.on('ready', () => {
const mainWindow = new BrowserWindow({
show: false,
Expand All @@ -28,4 +32,4 @@ app.on('ready', () => {
process.crash();
}, 500);
}
});
});