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
});
}
}
}
// Prefer env var over global
if (process.env.SENTRY_RELEASE) {
options.release = process.env.SENTRY_RELEASE;
}
// This supports the variable that sentry-webpack-plugin injects
else if (global.SENTRY_RELEASE && global.SENTRY_RELEASE.id) {
options.release = global.SENTRY_RELEASE.id;
}
}
if (options.environment === undefined && process.env.SENTRY_ENVIRONMENT) {
options.environment = process.env.SENTRY_ENVIRONMENT;
}
if (domain.active) {
setHubOnCarrier(getMainCarrier(), getCurrentHub());
}
initAndBind(NodeClient, options);
}
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;
});
}