本文整理汇总了TypeScript中@sentry/core.getCurrentHub函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getCurrentHub函数的具体用法?TypeScript getCurrentHub怎么用?TypeScript getCurrentHub使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getCurrentHub函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: showReportDialog
export function showReportDialog(options: ReportDialogOptions = {}): void {
if (!options.eventId) {
options.eventId = getCurrentHub().lastEventId();
}
const client = getCurrentHub().getClient<BrowserClient>();
if (client) {
client.showReportDialog(options);
}
}
示例2: close
export async function close(timeout?: number): Promise<boolean> {
const client = getCurrentHub().getClient<NodeClient>();
if (client) {
return client.close(timeout);
}
return Promise.reject(false);
}
示例3: flush
export function flush(timeout?: number): Promise<boolean> {
const client = getCurrentHub().getClient<BrowserClient>();
if (client) {
return client.flush(timeout);
}
return Promise.reject(false);
}
示例4: _htmlTreeAsString
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,
},
);
};
示例5: getCurrentHub
d2.run(() => {
const hub = getCurrentHub();
hub.getStack().push({ client: 'local' });
expect(hub.getStack()[1]).toEqual({ client: 'local' });
setTimeout(() => {
d2done = true;
if (d1done) {
done();
}
});
});
示例6: test
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);
});
});
示例7: eventFromException
/**
* @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),
);
}
示例8: defaultOnFatalError
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);
}),
);
}
示例9: init
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);
}