How to use the @sentry/utils.fill 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 / integrations / src / tracing.ts View on Github external
fill(
      xhrproto,
      'open',
      originalOpen =>
        function(this: XMLHttpRequest, ...args: any[]): void {
          // @ts-ignore
          const self = getCurrentHub().getIntegration(Tracing);
          if (self) {
            self._xhrUrl = args[1] as string;
          }
          // tslint:disable-next-line: no-unsafe-any
          return originalOpen.apply(this, args);
        },
    );

    fill(
      xhrproto,
      'send',
      originalSend =>
        function(this: XMLHttpRequest, ...args: any[]): void {
          // @ts-ignore
          const self = getCurrentHub().getIntegration(Tracing);
          if (self && self._xhrUrl && self._options.tracingOrigins) {
            const url = self._xhrUrl;
            const headers = getCurrentHub().traceHeaders();
            // tslint:disable-next-line: prefer-for-of
            const isWhitelisted = self._options.tracingOrigins.some((origin: string | RegExp) =>
              isMatchingPattern(url, origin),
            );

            if (isWhitelisted && this.setRequestHeader) {
              Object.keys(headers).forEach(key => {
github getsentry / sentry-javascript / packages / browser / src / integrations / breadcrumbs.ts View on Github external
if (url) {
          // coerce to string (this is what pushState does)
          const to = String(url);
          const handlerData = {
            from: lastHref,
            to,
          };
          // keep track of the current URL state, as we always receive only the updated state
          lastHref = to;
          triggerHandlers(handlerData);
        }
        return originalHistoryFunction.apply(this, args);
      };
    }

    fill(global.history, 'pushState', historyReplacementFunction);
    fill(global.history, 'replaceState', historyReplacementFunction);
  }
github getsentry / sentry-javascript / packages / node / src / integrations / console.ts View on Github external
public setupOnce(): void {
    const nativeModule = require('module');
    fill(nativeModule, '_load', loadWrapper(nativeModule));
    // special case: since console is built-in and app-level code won't require() it, do that here
    require('console');
  }
}
github getsentry / sentry-javascript / packages / integrations / src / tracing.ts View on Github external
private _traceXHR(getCurrentHub: () => Hub): void {
    if (!('XMLHttpRequest' in getGlobalObject())) {
      return;
    }

    const xhrproto = XMLHttpRequest.prototype;

    fill(
      xhrproto,
      'open',
      originalOpen =>
        function(this: XMLHttpRequest, ...args: any[]): void {
          // @ts-ignore
          const self = getCurrentHub().getIntegration(Tracing);
          if (self) {
            self._xhrUrl = args[1] as string;
          }
          // tslint:disable-next-line: no-unsafe-any
          return originalOpen.apply(this, args);
        },
    );

    fill(
      xhrproto,
github getsentry / sentry-javascript / packages / browser / src / integrations / breadcrumbs.ts View on Github external
['debug', 'info', 'warn', 'error', 'log', 'assert'].forEach(function(level: string): void {
      if (!(level in global.console)) {
        return;
      }

      fill(global.console, level, function(originalConsoleLevel: () => any): Function {
        return function(...args: any[]): void {
          const handlerData = {
            args,
            level,
          };
          triggerHandlers(handlerData);

          // this fails for some browsers. :(
          if (originalConsoleLevel) {
            Function.prototype.apply.call(originalConsoleLevel, global.console, args);
          }
        };
      });
    });
  }
github getsentry / sentry-javascript / packages / browser / src / integrations / trycatch.ts View on Github external
public setupOnce(): void {
    this._ignoreOnError = this._ignoreOnError;

    const global = getGlobalObject();

    fill(global, 'setTimeout', this._wrapTimeFunction.bind(this));
    fill(global, 'setInterval', this._wrapTimeFunction.bind(this));
    fill(global, 'requestAnimationFrame', this._wrapRAF.bind(this));

    if ('XMLHttpRequest' in global) {
      fill(XMLHttpRequest.prototype, 'send', this._wrapXHR.bind(this));
    }

    [
      'EventTarget',
      'Window',
      'Node',
      'ApplicationCache',
      'AudioTrackList',
      'ChannelMergerNode',
      'CryptoOperation',
      'EventSource',
github getsentry / sentry-javascript / packages / browser / src / integrations / trycatch.ts View on Github external
public setupOnce(): void {
    this._ignoreOnError = this._ignoreOnError;

    const global = getGlobalObject();

    fill(global, 'setTimeout', this._wrapTimeFunction.bind(this));
    fill(global, 'setInterval', this._wrapTimeFunction.bind(this));
    fill(global, 'requestAnimationFrame', this._wrapRAF.bind(this));

    if ('XMLHttpRequest' in global) {
      fill(XMLHttpRequest.prototype, 'send', this._wrapXHR.bind(this));
    }

    [
      'EventTarget',
      'Window',
      'Node',
      'ApplicationCache',
      'AudioTrackList',
      'ChannelMergerNode',
      'CryptoOperation',
      'EventSource',
      'FileReader',
      'HTMLUnknownElement',
      'IDBDatabase',
      'IDBRequest',
      'IDBTransaction',
github getsentry / sentry-javascript / packages / browser / src / integrations / breadcrumbs.ts View on Github external
function wrapProp(prop: XMLHttpRequestProp, xhr: XMLHttpRequest): void {
      if (prop in xhr && typeof xhr[prop] === 'function') {
        fill(xhr, prop, original =>
          wrap(original, {
            mechanism: {
              data: {
                function: prop,
                handler: (original && original.name) || '',
              },
              handled: true,
              type: 'instrument',
            },
          }),
        );
      }
    }
github getsentry / sentry-javascript / packages / node / src / integrations / console.ts View on Github external
return function(level: string): any {
    if (!(level in originalModule)) {
      return;
    }

    fill(originalModule, level, function(originalConsoleLevel: () => any): any {
      let sentryLevel: Severity;

      switch (level) {
        case 'debug':
          sentryLevel = Severity.Debug;
          break;
        case 'error':
          sentryLevel = Severity.Error;
          break;
        case 'info':
          sentryLevel = Severity.Info;
          break;
        case 'warn':
          sentryLevel = Severity.Warning;
          break;
        default: