Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "helpers/utils"

This module exports a number of utility functions that are used throughout the application being traced. Some functions are specifically meant to be called at application startup to initialize the global tracer, set up trace headers, etc.

This module is re-exported as a top-level export.

See the quickstart for a primer on how to set up your application for tracing.

Index

Functions

attachSpan

  • attachSpan(fn: Function | FunctionConstructor, operation: string, options?: SpanOptions, onSuccess?: (result: any, span: Span) => void, onError?: (err: Error, span: Span) => void): (Anonymous function)
  • Creates a wrapper around the input function that, when invoked, executes the given function inside a new span. When you don't need to manually alter the span before it is closed and reported, the success and error callbacks can be omitted. In this case, when the function ends, it either returns its result (or void) back to the caller or throws an error. In both cases, the span enclosing the function's execution is always properly closed and reported, enriched with additional error information, if applicable.

    On the other hand, when you need access to the span (at the end of the function) just before it is finalized, you can specify the success and error callbacks, within which you will have access to the span. You can now add your custom tags/logs to the span. The span must be explicity closed in the body of both callbacks by invoking its finish method.

    Parameters

    • fn: Function | FunctionConstructor

      The function to be wrapped in a span.

    • operation: string

      The operation name to be recorded in the span.

    • Default value options: SpanOptions = {}

      The optional SpanOptions object that describes the span.

    • Optional onSuccess: (result: any, span: Span) => void

      The optional success callback. It is called with two parameters:

      1. result - containing the result of invoking fn.
      2. span - the Span object that was used to instrument fn.
        • (result: any, span: Span): void
        • Parameters

          • result: any
          • span: Span

          Returns void

    • Optional onError: (err: Error, span: Span) => void

      The optional error callback. It is called with two parameters:

      1. err - the Error that occurred when invoking fn.
      2. span - the Span object that was used to instrument fn.
        • (err: Error, span: Span): void
        • Parameters

          • err: Error
          • span: Span

          Returns void

    Returns (Anonymous function)

    The wrapper function that accepts the same arguments as fn.

clearTraceContext

  • clearTraceContext(): void
  • Clears the global tracer's memory of all trace and span context. Useful when it is desired to manually start a fresh trace. Normally required only in test suite runs.

    Returns void

executeTask

  • executeTask(task: TaskOpts, operation: string, options?: SpanOptions): void
  • Registers a task while ensuring that the trace context is correctly propagated over to the V8 context where the task is actually run. The function executed by the task is wrapped in a new span which carries the same trace context that was active at the time of registering the task.

    Parameters

    • task: TaskOpts

      The object describing the task.

    • operation: string

      The operation name to be recorded in the span.

    • Default value options: SpanOptions = {}

      The optional SpanOptions object that describes the span.

    Returns void

executeTransaction

  • executeTransaction(data: Transaction, operation: string, options?: SpanOptions): void
  • Start a transaction while ensuring that the trace context is correctly propagated over to the V8 context where the transaction is actually run. The command executed by the transaction is wrapped in a new span which carries the same trace context that was active in the V8 context that invoked the transaction.

    Parameters

    • data: Transaction

      The Transaction description.

    • operation: string

      The operation name to be recorded in the span.

    • Default value options: SpanOptions = {}

      The optional SpanOptions object that describes the span.

    Returns void

generateUUID

  • generateUUID(): string

initTracer

  • initTracer(): void
  • Initializes the global tracer at application startup. This should be called as early as possible (and only once) when application starts.

    Returns void

instrumentedQuery

  • instrumentedQuery(query: Query, operation: string, options?: SpanOptions): Cursor<any>
  • Executes the given query inside a new span and returns the resultant cursor. The enclosing span records query stats (available within the cursor object) in its logs.

    Parameters

    • query: Query

      The AQL Query to execute.

    • operation: string

      The operation name to be recorded in the span.

    • Default value options: SpanOptions = {}

      The optional SpanOptions object that describes the span.

    Returns Cursor<any>

    The Cursor that is created as a result of running the query.

startSpan

  • startSpan(name: string, options?: SpanOptions): Span
  • Start a new span. Useful when it is desired to manually start a fresh trace. Normally required only in test suite runs.

    Parameters

    • name: string

      The operation name to be recorded in the span.

    • Default value options: SpanOptions = {}

      The optional SpanOptions object that describes the span.

    Returns Span

    The created Span.

Generated using TypeDoc