How to use the @sentry/utils.normalize function in @sentry/utils

To help you get started, we’ve selected a few @sentry/utils 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 / browser / src / integrations / instrumenthandlers.ts View on Github external
function consoleBreadcrumb(handlerData: { [key: string]: any }): void {
  const breadcrumb = {
    category: 'console',
    data: {
      extra: {
        arguments: normalize(handlerData.args, 3),
      },
      logger: 'console',
    },
    level: Severity.fromString(handlerData.level),
    message: safeJoin(handlerData.args, ' '),
  };

  if (handlerData.level === 'assert') {
    if (handlerData.args[0] === false) {
      breadcrumb.message = `Assertion failed: ${safeJoin(handlerData.args.slice(1), ' ') || 'console.assert'}`;
      breadcrumb.data.extra.arguments = normalize(handlerData.args.slice(1), 3);
    } else {
      // Don't capture a breadcrumb for passed assertions
      return;
    }
  }
github getsentry / sentry-javascript / packages / browser / src / integrations / instrumenthandlers.ts View on Github external
const breadcrumb = {
    category: 'console',
    data: {
      extra: {
        arguments: normalize(handlerData.args, 3),
      },
      logger: 'console',
    },
    level: Severity.fromString(handlerData.level),
    message: safeJoin(handlerData.args, ' '),
  };

  if (handlerData.level === 'assert') {
    if (handlerData.args[0] === false) {
      breadcrumb.message = `Assertion failed: ${safeJoin(handlerData.args.slice(1), ' ') || 'console.assert'}`;
      breadcrumb.data.extra.arguments = normalize(handlerData.args.slice(1), 3);
    } else {
      // Don't capture a breadcrumb for passed assertions
      return;
    }
  }

  getCurrentHub().addBreadcrumb(breadcrumb, {
    input: handlerData.args,
    level: handlerData.level,
  });
}
github getsentry / sentry-javascript / packages / integrations / src / captureconsole.ts View on Github external
hub.withScope(scope => {
            scope.setLevel(Severity.fromString(level));
            scope.setExtra('arguments', normalize(args, 3));
            scope.addEventProcessor(event => {
              event.logger = 'console';
              return event;
            });

            let message = safeJoin(args, ' ');
            if (level === 'assert') {
              if (args[0] === false) {
                message = `Assertion failed: ${safeJoin(args.slice(1), ' ') || 'console.assert'}`;
                scope.setExtra('arguments', normalize(args.slice(1), 3));
                hub.captureMessage(message);
              }
            } else {
              hub.captureMessage(message);
            }
          });
        }
github getsentry / sentry-javascript / packages / integrations / src / captureconsole.ts View on Github external
hub.withScope(scope => {
            scope.setLevel(Severity.fromString(level));
            scope.setExtra('arguments', normalize(args, 3));
            scope.addEventProcessor(event => {
              event.logger = 'console';
              return event;
            });

            let message = safeJoin(args, ' ');
            if (level === 'assert') {
              if (args[0] === false) {
                message = `Assertion failed: ${safeJoin(args.slice(1), ' ') || 'console.assert'}`;
                scope.setExtra('arguments', normalize(args.slice(1), 3));
                hub.captureMessage(message);
              }
            } else {
              hub.captureMessage(message);
            }
          });
github getsentry / sentry-javascript / packages / hub / src / scope.ts View on Github external
public setContext(name: string, context: { [key: string]: any } | null): this {
    this._context[name] = context ? normalize(context) : undefined;
    this._notifyScopeListeners();
    return this;
  }
github getsentry / sentry-javascript / packages / hub / src / scope.ts View on Github external
public setTags(tags: { [key: string]: string }): this {
    this._tags = {
      ...this._tags,
      ...normalize(tags),
    };
    this._notifyScopeListeners();
    return this;
  }
github getsentry / sentry-javascript / packages / integrations / src / extraerrordata.ts View on Github external
public enhanceEventWithErrorData(event: Event, hint?: EventHint): Event {
    if (!hint || !hint.originalException || !isError(hint.originalException)) {
      return event;
    }
    const name = (hint.originalException as ExtendedError).name || hint.originalException.constructor.name;

    const errorData = this._extractErrorData(hint.originalException as ExtendedError);

    if (errorData) {
      let contexts = {
        ...event.contexts,
      };

      const normalizedErrorData = normalize(errorData, this._options.depth);
      if (isPlainObject(normalizedErrorData)) {
        contexts = {
          ...event.contexts,
          [name]: {
            ...normalizedErrorData,
          },
        };
      }

      return {
        ...event,
        contexts,
      };
    }

    return event;
github getsentry / sentry-javascript / packages / hub / src / scope.ts View on Github external
public addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): this {
    const timestamp = timestampWithMs();
    const mergedBreadcrumb = { timestamp, ...breadcrumb };

    this._breadcrumbs =
      maxBreadcrumbs !== undefined && maxBreadcrumbs >= 0
        ? [...this._breadcrumbs, normalize(mergedBreadcrumb)].slice(-maxBreadcrumbs)
        : [...this._breadcrumbs, normalize(mergedBreadcrumb)];
    this._notifyScopeListeners();
    return this;
  }
github getsentry / sentry-javascript / packages / hub / src / scope.ts View on Github external
public setExtras(extra: { [key: string]: any }): this {
    this._extra = {
      ...this._extra,
      ...normalize(extra),
    };
    this._notifyScopeListeners();
    return this;
  }
github getsentry / sentry-javascript / packages / hub / src / scope.ts View on Github external
public setUser(user: User | null): this {
    this._user = normalize(user);
    this._notifyScopeListeners();
    return this;
  }