Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- fix: Preload injection path (#1243)
- fix: Preload `contextIsolation` issues (#1244)
- fix: Include `sentry.origin` with auto-generated logs (#1241)

## 7.1.0

Expand Down
2 changes: 2 additions & 0 deletions src/main/integrations/child-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const childProcessIntegration = defineIntegration((userOptions: Partial<O

if (enableLogs) {
log(messageFmt, {
'sentry.origin': 'auto.electron.child-process',
exitCode: details.exitCode,
name: details.name,
serviceName: details.serviceName,
Expand Down Expand Up @@ -133,6 +134,7 @@ export const childProcessIntegration = defineIntegration((userOptions: Partial<O

if (enableLogs) {
log(messageFmt, {
'sentry.origin': 'auto.electron.child-process',
exitCode: details.exitCode,
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/integrations/electron-breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ export const electronBreadcrumbsIntegration = defineIntegration(

addBreadcrumb(breadcrumb);

const attributes: Record<string, unknown> = {};
const attributes: Record<string, unknown> = {
'sentry.origin': 'auto.electron.events',
};

if (breadcrumb.data?.id) {
attributes.id = breadcrumb.data.id;
Expand Down
107 changes: 60 additions & 47 deletions src/main/integrations/net-breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
defineIntegration,
fill,
getBreadcrumbLogLevelFromHttpStatusCode,
getClient,
getTraceData,
LRUMap,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
Expand Down Expand Up @@ -89,6 +88,7 @@ type WrappedRequestMethodFactory = (original: RequestMethod) => RequestMethod;

function createWrappedRequestFactory(
options: NetOptions,
enableLogs: boolean,
tracePropagationTargets: TracePropagationTargets | undefined,
): WrappedRequestMethodFactory {
// We're caching results so we don't have to recompute regexp every time we create a request.
Expand Down Expand Up @@ -136,6 +136,57 @@ function createWrappedRequestFactory(
return true;
};

/**
* Captures Breadcrumb based on provided request/response pair
*/
const addRequestBreadcrumb = (
event: string,
method: string,
url: string,
req: ClientRequest,
res?: IncomingMessage,
): void => {
const level = getBreadcrumbLogLevelFromHttpStatusCode(res?.statusCode);

addBreadcrumb(
{
type: 'http',
category: 'electron.net',
data: {
url,
method: method,
status_code: res?.statusCode,
},
level,
},
{
event,
request: req,
response: res,
},
);

if (!enableLogs) {
return;
}

const attributes = {
'sentry.origin': 'auto.electron.net',
statusCode: res?.statusCode,
};

switch (level) {
case 'error':
logger.error(logger.fmt`Electron.net request failed: ${method} ${url}`, attributes);
break;
case 'warning':
logger.warn(logger.fmt`Electron.net request warning: ${method} ${url}`, attributes);
break;
default:
logger.info(logger.fmt`Electron.net request succeeded: ${method} ${url}`, attributes);
}
};

return function wrappedRequestMethodFactory(originalRequestMethod: RequestMethod): RequestMethod {
return function requestMethod(this: typeof electronNet, reqOptions: RequestOptions): ClientRequest {
const { url, method } = parseOptions(reqOptions);
Expand Down Expand Up @@ -191,64 +242,26 @@ function createWrappedRequestFactory(
};
}

/**
* Captures Breadcrumb based on provided request/response pair
*/
function addRequestBreadcrumb(
event: string,
method: string,
url: string,
req: ClientRequest,
res?: IncomingMessage,
): void {
const level = getBreadcrumbLogLevelFromHttpStatusCode(res?.statusCode);
addBreadcrumb(
{
type: 'http',
category: 'electron.net',
data: {
url,
method: method,
status_code: res?.statusCode,
},
level,
},
{
event,
request: req,
response: res,
},
);

const attributes = { statusCode: res?.statusCode };

switch (level) {
case 'error':
logger.error(logger.fmt`Electron.net request failed: ${method} ${url}`, attributes);
break;
case 'warning':
logger.warn(logger.fmt`Electron.net request warning: ${method} ${url}`, attributes);
break;
default:
logger.info(logger.fmt`Electron.net request succeeded: ${method} ${url}`, attributes);
}
}

/**
* Electron 'net' module integration
*/
export const electronNetIntegration = defineIntegration((options: NetOptions = {}) => {
return {
name: 'ElectronNet',
setup() {
const clientOptions = getClient()?.getOptions();
setup(client) {
const clientOptions = client.getOptions();
const enableLogs = !!clientOptions?.enableLogs;

// No need to instrument if we don't want to track anything
if (options.breadcrumbs === false && options.tracing === false) {
return;
}

fill(electronNet, 'request', createWrappedRequestFactory(options, clientOptions?.tracePropagationTargets));
fill(
electronNet,
'request',
createWrappedRequestFactory(options, enableLogs, clientOptions?.tracePropagationTargets),
);
},
};
});
1 change: 1 addition & 0 deletions test/e2e/test-apps/other/renderer-error/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ electronTestRunner(__dirname, async (ctx) => {
trace_id: UUID_MATCHER,
severity_number: 9,
attributes: {
'sentry.origin': { value: 'auto.electron.events', type: 'string' },
'sentry.release': { value: 'javascript-logs@1.0.0', type: 'string' },
'sentry.environment': { value: 'development', type: 'string' },
'sentry.sdk.name': { value: 'sentry.javascript.electron', type: 'string' },
Expand Down