Skip to content

Commit 3b6f2be

Browse files
authored
fix: Only capture logs if enableLogs is true (#1235)
1 parent 1c92fc9 commit 3b6f2be

File tree

2 files changed

+61
-53
lines changed

2 files changed

+61
-53
lines changed

src/main/integrations/child-process.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export const childProcessIntegration = defineIntegration((userOptions: Partial<O
8080
// only hook these events if we're after more than just the unresponsive event
8181
if (allReasons.length > 0) {
8282
const clientOptions = client.getOptions() as ElectronMainOptions;
83+
const enableLogs = !!clientOptions?.enableLogs;
8384

8485
app.on('child-process-gone', (_, details) => {
8586
const { reason } = details;
@@ -100,11 +101,13 @@ export const childProcessIntegration = defineIntegration((userOptions: Partial<O
100101
data: details,
101102
});
102103

103-
log(messageFmt, {
104-
exitCode: details.exitCode,
105-
name: details.name,
106-
serviceName: details.serviceName,
107-
});
104+
if (enableLogs) {
105+
log(messageFmt, {
106+
exitCode: details.exitCode,
107+
name: details.name,
108+
serviceName: details.serviceName,
109+
});
110+
}
108111
}
109112
});
110113

@@ -128,9 +131,11 @@ export const childProcessIntegration = defineIntegration((userOptions: Partial<O
128131
data: details,
129132
});
130133

131-
log(messageFmt, {
132-
exitCode: details.exitCode,
133-
});
134+
if (enableLogs) {
135+
log(messageFmt, {
136+
exitCode: details.exitCode,
137+
});
138+
}
134139
}
135140
});
136141
}

src/main/integrations/electron-breadcrumbs.ts

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -110,55 +110,58 @@ export const electronBreadcrumbsIntegration = defineIntegration(
110110
...normalizeOptions(userOptions),
111111
};
112112

113-
function patchEventEmitter(
114-
emitter: NodeJS.EventEmitter | WebContents | BrowserWindow,
115-
category: string,
116-
shouldCapture: EventFunction | undefined | false,
117-
id?: number | undefined,
118-
): void {
119-
const emit = emitter.emit.bind(emitter) as (event: string, ...args: unknown[]) => boolean;
120-
121-
emitter.emit = (event: string, ...args: unknown[]) => {
122-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
123-
if (shouldCapture && shouldCapture(event)) {
124-
const breadcrumb: Breadcrumb = {
125-
category: 'electron',
126-
message: `${category}.${event}`,
127-
timestamp: new Date().getTime() / 1_000,
128-
type: 'ui',
129-
};
130-
131-
if (id) {
132-
breadcrumb.data = { ...getRendererProperties(id) };
133-
134-
if (!options.captureWindowTitles && breadcrumb.data?.title) {
135-
delete breadcrumb.data?.title;
136-
}
137-
}
138-
139-
addBreadcrumb(breadcrumb);
140-
141-
const attributes: Record<string, unknown> = {};
142-
143-
if (breadcrumb.data?.id) {
144-
attributes.id = breadcrumb.data.id;
145-
}
146-
147-
if (breadcrumb.data?.url) {
148-
attributes.url = breadcrumb.data.url;
149-
}
150-
151-
logger.info(logger.fmt`electron.${category}.${event}`, attributes);
152-
}
153-
154-
return emit(event, ...args);
155-
};
156-
}
157-
158113
return {
159114
name: 'ElectronBreadcrumbs',
160115
setup(client: NodeClient) {
161116
const clientOptions = client.getOptions() as ElectronMainOptions | undefined;
117+
const enableLogs = !!clientOptions?.enableLogs;
118+
119+
function patchEventEmitter(
120+
emitter: NodeJS.EventEmitter | WebContents | BrowserWindow,
121+
category: string,
122+
shouldCapture: EventFunction | undefined | false,
123+
id?: number | undefined,
124+
): void {
125+
const emit = emitter.emit.bind(emitter) as (event: string, ...args: unknown[]) => boolean;
126+
127+
emitter.emit = (event: string, ...args: unknown[]) => {
128+
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
129+
if (shouldCapture && shouldCapture(event)) {
130+
const breadcrumb: Breadcrumb = {
131+
category: 'electron',
132+
message: `${category}.${event}`,
133+
timestamp: new Date().getTime() / 1_000,
134+
type: 'ui',
135+
};
136+
137+
if (id) {
138+
breadcrumb.data = { ...getRendererProperties(id) };
139+
140+
if (!options.captureWindowTitles && breadcrumb.data?.title) {
141+
delete breadcrumb.data?.title;
142+
}
143+
}
144+
145+
addBreadcrumb(breadcrumb);
146+
147+
const attributes: Record<string, unknown> = {};
148+
149+
if (breadcrumb.data?.id) {
150+
attributes.id = breadcrumb.data.id;
151+
}
152+
153+
if (breadcrumb.data?.url) {
154+
attributes.url = breadcrumb.data.url;
155+
}
156+
157+
if (enableLogs) {
158+
logger.info(logger.fmt`electron.${category}.${event}`, attributes);
159+
}
160+
}
161+
162+
return emit(event, ...args);
163+
};
164+
}
162165

163166
trackRendererProperties();
164167

0 commit comments

Comments
 (0)