@sentry/node

  • Version 7.112.2
  • Published
  • 2.13 MB
  • 5 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 anrIntegration

const anrIntegration: AnrReturn;

    variable cron

    const cron: {
    instrumentCron: typeof instrumentCron;
    instrumentNodeCron: typeof instrumentNodeCron;
    instrumentNodeSchedule: typeof instrumentNodeSchedule;
    };
    • Methods to instrument cron libraries for Sentry check-ins

    variable defaultIntegrations

    const defaultIntegrations: any[];
    • Deprecated

      Use getDefaultIntegrations(options) instead.

    variable defaultStackParser

    const defaultStackParser: StackParser;
    • Node.js stack parser

    variable hapiErrorPlugin

    const hapiErrorPlugin: {
    name: string;
    version: string;
    register: (serverArg: Record<any, any>) => Promise<void>;
    };

      variable Integrations

      const Integrations: {
      Apollo: any;
      Express: any;
      GraphQL: any;
      Mongo: any;
      Mysql: any;
      Postgres: any;
      Prisma: any;
      Console: any;
      Http: typeof NodeIntegrations.Http;
      OnUncaughtException: any;
      OnUnhandledRejection: any;
      Modules: any;
      ContextLines: any;
      Context: any;
      RequestData: any;
      LocalVariables: any;
      Undici: typeof NodeIntegrations.Undici;
      Spotlight: any;
      Anr: any;
      Hapi: any;
      FunctionToString: any;
      InboundFilters: any;
      LinkedErrors: any;
      };

        Functions

        function autoDiscoverNodePerformanceMonitoringIntegrations

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

        function consoleIntegration

        consoleIntegration: () => any;

          function contextLinesIntegration

          contextLinesIntegration: (options?: ContextLinesOptions | undefined) => any;

            function createGetModuleFromFilename

            createGetModuleFromFilename: (
            basePath?: string,
            isWindows?: boolean
            ) => (filename: string | undefined) => string | undefined;
            • Creates a function that gets the module name from a filename

            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

              Deprecated

              This function will be removed in the next major version.

            function enableAnrDetection

            enableAnrDetection: (options: Partial<LegacyOptions>) => Promise<void>;
            • Deprecated

              Use the Anr integration instead.

              import * as Sentry from '@sentry/node';
              Sentry.init({
              dsn: '__DSN__',
              integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true })],
              });

            function getDefaultIntegrations

            getDefaultIntegrations: (_options: Options) => Integration[];
            • Get the default integrations for the Node SDK.

            function getModuleFromFilename

            getModuleFromFilename: (filename: string | undefined) => string | undefined;
            • Deprecated

              use createGetModuleFromFilename instead.

            function getSentryRelease

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

            function hapiIntegration

            hapiIntegration: (options?: HapiOptions | undefined) => any;

              function httpIntegration

              httpIntegration: (
              options?: HttpIntegrationOptions | undefined
              ) => IntegrationFnResult;
              • The http module integration instruments Node's internal http module. It creates breadcrumbs, spans for outgoing http requests, and attaches trace data when tracing is enabled via its tracing option.

                By default, this will always create breadcrumbs, and will create spans if tracing is enabled.

              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 localVariablesIntegration

              localVariablesIntegration: (
              options?: import('./common').LocalVariablesIntegrationOptions | undefined,
              session?: import('./local-variables-sync').DebugSession | undefined
              ) => any;

                function makeNodeTransport

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

                function modulesIntegration

                modulesIntegration: () => any;

                  function nativeNodeFetchintegration

                  nativeNodeFetchintegration: (
                  options?: Partial<UndiciOptions> | undefined
                  ) => IntegrationFnResult;

                    function nodeContextIntegration

                    nodeContextIntegration: (options?: ContextOptions | undefined) => any;

                      function onUncaughtExceptionIntegration

                      onUncaughtExceptionIntegration: (
                      options?: Partial<OnUncaughtExceptionOptions> | undefined
                      ) => any;

                        function onUnhandledRejectionIntegration

                        onUnhandledRejectionIntegration: (
                        options?: Partial<OnUnhandledRejectionOptions> | undefined
                        ) => any;

                          function spotlightIntegration

                          spotlightIntegration: (
                          options?: Partial<SpotlightConnectionOptions> | undefined
                          ) => any;

                            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.

                            Classes

                            class Http

                            class Http implements Integration {}
                            • The http module integration instruments Node's internal http module. It creates breadcrumbs, transactions for outgoing http requests and attaches trace data when tracing is enabled via its tracing option.

                              Deprecated

                              Use httpIntegration() instead.

                            constructor

                            constructor(options?: HttpOptions);

                            property id

                            static id: string;

                            property name

                            name: string;

                            method setupOnce

                            setupOnce: (
                            _addGlobalEventProcessor: (callback: EventProcessor) => void,
                            setupOnceGetCurrentHub: () => Hub
                            ) => void;

                            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.

                            class Undici

                            class Undici implements Integration {}
                            • Instruments outgoing HTTP requests made with the undici package via Node's diagnostics_channel API.

                              Supports Undici 4.7.0 or higher.

                              Requires Node 16.17.0 or higher.

                              Deprecated

                              Use nativeNodeFetchintegration() instead.

                            constructor

                            constructor(_options?: Partial<UndiciOptions>);

                              property id

                              static id: string;

                              property name

                              name: string;

                              method setupOnce

                              setupOnce: (
                              _addGlobalEventProcessor: (callback: EventProcessor) => void
                              ) => void;

                              Interfaces

                              interface AnrIntegrationOptions

                              interface AnrIntegrationOptions {}

                                property anrThreshold

                                anrThreshold: number;
                                • Threshold in milliseconds to trigger an ANR event.

                                  Defaults to 5000ms.

                                property appRootPath

                                appRootPath: string | undefined;
                                • Internal use only.

                                  If this is supplied, stack frame filenames will be rewritten to be relative to this path.

                                property captureStackTrace

                                captureStackTrace: boolean;
                                • Whether to capture a stack trace when the ANR event is triggered.

                                  Defaults to false.

                                  This uses the node debugger which enables the inspector API and opens the required ports.

                                property pollInterval

                                pollInterval: number;
                                • Interval to send heartbeat messages to the ANR worker.

                                  Defaults to 50ms.

                                property staticTags

                                staticTags: {
                                [key: string]: Primitive;
                                };
                                • Tags to include with ANR events.

                                interface DebugSession

                                interface DebugSession {}

                                  method configureAndConnect

                                  configureAndConnect: (
                                  onPause: (
                                  message: InspectorNotification<Debugger.PausedEventDataType>,
                                  complete: () => void
                                  ) => void,
                                  captureAll: boolean
                                  ) => void;
                                  • Configures and connects to the debug session

                                  method getLocalVariables

                                  getLocalVariables: (
                                  objectId: string,
                                  callback: (vars: Variables) => void
                                  ) => void;
                                  • Gets local variables for an objectId

                                  method setPauseOnExceptions

                                  setPauseOnExceptions: (captureAll: boolean) => void;
                                  • Updates which kind of exceptions to capture

                                  interface LocalVariablesIntegrationOptions

                                  interface LocalVariablesIntegrationOptions {}

                                    property captureAllExceptions

                                    captureAllExceptions?: boolean;
                                    • Capture local variables for both caught and uncaught exceptions

                                      - When false, only uncaught exceptions will have local variables - When true, both caught and uncaught exceptions will have local variables.

                                      Defaults to true.

                                      Capturing local variables for all exceptions can be expensive since the debugger pauses for every throw to collect local variables.

                                      To reduce the likelihood of this feature impacting app performance or throughput, this feature is rate-limited. Once the rate limit is reached, local variables will only be captured for uncaught exceptions until a timeout has been reached.

                                    property maxExceptionsPerSecond

                                    maxExceptionsPerSecond?: number;
                                    • Maximum number of exceptions to capture local variables for per second before rate limiting is triggered.

                                    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

                                    variable trpcMiddleware

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

                                      Deprecated

                                      Please use the top level export instead:

                                      // OLD
                                      import * as Sentry from '@sentry/node';
                                      Sentry.Handlers.trpcMiddleware();
                                      // NEW
                                      import * as Sentry from '@sentry/node';
                                      Sentry.trpcMiddleware();

                                    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

                                    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 (27)

                                      Dependencies (5)

                                      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>