Skip to content
Draft
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
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@
"e2e": "xvfb-maybe vitest run --root=./test/e2e --silent=false --disable-console-intercept"
},
"dependencies": {
"@sentry/browser": "10.70.0",
"@sentry/browser": "11.0.0-alpha.1",
"@sentry/conventions": "^0.16.0",
"@sentry/core": "10.70.0",
"@sentry/node": "10.70.0"
"@sentry/core": "11.0.0-alpha.1",
"@sentry/node": "11.0.0-alpha.1",
"@sentry/opentelemetry": "11.0.0-alpha.1",
"@sentry/server-utils": "11.0.0-alpha.1"
},
"peerDependencies": {
"@sentry/node-native": "10.70.0"
"@sentry/node-native": "11.0.0-alpha.1"
},
"peerDependenciesMeta": {
"@sentry/node-native": {
Expand All @@ -120,8 +122,8 @@
},
"devDependencies": {
"@rollup/plugin-typescript": "^12.1.3",
"@sentry/eslint-plugin-sdk": "10.70.0",
"@sentry/node-native": "10.70.0",
"@sentry/eslint-plugin-sdk": "11.0.0-alpha.1",
"@sentry/node-native": "11.0.0-alpha.1",
"@types/busboy": "^1.5.4",
"@types/koa": "^2.0.52",
"@types/koa-bodyparser": "^4.3.0",
Expand Down
20 changes: 5 additions & 15 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export {
addIntegration,
amqplibIntegration,
anthropicAIIntegration,
applyDiagnosticsChannelInjectionIntegrations,
bindScopeToEmitter,
buildLaunchDarklyFlagUsedHandler,
captureCheckIn,
Expand All @@ -33,7 +32,6 @@ export {
captureMessage,
captureSession,
close,
connectIntegration,
consoleIntegration,
consoleLoggingIntegration,
contextLinesIntegration,
Expand All @@ -46,7 +44,6 @@ export {
cron,
dataloaderIntegration,
dedupeIntegration,
diagnosticsChannelInjectionIntegrations,
endSession,
eventFiltersIntegration,
expressErrorHandler,
Expand All @@ -58,14 +55,14 @@ export {
flush,
fsIntegration,
functionToStringIntegration,
generateInstrumentOnce,
genericPoolIntegration,
getActiveSpan,
getAutoPerformanceIntegrations,
getClient,
getCurrentScope,
getGlobalScope,
getIsolationScope,
getOtlpTracesEndpoint,
getRootSpan,
getSpanDescendants,
getSpanStatusFromHttpCode,
Expand All @@ -75,23 +72,18 @@ export {
growthbookIntegration,
graphqlIntegration,
hapiIntegration,
honoIntegration,
httpHeadersToSpanAttributes,
httpIntegration,
httpServerIntegration,
httpServerSpansIntegration,
// eslint-disable-next-line deprecation/deprecation
inboundFiltersIntegration,
initOpenTelemetry,
instrumentAnthropicAiClient,
instrumentGoogleGenAIClient,
instrumentLangChainEmbeddings,
instrumentLangGraph,
instrumentOpenAiClient,
instrumentStateGraph,
instrumentStateGraphCompile,
instrumentSupabaseClient,
isDiagnosticsChannelInjectionEnabled,
isEnabled,
isInitialized,
kafkaIntegration,
Expand Down Expand Up @@ -119,6 +111,7 @@ export {
openAIIntegration,
OpenFeatureIntegrationHook,
openFeatureIntegration,
otlpIntegration,
parameterize,
pinoIntegration,
postgresIntegration,
Expand All @@ -133,7 +126,6 @@ export {
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
SentryContextManager,
setAttribute,
setAttributes,
setConversationId,
Expand All @@ -143,19 +135,18 @@ export {
setExtras,
setHttpStatus,
setMeasurement,
setNodeAsyncContextStrategy,
setOpenTelemetryContextAsyncContextStrategy,
setTag,
setTags,
setupConnectErrorHandler,
setupExpressErrorHandler,
setupFastifyErrorHandler,
setupHapiErrorHandler,
setupHonoErrorHandler,
setupKoaErrorHandler,
setUser,
spanStreamingIntegration,
spanToBaggageHeader,
spanToJSON,
spanToStaticSpanJSON,
spanToTraceHeader,
spotlightIntegration,
startInactiveSpan,
Expand All @@ -171,13 +162,12 @@ export {
trpcMiddleware,
unleashIntegration,
updateSpanName,
experimentalUseDiagnosticsChannelInjection,
validateOpenTelemetrySetup,
winterCGHeadersToDict,
withActiveSpan,
withIsolationScope,
withMonitor,
withScope,
withStaticSpan,
withStreamedSpan,
wrapMcpServerWithSentry,
zodErrorsIntegration,
Expand Down
12 changes: 11 additions & 1 deletion src/main/integrations/child-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ export interface ChildProcessOptions extends NodeChildProcessOptions {
breadcrumbs: Readonly<ExitReason[]>;
/** Child process events that generate Sentry events */
events: Readonly<ExitReason[]>;
/**
* Whether to also capture Sentry logs for child process events
*
* Logs are only sent if they have not been disabled via the `enableLogs` client option.
*
* default: false
*/
captureLogs: boolean;
}

const DEFAULT_OPTIONS: ChildProcessOptions = {
breadcrumbs: EXIT_REASONS,
events: ['abnormal-exit', 'launch-failed', 'integrity-failure'],
captureLogs: false,
};

type LogFn = (msg: ParameterizedString, attributes: Log['attributes']) => void;
Expand Down Expand Up @@ -63,6 +72,7 @@ export const childProcessIntegration = defineIntegration((userOptions: Partial<O
const options: ChildProcessOptions = {
breadcrumbs: Array.isArray(breadcrumbs) ? breadcrumbs : breadcrumbs === false ? [] : DEFAULT_OPTIONS.breadcrumbs,
events: Array.isArray(events) ? events : events === false ? [] : DEFAULT_OPTIONS.events,
captureLogs: !!userOptions.captureLogs,
};

return {
Expand All @@ -76,7 +86,7 @@ export const childProcessIntegration = defineIntegration((userOptions: Partial<O
// only hook these events if we're after more than just the unresponsive event
if (allReasons.length > 0) {
const clientOptions = client.getOptions() as ElectronMainOptions;
const enableLogs = !!clientOptions?.enableLogs;
const enableLogs = options.captureLogs && clientOptions?.enableLogs !== false;

app.on('child-process-gone', (_, details) => {
const { reason } = details;
Expand Down
14 changes: 12 additions & 2 deletions src/main/integrations/electron-breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ export interface ElectronBreadcrumbsOptions<T> {
* default: false
*/
captureWindowTitles: boolean;

/**
* Whether to also capture Sentry logs for Electron events
*
* Logs are only sent if they have not been disabled via the `enableLogs` client option.
*
* default: false
*/
captureLogs: boolean;
}

const DEFAULT_OPTIONS: ElectronBreadcrumbsOptions<EventFunction> = {
Expand All @@ -81,6 +90,7 @@ const DEFAULT_OPTIONS: ElectronBreadcrumbsOptions<EventFunction> = {
screen: () => true,
powerMonitor: () => true,
captureWindowTitles: false,
captureLogs: false,
};

/** Converts all user supplied options to function | false */
Expand All @@ -89,7 +99,7 @@ export function normalizeOptions(
): Partial<ElectronBreadcrumbsOptions<EventFunction | false>> {
return (Object.keys(options) as (keyof ElectronBreadcrumbsOptions<EventTypes>)[]).reduce(
(obj, k) => {
if (k === 'captureWindowTitles') {
if (k === 'captureWindowTitles' || k === 'captureLogs') {
obj[k] = !!options[k];
} else {
const val: EventTypes = options[k];
Expand Down Expand Up @@ -120,7 +130,7 @@ export const electronBreadcrumbsIntegration = defineIntegration(
name: 'ElectronBreadcrumbs',
setup(client: NodeClient) {
const clientOptions = client.getOptions() as ElectronMainOptions | undefined;
const enableLogs = !!clientOptions?.enableLogs;
const enableLogs = options.captureLogs && clientOptions?.enableLogs !== false;

function patchEventEmitter(
emitter: NodeJS.EventEmitter | WebContents | BrowserWindow,
Expand Down
13 changes: 11 additions & 2 deletions src/main/integrations/net-breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export interface NetOptions {
* Defaults to: true
*/
tracing?: ShouldTraceFn | boolean;
/**
* Whether to also capture Sentry logs for net requests
*
* Logs are only sent if they have not been disabled via the `enableLogs` client option.
*
* Defaults to: false
*/
captureLogs?: boolean;
}

/**
Expand Down Expand Up @@ -98,9 +106,10 @@ type RequestMethod = (opt: RequestOptions, ...args: unknown[]) => ClientRequest;
type WrappedRequestMethodFactory = (original: RequestMethod) => RequestMethod;

function createWrappedRequestFactory(
{ tracing, breadcrumbs }: NetOptions,
{ tracing, breadcrumbs, captureLogs }: NetOptions,
{ enableLogs, tracePropagationTargets, propagateTraceparent }: ClientOptions,
): WrappedRequestMethodFactory {
const logsEnabled = !!captureLogs && enableLogs !== false;
// We're caching results so we don't have to recompute regexp every time we create a request.
const createSpanUrlMap = new LRUMap<string, boolean>(100);
const headersUrlMap = new LRUMap<string, boolean>(100);
Expand Down Expand Up @@ -176,7 +185,7 @@ function createWrappedRequestFactory(
},
);

if (!enableLogs) {
if (!logsEnabled) {
return;
}

Expand Down
20 changes: 4 additions & 16 deletions src/main/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import {
eventFiltersIntegration,
functionToStringIntegration,
getCurrentScope,
initOpenTelemetry,
linkedErrorsIntegration,
localVariablesIntegration,
nativeNodeFetchIntegration,
NodeClient,
nodeContextIntegration,
onUnhandledRejectionIntegration,
setNodeAsyncContextStrategy,
} from '@sentry/node';
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils';
import type { Session, WebContents } from 'electron';
import { session } from 'electron';
import { IPCMode } from '../common/ipc.js';
Expand Down Expand Up @@ -155,12 +154,6 @@ export type ElectronMainOptions = Pick<
Omit<ElectronMainOptionsInternal, 'getSessions' | 'ipcMode' | 'ipcNamespace'> &
NodeOptions;

function resolveUserInfo(options: ElectronMainOptions): boolean {
const base = options.dataCollection != null ? true : !!options.sendDefaultPii;
const dc = options.dataCollection ?? {};
return dc.userInfo ?? base;
}

/**
* Initialize Sentry in the Electron main process
*/
Expand All @@ -171,7 +164,7 @@ export function init(userOptions: ElectronMainOptions): void {
throw new Error('Sentry Electron SDK requires Electron 23 or higher');
}

const inferIpAddress = resolveUserInfo(userOptions);
const inferIpAddress = userOptions.dataCollection?.userInfo ?? true;

const optionsWithDefaults = {
_metadata: { sdk: getSdkInfo(inferIpAddress) },
Expand Down Expand Up @@ -200,12 +193,13 @@ export function init(userOptions: ElectronMainOptions): void {
removeRedundantIntegrations(options);
configureUtilityProcessIPC();

setNodeAsyncContextStrategy();
const asyncLocalStorage = setAsyncLocalStorageAsyncContextStrategy();

const scope = getCurrentScope();
scope.update(options.initialScope);

const client = new NodeClient(options);
client.asyncLocalStorageLookup = { asyncLocalStorage };
Comment thread
timfish marked this conversation as resolved.

if (inferIpAddress) {
client.on('beforeSendSession', addAutoIpAddressToSession);
Expand All @@ -223,12 +217,6 @@ export function init(userOptions: ElectronMainOptions): void {
client.init();

configureIPC(client, options);

// If users opt-out of this, they _have_ to set up OpenTelemetry themselves
// There is no way to use this SDK without OpenTelemetry!
if (!options.skipOpenTelemetrySetup) {
initOpenTelemetry(client);
}
}

/** A list of integrations which cause default integrations to be removed */
Expand Down
13 changes: 3 additions & 10 deletions src/renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export {
contextLinesIntegration,
continueTrace,
createConsolaReporter,
createLangChainCallbackHandler,
createTransport,
createUserFeedbackEnvelope,
dedupeIntegration,
Expand Down Expand Up @@ -79,16 +78,7 @@ export {
growthbookIntegration,
httpClientIntegration,
httpContextIntegration,
// eslint-disable-next-line deprecation/deprecation
inboundFiltersIntegration,
instrumentAnthropicAiClient,
instrumentCreateReactAgent,
instrumentGoogleGenAIClient,
instrumentLangChainEmbeddings,
instrumentLangGraph,
instrumentOpenAiClient,
instrumentOutgoingRequests,
instrumentStateGraph,
instrumentSupabaseClient,
isBotUserAgent,
isEnabled,
Expand Down Expand Up @@ -132,6 +122,7 @@ export {
spanStreamingIntegration,
spanToBaggageHeader,
spanToJSON,
spanToStaticSpanJSON,
spanToTraceHeader,
spotlightBrowserIntegration,
startBrowserTracingNavigationSpan,
Expand All @@ -146,13 +137,15 @@ export {
suppressTracing,
thirdPartyErrorFilterIntegration,
uiProfiler,
userTimingIntegration,
unleashIntegration,
updateSpanName,
webVitalsIntegration,
webWorkerIntegration,
withActiveSpan,
withIsolationScope,
withScope,
withStaticSpan,
withStreamedSpan,
viewHierarchyIntegration,
zodErrorsIntegration,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface ElectronRendererOptions extends Partial<ElectronRendererOptionsInterna
export function init<O extends ElectronRendererOptions>(
options: ElectronRendererOptions & O = {} as ElectronRendererOptions & O,
// This parameter name ensures that TypeScript error messages contain a hint for fixing SDK version mismatches
originalInit: (if_you_get_a_typescript_error_ensure_sdks_use_version_v10_70_0: O) => void = browserInit,
originalInit: (if_you_get_a_typescript_error_ensure_sdks_use_version_v11_0_0_alpha_1: O) => void = browserInit,
): void {
// Ensure the browser SDK is only init'ed once.
if (window?.__SENTRY__RENDERER_INIT__) {
Expand Down
Loading
Loading