export function showReportDialog(options: ReportDialogOptions = {}): void { if (!options.eventId) { options.eventId = getCurrentHub().lastEventId(); } const client = getCurrentHub().getClient<BrowserClient>(); if (client) { client.showReportDialog(options); } }
export async function close(timeout?: number): Promise<boolean> { const client = getCurrentHub().getClient<NodeClient>(); if (client) { return client.close(timeout); } return Promise.reject(false); }
export function flush(timeout?: number): Promise<boolean> { const client = getCurrentHub().getClient<BrowserClient>(); if (client) { return client.flush(timeout); } return Promise.reject(false); }
const captureBreadcrumb = () => { // try/catch both: // - accessing event.target (see getsentry/raven-js#838, #768) // - `htmlTreeAsString` because it's complex, and just accessing the DOM incorrectly // can throw an exception in some circumstances. let target; try { target = event.target ? _htmlTreeAsString(event.target as Node) : _htmlTreeAsString((event as unknown) as Node); } catch (e) { target = '<unknown>'; } if (target.length === 0) { return; } getCurrentHub().addBreadcrumb( { category: `ui.${eventName}`, // e.g. ui.click, ui.input message: target, }, { event, name: eventName, }, ); };
d2.run(() => { const hub = getCurrentHub(); hub.getStack().push({ client: 'local' }); expect(hub.getStack()[1]).toEqual({ client: 'local' }); setTimeout(() => { d2done = true; if (d1done) { done(); } }); });
d1.run(() => { const hub = getCurrentHub(); hub.getStack().push({ client: 'process' }); expect(hub.getStack()[1]).toEqual({ client: 'process' }); // Just in case so we don't have to worry which one finishes first // (although it always should be d2) setTimeout(() => { d1done = true; if (d2done) { done(); } }); });
test('domain hub scope inheritance', () => { const globalHub = getCurrentHub(); globalHub.configureScope(scope => { scope.setExtra('a', 'b'); scope.setTag('a', 'b'); scope.addBreadcrumb({ message: 'a' }); }); const d = domain.create(); d.run(() => { const hub = getCurrentHub(); expect(globalHub).toEqual(hub); }); });
/** * @inheritDoc */ public eventFromException(exception: any, hint?: EventHint): SyncPromise<Event> { let ex: any = exception; const mechanism: Mechanism = { handled: true, type: 'generic', }; if (!isError(exception)) { if (isPlainObject(exception)) { // This will allow us to group events based on top-level keys // which is much better than creating new group when any key/value change const keys = Object.keys(exception as {}).sort(); const message = `Non-Error exception captured with keys: ${keysToEventMessage(keys)}`; getCurrentHub().configureScope(scope => { scope.setExtra('__serialized__', normalizeToSize(exception as {})); }); ex = (hint && hint.syntheticException) || new Error(message); (ex as Error).message = message; } else { // This handles when someone does: `throw "something awesome";` // We use synthesized Error here so we can extract a (rough) stack trace. ex = (hint && hint.syntheticException) || new Error(exception as string); } mechanism.synthetic = true; } return new SyncPromise<Event>((resolve, reject) => parseError(ex as Error, this._options) .then(event => { addExceptionTypeValue(event, undefined, undefined, mechanism); resolve({ ...event, event_id: hint && hint.event_id, }); }) .catch(reject), ); }
export function defaultOnFatalError(error: Error): void { console.error(error && error.stack ? error.stack : error); const client = getCurrentHub().getClient<NodeClient>(); if (client === undefined) { logger.warn('No NodeClient was defined, we are exiting the process now.'); global.process.exit(1); return; } const options = client.getOptions(); const timeout = (options && options.shutdownTimeout && options.shutdownTimeout > 0 && options.shutdownTimeout) || DEFAULT_SHUTDOWN_TIMEOUT; forget( client.close(timeout).then((result: boolean) => { if (!result) { logger.warn('We reached the timeout for emptying the request buffer, still exiting now!'); } global.process.exit(1); }), ); }
export function init(options: NodeOptions = {}): void { if (options.defaultIntegrations === undefined) { options.defaultIntegrations = defaultIntegrations; } if (options.dsn === undefined && process.env.SENTRY_DSN) { options.dsn = process.env.SENTRY_DSN; } if (options.release === undefined && process.env.SENTRY_RELEASE) { options.release = process.env.SENTRY_RELEASE; } if (options.environment === undefined && process.env.SENTRY_ENVIRONMENT) { options.environment = process.env.SENTRY_ENVIRONMENT; } if (domain.active) { setHubOnCarrier(getMainCarrier(), getCurrentHub()); } initAndBind(NodeClient, options); }