BSB Node.js Type Definitions
    Preparing search index...

    Class ObservableBackendInternal

    Observable Backend - Unified backend for logging and metrics

    This is the internal backend that handles both logging and metrics operations. It replaces the separate PluginLogging and PluginMetrics classes with a single unified implementation.

    // Internal use only - plugins use Observable interface
    const backend = new ObservableBackend(
    'development',
    'my-app',
    'my-plugin',
    sbObservable
    );
    Index

    Constructors

    • Create an ObservableBackend instance

      Parameters

      • mode: DEBUG_MODE

        Debug mode setting

      • appId: string

        Application ID

      • pluginName: string

        Plugin name

      • bus: ObservableBus

        Observable bus for emitting events

      Returns ObservableBackend

    Methods

    • Logs a debug message

      Type Parameters

      • T extends string

      Parameters

      • trace: DTrace

        The trace to associate with the log

      • message: T

        The message to log

      • ...meta: SmartLogMeta<T>

        Additional information to log with the message

      Returns void

      nothing

      backend.debug(trace, "This is a debug log");
      backend.debug(trace, "This is a debug {key}", {"key": "log"});
    • Logs an info message

      Type Parameters

      • T extends string

      Parameters

      • trace: DTrace

        The trace to associate with the log

      • message: T

        The message to log

      • ...meta: SmartLogMeta<T>

        Additional information to log with the message

      Returns void

      nothing

      backend.info(trace, "This is an info log");
      backend.info(trace, "This is an info {key}", {"key": "log"});
    • Logs a warn message

      Type Parameters

      • T extends string

      Parameters

      • trace: DTrace

        The trace to associate with the log

      • message: T

        The message to log

      • ...meta: SmartLogMeta<T>

        Additional information to log with the message

      Returns void

      nothing

      backend.warn(trace, "This is a warn log");
      backend.warn(trace, "This is a warn {key}", {"key": "log"});
    • Logs an error message

      Type Parameters

      • T extends string

      Parameters

      • trace: DTrace

        The trace to associate with the log

      • message: T

        The message to log

      • ...meta: SmartLogMeta<T>

        Additional information to log with the message

      Returns void

      nothing

      backend.error(trace, "This is an error log");
      backend.error(trace, "This is an error {key}", {"key": "log"});
      backend.error(new BSBError(trace, "error-key", "This is an error log"));
      backend.error(new BSBError(trace, "error-key", "This is an error {key}", {"key": "log"}));
    • Logs an error message

      Type Parameters

      • T extends string

      Parameters

      Returns void

      nothing

      backend.error(trace, "This is an error log");
      backend.error(trace, "This is an error {key}", {"key": "log"});
      backend.error(new BSBError(trace, "error-key", "This is an error log"));
      backend.error(new BSBError(trace, "error-key", "This is an error {key}", {"key": "log"}));
    • Create a counter metric

      Counters are monotonically increasing values used to track cumulative totals. Common uses: request counts, error counts, bytes processed.

      Type Parameters

      • LABELS extends string | undefined

      Parameters

      • name: string

        Metric name (e.g., "requests_total")

      • description: string

        Short description

      • help: string

        Detailed help text

      • Optionallabels: LABELS[]

        Optional label names for dimensional metrics

      Returns Counter<LABELS>

      Counter instance with increment method

      const requests = backend.createCounter(
      "http_requests_total",
      "Total HTTP requests",
      "Count of all HTTP requests received",
      ["method", "status"]
      );
      requests.increment(1, { method: "GET", status: "200" });
    • Create a gauge metric

      Gauges represent point-in-time values that can go up or down. Common uses: memory usage, active connections, queue depth, temperature.

      Type Parameters

      • LABELS extends string | undefined

      Parameters

      • name: string

        Metric name (e.g., "active_connections")

      • description: string

        Short description

      • help: string

        Detailed help text

      • Optionallabels: LABELS[]

        Optional label names for dimensional metrics

      Returns Gauge<LABELS>

      Gauge instance with set, increment, and decrement methods

      const activeConns = backend.createGauge(
      "active_connections",
      "Active connections",
      "Number of currently active connections"
      );
      activeConns.set(42);
      activeConns.increment(1);
      activeConns.decrement(1);
    • Create a histogram metric

      Histograms track the distribution of values over time. Common uses: request duration, response size, batch size.

      Type Parameters

      • LABELS extends string | undefined

      Parameters

      • name: string

        Metric name (e.g., "request_duration_ms")

      • description: string

        Short description

      • help: string

        Detailed help text

      • Optionalboundaries: number[]

        Optional bucket boundaries (default: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10])

      • Optionallabels: LABELS[]

        Optional label names for dimensional metrics

      Returns Histogram<LABELS>

      Histogram instance with record method

      const duration = backend.createHistogram(
      "request_duration_ms",
      "Request duration",
      "Duration of HTTP requests in milliseconds",
      [10, 50, 100, 500, 1000, 5000],
      ["method"]
      );
      duration.record(125, { method: "GET" });
    • Create a new distributed trace

      Creates a root trace with no parent. Use this when starting a new request or operation that should be tracked independently.

      Parameters

      • name: string

        Name of the trace/span (e.g., "http-request")

      • Optionalattributes: Record<string, string | number | boolean>

        Optional attributes to attach to the trace

      Returns Trace

      Trace instance

      const trace = backend.createTrace("process-batch", {
      "batch.size": 100
      });
      // ... do work ...
      trace.end({ "batch.processed": 100 });
    • Create a child span within an existing trace

      Creates a child span that inherits the trace ID from the parent. This is used internally by Observable.startSpan().

      Parameters

      • trace: DTrace

        Parent DTrace object

      • name: string

        Name of the span (e.g., "database-query")

      • Optionalattributes: Record<string, string | number | boolean>

        Optional attributes to attach to the span

      Returns Trace

      Trace instance representing the child span

      // Usually accessed via Observable
      const childSpan = backend.createSpan(trace, "database-query");
      // ... do work ...
      childSpan.end();
    • Create a high-resolution timer

      Returns a timer that can measure elapsed time in milliseconds with sub-millisecond precision using Node.js hrtime.

      Returns Timer

      Timer instance with stop method

      const timer = backend.createTimer();
      await performOperation();
      const elapsed = timer.stop();