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

feat: Allow ignoring minidumps from specific processes #1050

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 19 additions & 3 deletions src/main/integrations/sentry-minidump/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@ interface Options {
* default: 10
*/
maxMinidumpsPerSession?: number;

/**
* Which processes to ignore minidumps for.
* Minidumps of the supplied types will be ignored and will not impact the apps crash free session rate
*
* default: None
*/
ignoredProcesses?: Array<'browser' | 'renderer' | 'utility' | 'GPU' | 'node' | 'unknown' | string>;
}

/**
* Sends minidumps via the Sentry uploader
*/
export const sentryMinidumpIntegration = defineIntegration((options: Options = {}) => {
const ignoredProcesses = options.ignoredProcesses || [];
// The remaining number of minidumps that can be sent in this session
let minidumpsRemaining = options.maxMinidumpsPerSession || 10;
// Store to persist context information beyond application crashes.
Expand Down Expand Up @@ -106,12 +115,12 @@ export const sentryMinidumpIntegration = defineIntegration((options: Options = {
let minidumpFound = false;

await minidumpLoader?.(deleteAll, async (minidumpProcess, attachment) => {
minidumpFound = true;

const event = getEvent(minidumpProcess);

const eventProcess = event.tags?.['event.process'];

// If this is a native main process crash, we need to apply the scope and context from the previous run
if (event.tags?.['event.process'] === 'browser') {
if (eventProcess === 'browser') {
const previousRun = await scopeLastRun;
if (previousRun) {
if (previousRun.scope) {
Expand All @@ -124,10 +133,17 @@ export const sentryMinidumpIntegration = defineIntegration((options: Options = {
}
}

if (typeof eventProcess === 'string' && ignoredProcesses.includes(eventProcess)) {
logger.log(`Dropping '${eventProcess}' minidump because they are ignored`);
return;
}

if (!event) {
return;
}

minidumpFound = true;

if (minidumpsRemaining > 0) {
minidumpsRemaining -= 1;
captureEvent(event as Event, { attachments: [attachment] });
Expand Down
75 changes: 75 additions & 0 deletions test/e2e/test-apps/native-sentry/child-exec/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"method": "envelope",
"sentryKey": "37f8a2ee37c0409d8970bc7559c7c7e4",
"appId": "277345",
"data": {
"sdk": {
"name": "sentry.javascript.electron",
"packages": [
{
"name": "npm:@sentry/electron",
"version": "{{version}}"
}
],
"version": "{{version}}"
},
"contexts": {
"app": {
"app_name": "native-sentry-child-exec",
"app_version": "1.0.0",
"app_start_time": "{{time}}"
},
"browser": {
"name": "Chrome"
},
"chrome": {
"name": "Chrome",
"type": "runtime",
"version": "{{version}}"
},
"device": {
"arch": "{{arch}}",
"family": "Desktop",
"memory_size": 0,
"free_memory": 0,
"processor_count": 0,
"processor_frequency": 0,
"cpu_description": "{{cpu}}",
"screen_resolution": "{{screen}}",
"screen_density": 1
},
"culture": {
"locale": "{{locale}}",
"timezone": "{{timezone}}"
},
"node": {
"name": "Node",
"type": "runtime",
"version": "{{version}}"
},
"os": {
"name": "{{platform}}",
"version": "{{version}}"
},
"runtime": {
"name": "Electron",
"version": "{{version}}"
}
},
"release": "[email protected]",
"environment": "development",
"event_id": "{{id}}",
"timestamp": 0,
"breadcrumbs": [],
"tags": {
"event.environment": "native",
"event.origin": "electron",
"event.process": "unknown"
}
},
"attachments": [
{
"attachment_type": "event.minidump"
}
]
}
9 changes: 9 additions & 0 deletions test/e2e/test-apps/native-sentry/child-exec/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "native-sentry-child-exec",
"version": "1.0.0",
"main": "src/main.js",
"dependencies": {
"@sentry/electron": "5.6.0",
"crashy-cli": "1.0.1"
}
}
5 changes: 5 additions & 0 deletions test/e2e/test-apps/native-sentry/child-exec/recipe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: Native Child Exec Crash
category: Native (Sentry Uploader)
command: yarn
runTwice: true
condition: platform === 'darwin'
15 changes: 15 additions & 0 deletions test/e2e/test-apps/native-sentry/child-exec/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<script>
const { init } = require('@sentry/electron/renderer');

init({
debug: true,
});
</script>
</body>
</html>
37 changes: 37 additions & 0 deletions test/e2e/test-apps/native-sentry/child-exec/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const path = require('path');
const child_process = require('child_process');

const { getPath } = require('crashy-cli');
const { app, BrowserWindow } = require('electron');
const { init } = require('@sentry/electron/main');

init({
dsn: '__DSN__',
debug: true,
autoSessionTracking: false,
onFatalError: () => {},
});

app.on('ready', () => {
const mainWindow = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});

mainWindow.loadFile(path.join(__dirname, 'index.html'));

if (process.env.APP_FIRST_RUN) {
try {
child_process.execSync(getPath());
} catch (_) {
//
}

setTimeout(() => {
app.exit();
}, 3000);
}
});
75 changes: 75 additions & 0 deletions test/e2e/test-apps/native-sentry/child-fork/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"method": "envelope",
"sentryKey": "37f8a2ee37c0409d8970bc7559c7c7e4",
"appId": "277345",
"data": {
"sdk": {
"name": "sentry.javascript.electron",
"packages": [
{
"name": "npm:@sentry/electron",
"version": "{{version}}"
}
],
"version": "{{version}}"
},
"contexts": {
"app": {
"app_name": "native-sentry-child-fork",
"app_version": "1.0.0",
"app_start_time": "{{time}}"
},
"browser": {
"name": "Chrome"
},
"chrome": {
"name": "Chrome",
"type": "runtime",
"version": "{{version}}"
},
"device": {
"arch": "{{arch}}",
"family": "Desktop",
"memory_size": 0,
"free_memory": 0,
"processor_count": 0,
"processor_frequency": 0,
"cpu_description": "{{cpu}}",
"screen_resolution": "{{screen}}",
"screen_density": 1
},
"culture": {
"locale": "{{locale}}",
"timezone": "{{timezone}}"
},
"node": {
"name": "Node",
"type": "runtime",
"version": "{{version}}"
},
"os": {
"name": "{{platform}}",
"version": "{{version}}"
},
"runtime": {
"name": "Electron",
"version": "{{version}}"
}
},
"release": "[email protected]",
"environment": "development",
"event_id": "{{id}}",
"timestamp": 0,
"breadcrumbs": [],
"tags": {
"event.environment": "native",
"event.origin": "electron",
"event.process": "node"
}
},
"attachments": [
{
"attachment_type": "event.minidump"
}
]
}
9 changes: 9 additions & 0 deletions test/e2e/test-apps/native-sentry/child-fork/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "native-sentry-child-fork",
"version": "1.0.0",
"main": "src/main.js",
"dependencies": {
"@sentry/electron": "5.6.0",
"sadness-generator": "0.0.2"
}
}
5 changes: 5 additions & 0 deletions test/e2e/test-apps/native-sentry/child-fork/recipe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: Native Child Crash
category: Native (Sentry Uploader)
command: yarn
runTwice: true
condition: platform !== 'linux'
5 changes: 5 additions & 0 deletions test/e2e/test-apps/native-sentry/child-fork/src/child.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { raiseSegfault } = require('sadness-generator')

setTimeout(() => {
raiseSegfault();
}, 1000);
15 changes: 15 additions & 0 deletions test/e2e/test-apps/native-sentry/child-fork/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<script>
const { init } = require('@sentry/electron/renderer');

init({
debug: true,
});
</script>
</body>
</html>
32 changes: 32 additions & 0 deletions test/e2e/test-apps/native-sentry/child-fork/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const path = require('path');
const child_process = require('child_process');

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

init({
dsn: '__DSN__',
debug: true,
autoSessionTracking: false,
onFatalError: () => {},
});

app.on('ready', () => {
const mainWindow = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});

mainWindow.loadFile(path.join(__dirname, 'index.html'));

if (process.env.APP_FIRST_RUN) {
child_process.fork(path.join(__dirname, 'child.js'));

setTimeout(() => {
app.exit();
}, 3000);
}
});
Loading
Loading