How to use @sentry/core - 10 common examples

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-react-native / src / js / integrations / devicecontext.ts View on Github external
public setupOnce(): void {
    addGlobalEventProcessor(async (event: Event) => {
      const self = getCurrentHub().getIntegration(DeviceContext);
      if (!self) {
        return event;
      }

      try {
        // tslint:disable-next-line: no-unsafe-any
        const deviceContexts = await RNSentry.deviceContexts();
        event.contexts = { ...deviceContexts, ...event.contexts };
      } catch (_Oo) {
        // Something went wrong, we just continue
      }

      return event;
    });
  }
github getsentry / sentry-react-native / src / js / integrations / reactnative.ts View on Github external
public setupOnce(): void {
    this._handleUnhandledRejections();
    this._handleOnError();

    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 / debugsymbolicator.ts View on Github external
public setupOnce(): void {
    // tslint:disable-next-line: cyclomatic-complexity
    addGlobalEventProcessor(async (event: Event, hint?: EventHint) => {
      const self = getCurrentHub().getIntegration(DebugSymbolicator);
      // tslint:disable: strict-comparisons
      if (!self || hint === undefined || hint.originalException === undefined) {
        return event;
      }

      const reactError = hint.originalException as ReactNativeError;

      // tslint:disable: no-unsafe-any
      const parseErrorStack = require("react-native/Libraries/Core/Devtools/parseErrorStack");
      const stack = parseErrorStack(reactError);

      // Ideally this should go into contexts but android sdk doesn't support it
      event.extra = {
        ...event.extra,
        componentStack: reactError.componentStack,
github getsentry / sentry-javascript / packages / browser / src / integrations / useragent.ts View on Github external
public setupOnce(): void {
    addGlobalEventProcessor((event: Event) => {
      if (getCurrentHub().getIntegration(UserAgent)) {
        if (!global.navigator || !global.location) {
          return event;
        }

        // Request Interface: https://docs.sentry.io/development/sdk-dev/event-payloads/request/
        const request = event.request || {};
        request.url = request.url || global.location.href;
        request.headers = request.headers || {};
        request.headers['User-Agent'] = global.navigator.userAgent;

        return {
          ...event,
          request,
        };
      }
github getsentry / sentry-react-native / src / js / integrations / release.ts View on Github external
public setupOnce(): void {
    addGlobalEventProcessor(async (event: Event) => {
      const self = getCurrentHub().getIntegration(Release);
      if (!self) {
        return event;
      }

      try {
        // tslint:disable-next-line: no-unsafe-any
        const release = (await RNSentry.fetchRelease()) as {
          build: string;
          id: string;
          version: string;
        };
        if (release) {
          event.release = `${release.id}-${release.version}`;
          event.dist = `${release.build}`;
        }