Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function callOnHub(method: string, ...args: any[]): T {
const hub = getCurrentHub();
if (hub && hub[method as keyof Hub]) {
// tslint:disable-next-line:no-unsafe-any
return (hub[method as keyof Hub] as any)(...args);
}
throw new Error(`No hub defined or ${method} was not found on the hub, please open a bug report.`);
}
public flush(): void {
const finishedSpans = this._spans.filter((span: Span) => span.isFinished() && !span.isFlushed());
if (finishedSpans.length) {
getCurrentHub().captureEvent({
spans: finishedSpans.map((span: Span) => span.flush()),
type: 'none', // This ensures a Sentry event will not be created on the server
});
}
}
}
beforeEach(() => {
global.__SENTRY__ = {
hub: undefined,
};
client.captureException.mockClear();
getCurrentHub().pushScope();
getCurrentHub().bindClient(client);
});
afterEach(() => {
getCurrentHub().popScope();
})
beforeEach(() => {
global.__SENTRY__ = {
hub: undefined,
};
client.captureException.mockClear();
getCurrentHub().pushScope();
getCurrentHub().bindClient(client);
});
beforeEach(() => {
global.__SENTRY__ = {
hub: undefined,
};
client.captureException.mockClear();
getCurrentHub().pushScope();
getCurrentHub().bindClient(client);
});
export function getCurrentHub(): Hub {
const globalHub = getCurrentHubBase();
if (!domain.active) {
return globalHub;
}
let carrier = domain.active.__SENTRY__;
if (!carrier) {
domain.active.__SENTRY__ = carrier = {};
}
if (!carrier.hub) {
const top = globalHub.getStackTop();
carrier.hub = top ? new Hub(top.client, top.scope) : new Hub();
}
return carrier.hub;
}
addGlobalEventProcessor((event: Event) => {
const hub = getCurrentHub();
if (!hub) {
return event;
}
const self = hub.getIntegration(InboundFilters);
if (self) {
const client = hub.getClient();
const clientOptions = client ? client.getOptions() : {};
const options = self._mergeOptions(clientOptions);
if (self._shouldDropEvent(event, options)) {
return null;
}
}
return event;
});
}
addGlobalEventProcessor((event: Event) => {
const hub = getCurrentHub();
if (!hub) {
return event;
}
const self = hub.getIntegration(InboundFilters);
if (self) {
const client = hub.getClient();
const clientOptions = client ? client.getOptions() : {};
const options = self._mergeOptions(clientOptions);
if (self._shouldDropEvent(event, options)) {
return null;
}
}
return event;
});
}
export function initAndBind(clientClass: ClientClass, options: O): void {
if (options.debug === true) {
logger.enable();
}
getCurrentHub().bindClient(new clientClass(options));
}