How to use the @sentry/hub.getCurrentHub function in @sentry/hub

To help you get started, we’ve selected a few @sentry/hub examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github getsentry / sentry-javascript / packages / minimal / src / index.ts View on Github external
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.`);
}
github getsentry / sentry-javascript / packages / opentracing / src / tracer.ts View on Github external
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
      });
    }
  }
}
github mentos1386 / nest-raven / test / http / global.e2e.spec.ts View on Github external
beforeEach(() => {
    global.__SENTRY__ = {
      hub: undefined,
    };
    client.captureException.mockClear();
    getCurrentHub().pushScope();
    getCurrentHub().bindClient(client);
  });
github mentos1386 / nest-raven / test / http / method.e2e.spec.ts View on Github external
beforeEach(() => {
    global.__SENTRY__ = {
      hub: undefined,
    };
    client.captureException.mockClear();
    getCurrentHub().pushScope();
    getCurrentHub().bindClient(client);
  });
github mentos1386 / nest-raven / test / http / method.e2e.spec.ts View on Github external
beforeEach(() => {
    global.__SENTRY__ = {
      hub: undefined,
    };
    client.captureException.mockClear();
    getCurrentHub().pushScope();
    getCurrentHub().bindClient(client);
  });
github getsentry / sentry-javascript / packages / node / src / hub.ts View on Github external
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;
}
github getsentry / sentry-javascript / packages / core / src / integrations / inboundfilters.ts View on Github external
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;
    });
  }
github getsentry / sentry-javascript / packages / core / src / integrations / inboundfilters.ts View on Github external
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;
    });
  }
github getsentry / sentry-javascript / packages / core / src / sdk.ts View on Github external
export function initAndBind(clientClass: ClientClass, options: O): void {
  if (options.debug === true) {
    logger.enable();
  }
  getCurrentHub().bindClient(new clientClass(options));
}

@sentry/hub

Sentry hub which handles global state managment.

MIT
Latest version published 8 months ago

Package Health Score

97 / 100
Full package analysis