How to use @sentry/hub - 10 common examples

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 getsentry / sentry-javascript / packages / node / src / sdk.ts View on Github external
// Prefer env var over global
    if (process.env.SENTRY_RELEASE) {
      options.release = process.env.SENTRY_RELEASE;
    }
    // This supports the variable that sentry-webpack-plugin injects
    else if (global.SENTRY_RELEASE && global.SENTRY_RELEASE.id) {
      options.release = global.SENTRY_RELEASE.id;
    }
  }

  if (options.environment === undefined && process.env.SENTRY_ENVIRONMENT) {
    options.environment = process.env.SENTRY_ENVIRONMENT;
  }

  if (domain.active) {
    setHubOnCarrier(getMainCarrier(), getCurrentHub());
  }

  initAndBind(NodeClient, options);
}
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;
    });
  }

@sentry/hub

Sentry hub which handles global state managment.

MIT
Latest version published 8 months ago

Package Health Score

97 / 100
Full package analysis