Documentation - v7.4.0
    Preparing search index...

    An isolated monitor, as returned by createMonitor.

    interface Monitor {
        callMonitored: {
            <T extends (...args: any[]) => unknown>(
                fn: T,
                context: ThisParameterType<T>,
                args: Parameters<T>,
            ): ReturnType<T> | undefined;
            <T extends (this: void) => unknown>(fn: T): ReturnType<T> | undefined;
        };
        monitor: <T extends (...args: any[]) => unknown>(fn: T) => T;
        monitored: <T extends (...params: any[]) => unknown>(
            _: any,
            __: string,
            descriptor: TypedPropertyDescriptor<T>,
        ) => void;
        monitorError: (e: unknown) => void;
    }
    Index

    Properties

    callMonitored: {
        <T extends (...args: any[]) => unknown>(
            fn: T,
            context: ThisParameterType<T>,
            args: Parameters<T>,
        ): ReturnType<T> | undefined;
        <T extends (this: void) => unknown>(fn: T): ReturnType<T> | undefined;
    }

    Invokes a function with error handling: returns its result, or reports the error (via the error callback) and returns undefined if it throws.

    When to use: prefer this for a one-off inline block you want to run immediately under error protection. If you instead need a callback to pass elsewhere and reuse, wrap it once with Monitor.monitor.

    The function to invoke.

    this value to invoke fn with (optional for context-free functions).

    Arguments to invoke fn with (optional for context-free functions).

    The result of fn, or undefined if it threw.

    callMonitored(() => {
    const stackTrace = computeStackTrace(error)
    reportStackTrace(stackTrace)
    })
    monitor: <T extends (...args: any[]) => unknown>(fn: T) => T

    Wraps a function so that, when called, any thrown error is caught and reported (via the error callback) instead of propagating. The wrapper keeps the same signature as the input function.

    When to use: prefer this when you need a reusable monitored callback to hand to something that invokes it later, possibly multiple times — an event listener, setTimeout, an observable subscription. For a one-shot inline block, use Monitor.callMonitored instead.

    Type Declaration

      • <T extends (...args: any[]) => unknown>(fn: T): T
      • Type Parameters

        • T extends (...args: any[]) => unknown

        Parameters

        • fn: T

          The function to wrap.

        Returns T

        A function with the same signature that never throws (errors are collected instead).

    element.addEventListener(
    'click',
    monitor((event) => {
    // handler errors are collected instead of surfacing to the page
    })
    )
    monitored: <T extends (...params: any[]) => unknown>(
        _: any,
        __: string,
        descriptor: TypedPropertyDescriptor<T>,
    ) => void

    TypeScript method decorator that routes a class method through Monitor.monitor, so any error it throws is caught and reported instead of propagating to the caller. Apply it as @monitored on the method (it replaces the method's descriptor value with the monitored wrapper).

    When to use: prefer this for class methods that are entry points from outside the SDK (public API methods, lifecycle callbacks) where an internal error must never reach the host application. For standalone functions or inline blocks, use Monitor.monitor or Monitor.callMonitored instead.

    monitorError: (e: unknown) => void

    Reports an error directly: logs it to the console when debug mode is enabled, then forwards it to the error callback. Used internally by Monitor.monitor/Monitor.callMonitored, but can also be called to report an error caught elsewhere.

    When to use: prefer this when you already hold an error value and only need to route it to telemetry — e.g. a promise rejection, which monitor/callMonitored do not catch (they only handle synchronous throws).

    Type Declaration

      • (e: unknown): void
      • Parameters

        • e: unknown

          The error to report.

        Returns void

    // route a promise rejection to telemetry
    doAsyncThing().catch(monitorError)