@sentry/node

  • Version 7.70.0
  • Published
  • 1.38 MB
  • 8 dependencies
  • MIT license

Install

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

Overview

Official Sentry SDK for Node.js

Index

Variables

variable DEFAULT_USER_INCLUDES

const DEFAULT_USER_INCLUDES: string[];

    variable defaultIntegrations

    const defaultIntegrations: any[];

      variable defaultStackParser

      const defaultStackParser: StackParser;
      • Node.js stack parser

      variable Integrations

      const Integrations: {
      Apollo: any;
      Express: any;
      GraphQL: any;
      Mongo: any;
      Mysql: any;
      Postgres: any;
      Prisma: any;
      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;
      Context: typeof NodeIntegrations.Context;
      RequestData: typeof NodeIntegrations.RequestData;
      LocalVariables: typeof NodeIntegrations.LocalVariables;
      Undici: typeof NodeIntegrations.Undici;
      FunctionToString: any;
      InboundFilters: any;
      };

        Functions

        function addRequestDataToEvent

        addRequestDataToEvent: (
        event: Event,
        req: PolymorphicRequest,
        options?: AddRequestDataToEventOptions
        ) => Event;
        • Add data from the given request to the given event

          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

          Returns

          The mutated Event object

        function autoDiscoverNodePerformanceMonitoringIntegrations

        autoDiscoverNodePerformanceMonitoringIntegrations: () => Integration[];
        • Automatically detects and returns integrations that will work with your dependencies.

        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: PolymorphicRequest,
        options?: { include?: string[] }
        ) => ExtractedNodeRequestData;
        • Normalize data from the request object

          Parameter req

          The request object from which to extract data

          Parameter

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

          Parameter

          options.deps Injected, platform-specific dependencies

          Returns

          An object containing normalized request data

        function getModuleFromFilename

        getModuleFromFilename: (
        filename: string | undefined,
        normalizeWindowsPathSeparator?: boolean
        ) => string | undefined;
        • Gets the module from a filename

        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 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 ServerRuntimeClient<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.

        Interfaces

        interface NodeOptions

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

          See Also

          • @sentry/types Options for more information.

        Type Aliases

        type TransactionNamingScheme

        type TransactionNamingScheme = 'path' | 'methodPath' | 'handler';

          Namespaces

          namespace Handlers

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

            See Also

            • Exposed as Handlers.tracingHandler

          function errorHandler

          errorHandler: (options?: {
          shouldHandleError?(this: void, 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: PolymorphicRequest,
          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

          function trpcMiddleware

          trpcMiddleware: (
          options?: SentryTrpcMiddlewareOptions
          ) => <T>({ path, type, next, rawInput }: TrpcMiddlewareArguments<T>) => T;
          • Sentry tRPC middleware that names the handling transaction after the called procedure.

            Use the Sentry tRPC middleware in combination with the Sentry server integration, e.g. Express Request Handlers or Next.js SDK.

          type ExpressRequest

          type ExpressRequest = PolymorphicRequest;
          • Deprecated

            Handlers.ExpressRequest is deprecated and will be removed in v8. Use PolymorphicRequest 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 (11)

            Dependencies (8)

            Dev Dependencies (7)

            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>