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

To help you get started, we’ve selected a few @sentry/core 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-react-native / src / js / backend.ts View on Github external
this._browserBackend = new BrowserBackend(_options);

    // This is a workaround for now using fetch on RN, this is a known issue in react-native and only generates a warning
    YellowBox.ignoreWarnings(["Require cycle:"]);

    // tslint:disable: no-unsafe-any
    if (
      RNSentry &&
      RNSentry.nativeClientAvailable &&
      _options.enableNative !== false
    ) {
      RNSentry.startWithDsnString(_options.dsn, _options).then(() => {
        RNSentry.setLogLevel(_options.debug ? 2 : 1);
      });
      // Workaround for setting release/dist on native
      const scope = getCurrentHub().getScope();
      if (scope) {
        scope.addScopeListener(scope =>
          RNSentry.extraUpdated((scope as any)._extra)
        );
      }
    } else {
      if (__DEV__ && _options.enableNativeNagger) {
        Alert.alert(
          "Sentry",
          "Warning, could not connect to Sentry native SDK.\nIf you do not want to use the native component please pass `enableNative: false` in the options.\nVisit: https://docs.sentry.io/platforms/react-native/#linking for more details."
        );
      }
    }
    // tslint:enable: no-unsafe-any
  }
github getsentry / sentry-javascript / packages / browser / src / integrations / instrumenthandlers.ts View on Github external
function addSentryBreadcrumb(serializedData: string): void {
  // There's always something that can go wrong with deserialization...
  try {
    const event = JSON.parse(serializedData);
    getCurrentHub().addBreadcrumb(
      {
        category: 'sentry',
        event_id: event.event_id,
        level: event.level || Severity.fromString('error'),
        message: getEventDescription(event),
      },
      {
        event,
      },
    );
  } catch (_oO) {
    logger.error('Error while adding sentry type breadcrumb');
  }
}
github getsentry / sentry-javascript / packages / node / src / integrations / http.ts View on Github external
return function(this: SentryRequest, event: string, response: http.ServerResponse): any {
    // I'm not sure why but Node.js (at least in v8.X)
    // is emitting all events twice :|
    if (lastResponse === undefined || lastResponse !== response) {
      lastResponse = response;
    } else {
      return origEmit.apply(this, arguments);
    }

    const client = getCurrentHub().getClient();
    if (client) {
      const dsn = client.getDsn();

      const isInterestingEvent = event === 'response' || event === 'error';
      const isNotSentryRequest = dsn && this.__ravenBreadcrumbUrl && this.__ravenBreadcrumbUrl.indexOf(dsn.host) === -1;

      if (isInterestingEvent && isNotSentryRequest && getCurrentHub().getIntegration(Http)) {
        getCurrentHub().addBreadcrumb(
          {
            category: 'http',
            data: {
              method: this.method,
              status_code: response.statusCode,
              url: this.__ravenBreadcrumbUrl,
            },
            type: 'http',
github getsentry / sentry-react-native / src / js / integrations / reactnative.ts View on Github external
addGlobalEventProcessor((event: Event) => {
      const self = getCurrentHub().getIntegration(ReactNative);
      if (self) {
        // getCurrentHub().configureScope(scope => {
        //   scope.addScopeListener();
        // });
      }
      return event;
    });
  }
github getsentry / sentry-react-native / src / js / integrations / reactnativeerrorhandlers.ts View on Github external
ErrorUtils.setGlobalHandler((error: any, isFatal?: boolean) => {
        // We want to handle fatals, but only in production mode.
        const shouldHandleFatal = isFatal && !global.__DEV__;
        if (shouldHandleFatal) {
          if (handlingFatal) {
            logger.log(
              "Encountered multiple fatals in a row. The latest:",
              error
            );
            return;
          }
          handlingFatal = true;
        }

        getCurrentHub().withScope(scope => {
          if (isFatal) {
            scope.setLevel(Severity.Fatal);
          }
          getCurrentHub().captureException(error, {
            originalException: error
          });
        });

        const client = getCurrentHub().getClient();
        // If in dev, we call the default handler anyway and hope the error will be sent
        // Just for a better dev experience
        if (client && !__DEV__) {
          client.flush(client.getOptions().shutdownTimeout || 2000).then(() => {
            defaultHandler(error, isFatal);
          });
        } else {
github getsentry / sentry-javascript / packages / node / src / handlers.ts View on Github external
export function logAndExitProcess(error: Error): void {
  console.error(error && error.stack ? error.stack : error);

  const client = getCurrentHub().getClient();

  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!');
      }
github getsentry / sentry-react-native / src / js / integrations / reactnativeerrorhandlers.ts View on Github external
getCurrentHub().withScope(scope => {
          if (isFatal) {
            scope.setLevel(Severity.Fatal);
          }
          getCurrentHub().captureException(error, {
            originalException: error
          });
        });
github getsentry / sentry-javascript / packages / node / src / integrations / console.ts View on Github external
return function(): any {
        if (getCurrentHub().getIntegration(Console)) {
          getCurrentHub().addBreadcrumb(
            {
              category: 'console',
              level: sentryLevel,
              message: util.format.apply(undefined, arguments),
            },
            {
              input: [...arguments],
              level,
            },
          );
        }

        originalConsoleLevel.apply(originalModule, arguments);
      };
    });
github getsentry / sentry-javascript / packages / node / src / integrations / linkederrors.ts View on Github external
addGlobalEventProcessor((event: Event, hint?: EventHint) => {
      const self = getCurrentHub().getIntegration(LinkedErrors);
      if (self) {
        return (self.handler(event, hint) as unknown) as PromiseLike;
      }
      return event;
    });
  }
github getsentry / sentry-javascript / packages / browser / src / integrations / linkederrors.ts View on Github external
addGlobalEventProcessor((event: Event, hint?: EventHint) => {
      const self = getCurrentHub().getIntegration(LinkedErrors);
      if (self) {
        return self._handler(event, hint);
      }
      return event;
    });
  }