Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
35 changes: 35 additions & 0 deletions packages/node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import type { SessionStatus, StackParser } from '@sentry/types';
import {
createStackParser,
GLOBAL_OBJ,
logger,
nodeStackLineParser,
serializeEnvelope,
stackParserFromStackParserOptions,
tracingContextFromHeaders,
} from '@sentry/utils';
Expand Down Expand Up @@ -179,6 +181,39 @@ export function init(options: NodeOptions = {}): void {
}

updateScopeFromEnvVariables();

connectToSpotlight(options);
}

function connectToSpotlight(options: NodeOptions): void {
if (!options.spotlight) {
return;
}

const spotlightUrl = typeof options.spotlight === 'string' ? options.spotlight : 'http://localhost:8969/stream';

const client = getCurrentHub().getClient();
if (client) {
client.setupIntegrations(true);
let tries = 0;
client.on('beforeEnvelope', envelope => {
if (tries > 3) {
logger.warn('[Spotlight] Disabled Sentry -> Spotlight integration due to too many failed requests');
return;
}
fetch(spotlightUrl, {
method: 'POST',
body: serializeEnvelope(envelope),
headers: {
'Content-Type': 'application/x-sentry-envelope',
},
mode: 'cors',
}).catch(() => {
tries++;
logger.warn('[Spotlight] Failed to send envelope to Spotlight Sidecar');
});
});
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ export interface BaseNodeOptions {

/** Callback that is executed when a fatal global error occurs. */
onFatalError?(this: void, error: Error): void;

/**
* The SDK tries to relay all events to Spotlight in development.
* Either set it to true, or provide a specific Spotlight URL.
*/
spotlight?: boolean | string;
}

/**
Expand Down