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

    Interface IPluginObservableInternal

    API: IPluginObservable

    Unified interface combining logging and metrics capabilities. This is the internal interface implemented by ObservableBackend.

    interface IPluginObservable {
        info<T extends string>(
            trace: DTrace,
            message: T,
            ...meta: SmartLogMeta<T>,
        ): void;
        warn<T extends string>(
            trace: DTrace,
            message: T,
            ...meta: SmartLogMeta<T>,
        ): void;
        debug<T extends string>(
            trace: DTrace,
            message: T,
            ...meta: SmartLogMeta<T>,
        ): void;
        error<T extends string>(
            trace: DTrace,
            message: T,
            ...meta: SmartLogMeta<T>,
        ): void;
        error<T extends string>(error: BSBError<T>): void;
        createCounter<LABELS extends string | undefined>(
            name: string,
            description: string,
            help: string,
            labels?: LABELS[],
        ): Counter<LABELS>;
        createGauge<LABELS extends string | undefined>(
            name: string,
            description: string,
            help: string,
            labels?: LABELS[],
        ): Gauge<LABELS>;
        createHistogram<LABELS extends string | undefined>(
            name: string,
            description: string,
            help: string,
            boundaries?: number[],
            labels?: LABELS[],
        ): Histogram<LABELS>;
        createTrace(
            name: string,
            attributes?: Record<string, string | number | boolean>,
        ): Trace;
        createSpan(
            trace: DTrace,
            name: string,
            attributes?: Record<string, string | number | boolean>,
        ): Trace;
        createTimer(): Timer;
    }

    Hierarchy (View Summary)

    Index

    Methods

    • Log an informational message with meta data.

      Type Parameters

      • T extends string

      Parameters

      • trace: DTrace

        The trace object.

      • message: T

        The message to log.

      • ...meta: SmartLogMeta<T>

        The meta data to log.

      Returns void

    • Log a warning message with meta data.

      Type Parameters

      • T extends string

      Parameters

      • trace: DTrace

        The trace object.

      • message: T

        The message to log.

      • ...meta: SmartLogMeta<T>

        The meta data to log.

      Returns void

    • Log a debug message with meta data.

      Type Parameters

      • T extends string

      Parameters

      • trace: DTrace

        The trace object.

      • message: T

        The message to log.

      • ...meta: SmartLogMeta<T>

        The meta data to log.

      Returns void

    • Log an error message with meta data.

      Type Parameters

      • T extends string

      Parameters

      • trace: DTrace

        The trace object.

      • message: T

        The message to log.

      • ...meta: SmartLogMeta<T>

        The meta data to log.

      Returns void

    • Log an error message with meta data.

      Type Parameters

      • T extends string

      Parameters

      Returns void

    • Creates a counter metric. A Counter is a metric that represents a monotonically increasing value. It is used to measure the cumulative count of an event that increases over time and resets to zero only when the process restarts.

      Type Parameters

      • LABELS extends string | undefined

      Parameters

      • name: string

        The name of the counter metric

      • description: string

        A description of the counter metric

      • help: string

        More information about the counter metric

      • Optionallabels: LABELS[]

        Optional labels to associate with the counter metric

      Returns Counter<LABELS>

      A Counter object that can be used to update the counter metric

      Use Cases:

      Event Counting: Counting the number of requests received, errors encountered, or messages processed. Work Done: Measuring the total number of bytes read or written, tasks completed, or jobs processed. Characteristics:

      Monotonic: Counters can only increase or reset. They cannot decrease. Sum: The focus is on the total accumulated value over time. Example: A Counter can be used to count the number of HTTP requests received by a server.

      let counter = this.metrics.createCounter("my-counter", "A counter metric");
      counter.inc(); // Increment the counter by 1
      counter.inc(1); // Increment the counter by 1
      counter.inc(10); // Increment the counter by 10
    • Creates a gauge metric. A Gauge is a metric that represents a value that can go up and down. It measures the current value of a particular data point at a specific moment in time.

      Type Parameters

      • LABELS extends string | undefined

      Parameters

      • name: string

        The name of the gauge metric

      • description: string

        A description of the gauge metric

      • help: string

        More information about the gauge metric

      • Optionallabels: LABELS[]

        Optional labels to associate with the gauge metric

      Returns Gauge<LABELS>

      A Gauge object that can be used to update the gauge metric

      Use Cases:

      Resource Levels: Monitoring CPU usage, memory consumption, or disk space. Temperature or Pressure: Tracking real-time sensor readings. Current State: Measuring the current number of active users or open connections. Characteristics:

      Variable: Gauges can increase and decrease over time. Instantaneous: Captures a snapshot of a value at a particular time. Example: A Gauge can be used to measure the current temperature of a system or the current memory usage of an application.

      let gauge = this.metrics.createGauge("my-gauge", "A gauge metric");
      gauge.set(10); // Set the gauge to 10
      gauge.set(20); // Set the gauge to 20
      gauge.set(30); // Set the gauge to 30
      gauge.increment(); // Increment the gauge by 1
      gauge.increment(10); // Increment the gauge by 10
      gauge.decrement(); // Decrement the gauge by 1
      gauge.decrement(10); // Decrement the gauge by 10
    • Creates a histogram metric. A Histogram is a metric that collects data samples and counts them in predefined buckets. It provides statistical distribution of values over time, capturing not just the total sum but also the distribution of values.

      Type Parameters

      • LABELS extends string | undefined

      Parameters

      • name: string

        The name of the histogram metric

      • description: string

        A description of the histogram metric

      • help: string

        More information about the histogram metric

      • Optionalboundaries: number[]

        Optional boundaries for the histogram metric

      • Optionallabels: LABELS[]

        Optional labels to associate with the histogram metric

      Returns Histogram<LABELS>

      A Histogram object that can be used to update the histogram metric

      Use Cases:

      Event Distribution: Measuring the distribution of events received by a system, such as the number of requests per second or the distribution of response times. Work Done: Measuring the distribution of bytes read or written, tasks completed, or jobs processed. Characteristics:

      Monotonic: Histograms can only increase or reset. They cannot decrease. Sum: The focus is on the total accumulated value over time. Example: A Histogram can be used to measure the distribution of response times for a web server.

      let histogram = this.metrics.createHistogram("my-histogram", "A histogram metric");
      histogram.record(10); // Record the value 10 in the histogram
      histogram.record(20); // Record the value 20 in the histogram
      histogram.record(30); // Record the value 30 in the histogram
    • Creates a trace metric. A Trace is a metric that represents a sequence of events or operations that form a request or transaction. It provides a way to track and monitor the flow of operations across your application.

      Parameters

      • name: string

        The name of the trace, used to identify the operation or request being traced

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

        Optional key-value pairs providing additional context about the trace

      Returns Trace

      A Trace object that can be used to record spans, errors, and manage the trace lifecycle

      Use Cases:

      • Request Tracing: Following a request as it moves through different services or components
      • Performance Monitoring: Tracking the timing and dependencies of operations
      • Error Tracking: Identifying where in a sequence of operations an error occurred
      • Distributed Tracing: Monitoring operations across multiple services

      Characteristics:

      • Unique Identification: Each trace has a unique ID
      • Attributes: Can include key-value pairs for additional context
      • Error Handling: Built-in support for error recording
      • Lifecycle Management: Clear start and end points
      // Create a simple trace
      const trace = this.metrics.createTrace("user-registration");

      // OR Create a trace with attributes
      const trace = this.metrics.createTrace("payment-processing", {
      "customer-id": "12345",
      "payment-method": "credit-card"
      });

      // Using the trace
      try {
      // Perform operations
      const span = this.metrics.createSpan(trace, "get-customer-balance");
      // Do some external work
      span.end({balance: 100});
      trace.end({transactionId: "12345"});
      } catch (error) {
      trace.error(error);
      }
      trace.end();
    • Creates a new span from an existing trace (automatic parent span).

      Parameters

      • trace: DTrace

        The trace to associate with the span

      • name: string

        The name of the span

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

        Optional attributes to associate with the span

      Returns Trace

      A Span object that can be used to update the span metric

      let span = this.metrics.createSpan(trace, "span-1", {"key": "value"});
      span.end();
    • Create Timer A Timer is a metric that measures the time taken to execute a block of code. It provides a simple way to measure the time taken to execute a block of code.

      Returns Timer

      A Timer object that can be used to update the timer metric

      Use Cases:

      Event Timing: Measuring the time taken to execute a block of code. Work Done: Measuring the time taken to execute a block of code. Characteristics:

      Monotonic: Timers can only increase or reset. They cannot decrease. Sum: The focus is on the total accumulated value over time. Example: A Timer can be used to measure the time taken to execute a block of code.

      let timer = this.metrics.createTimer(); // Start the timer
      // Do some work
      let elapsedTime = timer.stop(); // Stop the timer and get the elapsed time in nanoseconds