@sentry/node

  • Version 7.5.0
  • Published
  • 354 kB
  • 8 dependencies
  • BSD-3-Clause license

Install

npm i @sentry/node
yarn add @sentry/node
pnpm add @sentry/node

Overview

Official Sentry SDK for Node.js

Index

Variables

variable defaultIntegrations

const defaultIntegrations: any[];

    variable defaultStackParser

    const defaultStackParser: StackParser;
    • Node.js stack parser

    variable Integrations

    const Integrations: {
    Console: typeof NodeIntegrations.Console;
    Http: typeof NodeIntegrations.Http;
    OnUncaughtException: typeof NodeIntegrations.OnUncaughtException;
    OnUnhandledRejection: typeof NodeIntegrations.OnUnhandledRejection;
    LinkedErrors: typeof NodeIntegrations.LinkedErrors;
    Modules: typeof NodeIntegrations.Modules;
    ContextLines: typeof NodeIntegrations.ContextLines;
    FunctionToString: any;
    InboundFilters: any;
    };

      Functions

      function addRequestDataToEvent

      addRequestDataToEvent: (
      event: Event,
      req: CrossPlatformRequest,
      options?: Omit<AddRequestDataToEventOptions, 'deps'>
      ) => Event;
      • Add data from the given request to the given event

        (Note that there is no sister function to this one in @sentry/browser, because the whole point of this wrapper is to pass along injected dependencies, which isn't necessary in a browser context. Isomorphic packages like @sentry/nextjs should export directly from @sentry/utils in their browser index file.)

        Parameter event

        The event to which the request data will be added

        Parameter req

        Request object

        Parameter

        options.include Flags to control what data is included

      function close

      close: (timeout?: number) => Promise<boolean>;
      • Call close() on the current client, if there is one. See Client.close.

        Parameter timeout

        Maximum time in ms the client should wait to flush its event queue before shutting down. Omitting this parameter will cause the client to wait until all events are sent before disabling itself.

        Returns

        A promise which resolves to true if the queue successfully drains before the timeout, or false if it doesn't (or if there's no client defined).

      function deepReadDirSync

      deepReadDirSync: (targetDir: string) => string[];
      • Recursively read the contents of a directory.

        Parameter targetDir

        Absolute or relative path of the directory to scan. All returned paths will be relative to this directory.

        Returns

        Array holding all relative paths

      function extractRequestData

      extractRequestData: (
      req: CrossPlatformRequest,
      options?: { include?: string[] }
      ) => ExtractedNodeRequestData;
      • Normalize data from the request object, accounting for framework differences.

        (Note that there is no sister function to this one in @sentry/browser, because the whole point of this wrapper is to inject dependencies, which isn't necessary in a browser context. Isomorphic packages like @sentry/nextjs should export directly from @sentry/utils in their browser index file.)

        Parameter req

        The request object from which to extract data

        Parameter

        options.keys An optional array of keys to include in the normalized data. Defaults to DEFAULT_REQUEST_KEYS if not provided.

        Returns

        An object containing normalized request data

      function flush

      flush: (timeout?: number) => Promise<boolean>;
      • Call flush() on the current client, if there is one. See Client.flush.

        Parameter timeout

        Maximum time in ms the client should wait to flush its event queue. Omitting this parameter will cause the client to wait until all events are sent before resolving the promise.

        Returns

        A promise which resolves to true if the queue successfully drains before the timeout, or false if it doesn't (or if there's no client defined).

      function getSentryRelease

      getSentryRelease: (fallback?: string) => string | undefined;
      • Returns a release dynamically from environment variables.

      function init

      init: (options?: NodeOptions) => void;
      • The Sentry Node SDK Client.

        To use this SDK, call the init function as early as possible in the main entry module. To set context information or send manual events, use the provided methods.

        Example 1

        const { init } = require('@sentry/node');
        init({
        dsn: '__DSN__',
        // ...
        });

        Example 2

        const { configureScope } = require('@sentry/node');
        configureScope((scope: Scope) => {
        scope.setExtra({ battery: 0.7 });
        scope.setTag({ user_mode: 'admin' });
        scope.setUser({ id: '4711' });
        });

        Example 3

        const { addBreadcrumb } = require('@sentry/node');
        addBreadcrumb({
        message: 'My Breadcrumb',
        // ...
        });

        Example 4

        const Sentry = require('@sentry/node');
        Sentry.captureMessage('Hello, world!');
        Sentry.captureException(new Error('Good bye'));
        Sentry.captureEvent({
        message: 'Manual',
        stacktrace: [
        // ...
        ],
        });

        See Also

        • NodeOptions for documentation on configuration options.

      function lastEventId

      lastEventId: () => string | undefined;
      • This is the getter for lastEventId.

        Returns

        The last event id of a captured event.

      function makeNodeTransport

      makeNodeTransport: (options: NodeTransportOptions) => Transport;
      • Creates a Transport that uses native the native 'http' and 'https' modules to send events to Sentry.

      Classes

      class NodeClient

      class NodeClient extends BaseClient<NodeClientOptions> {}
      • The Sentry Node SDK Client.

        See Also

        • NodeClientOptions for documentation on configuration options.

        • SentryClient for usage documentation.

      constructor

      constructor(options: NodeClientOptions);
      • Creates a new Node SDK instance.

        Parameter options

        Configuration options for this SDK.

      method captureEvent

      captureEvent: (
      event: Event,
      hint?: EventHint,
      scope?: Scope
      ) => string | undefined;

      method captureException

      captureException: (
      exception: any,
      hint?: EventHint,
      scope?: Scope
      ) => string | undefined;

      method close

      close: (timeout?: number) => PromiseLike<boolean>;

      method eventFromException

      eventFromException: (exception: any, hint?: EventHint) => PromiseLike<Event>;

      method eventFromMessage

      eventFromMessage: (
      message: string,
      level?: Severity | SeverityLevel,
      hint?: EventHint
      ) => PromiseLike<Event>;

      method initSessionFlusher

      initSessionFlusher: () => void;
      • Method that initialises an instance of SessionFlusher on Client

      Interfaces

      interface NodeOptions

      interface NodeOptions extends Options<NodeTransportOptions>, BaseNodeOptions {}
      • Configuration options for the Sentry Node SDK

        See Also

        • @sentry/types Options for more information.

      Namespaces

      namespace Handlers

      module 'types/handlers.d.ts' {}
      • Express-compatible tracing handler.

        See Also

        • Exposed as Handlers.tracingHandler

      function errorHandler

      errorHandler: (options?: {
      shouldHandleError?(error: MiddlewareError): boolean;
      }) => (
      error: MiddlewareError,
      req: http.IncomingMessage,
      res: http.ServerResponse,
      next: (error: MiddlewareError) => void
      ) => void;
      • Express compatible error handler.

        See Also

        • Exposed as Handlers.errorHandler

      function extractRequestData

      extractRequestData: (
      req: { [key: string]: any },
      keys?: string[]
      ) => ExtractedNodeRequestData;
      • Normalizes data from the request object, accounting for framework differences.

        Parameter req

        The request object from which to extract data

        Parameter keys

        An optional array of keys to include in the normalized data.

        Returns

        An object containing normalized request data

        Deprecated

        Handlers.extractRequestData is deprecated and will be removed in v8. Use extractRequestData instead.

      function parseRequest

      parseRequest: (
      event: Event,
      req: CrossPlatformRequest,
      options?: ParseRequestOptions
      ) => Event;
      • Enriches passed event with request data.

        Parameter event

        Will be mutated and enriched with req data

        Parameter req

        Request object

        Parameter options

        object containing flags to enable functionality

        Deprecated

        Handlers.parseRequest is deprecated and will be removed in v8. Use addRequestDataToEvent instead.

      function requestHandler

      requestHandler: (
      options?: RequestHandlerOptions
      ) => (
      req: http.IncomingMessage,
      res: http.ServerResponse,
      next: (error?: any) => void
      ) => void;
      • Express compatible request handler.

        See Also

        • Exposed as Handlers.requestHandler

      function tracingHandler

      tracingHandler: () => (
      req: http.IncomingMessage,
      res: http.ServerResponse,
      next: (error?: any) => void
      ) => void;
      • Express-compatible tracing handler.

        See Also

        • Exposed as Handlers.tracingHandler

      type ExpressRequest

      type ExpressRequest = CrossPlatformRequest;
      • Deprecated

        Handlers.ExpressRequest is deprecated and will be removed in v8. Use CrossPlatformRequest instead.

      type ParseRequestOptions

      type ParseRequestOptions = AddRequestDataToEventOptions['include'] & {
      serverName?: boolean;
      version?: boolean;
      };
      • Options deciding what parts of the request to use when enhancing an event

        Deprecated

        Handlers.ParseRequestOptions is deprecated and will be removed in v8. Use AddRequestDataToEventOptions in @sentry/utils instead.

      type RequestHandlerOptions

      type RequestHandlerOptions = (ParseRequestOptions | AddRequestDataToEventOptions) & {
      flushTimeout?: number;
      };

        Package Files (8)

        Dependencies (8)

        Dev Dependencies (6)

        Peer Dependencies (0)

        No peer dependencies.

        Badge

        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@sentry/node.

        • Markdown
          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@sentry/node)
        • HTML
          <a href="https://www.jsdocs.io/package/@sentry/node"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>