Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface TraceAgent

Hierarchy

  • TraceAgent

Implemented by

Index

Properties

constants

constants: object

Type declaration

labels

labels: object

Type declaration

spanTypes

spanTypes: SpanType

Methods

createChildSpan

  • Creates and returns a new Span object nested within the current root span, which is detected automatically. If the root span is a phantom span or doesn't exist, the child span will be a phantom span as well.

    Parameters

    • Optional options: SpanOptions

      Options for creating the child span.

    Returns Span

    A new Span object.

enhancedDatabaseReportingEnabled

  • enhancedDatabaseReportingEnabled(): boolean
  • Gets the value of enhancedDatabaseReporting in the trace agent's configuration object.

    Returns boolean

    A boolean value indicating whether the trace agent was configured to have an enhanced level of reporting enabled.

getCurrentContextId

  • getCurrentContextId(): string | null
  • Returns a unique identifier for the currently active context. This can be used to uniquely identify the current root span. If there is no current, context, or if we have lost context, this will return null. The structure and the length of the returned string should be treated opaquely - the only guarantee is that the value would unique for every root span.

    Returns string | null

    an id for the current context, or null if there is none

getCurrentRootSpan

  • Gets the active root span for the current context. This method is guaranteed to return an object with the surface of a RootSpan object, but it may not represent a real root span if we are not in one. Use isRealSpan or check the type field to determine whether this is a real or phantom span.

    Returns RootSpan

    An object that represents either a real or phantom root span.

getProjectId

  • getProjectId(): Promise<string>
  • Returns the projectId that was either configured or auto-discovered by the TraceWriter.

    Returns Promise<string>

getResponseTraceContext

  • getResponseTraceContext(incomingTraceContext: string | null, isTraced: boolean): string
  • Generates a stringified trace context that should be set as the trace context header in a response to an incoming web request. This value is based on the trace context header value in the corresponding incoming request, as well as the result from the local trace policy on whether this request will be traced or not.

    Parameters

    • incomingTraceContext: string | null

      The trace context that was attached to the incoming web request, or null if the incoming request didn't have one.

    • isTraced: boolean

      Whether the incoming was traced. This is determined by the local tracing policy.

    Returns string

    If the response should contain the trace context within its header, the string to be set as this header's value. Otherwise, an empty string.

getWriterProjectId

  • getWriterProjectId(): string | null
  • Returns the projectId that was either configured or auto-discovered by the TraceWriter. Note that the auto-discovery is done asynchronously, so this may return falsey until the projectId auto-discovery completes.

    Returns string | null

isRealSpan

  • isRealSpan(span: Span): boolean
  • Returns whether a given span is real or not by checking its SpanType.

    Parameters

    Returns boolean

runInRootSpan

  • Runs the given function in a root span corresponding to an incoming request, passing it an object that exposes an interface for adding labels and closing the span.

    Type parameters

    • T

    Parameters

    • options: RootSpanOptions

      An object that specifies options for how the root span is created and propagated.

    • fn: function

      A function that will be called exactly once. If the incoming request should be traced, a root span will be created, and this function will be called with a Span object exposing functions operating on the root span; otherwise, it will be called with a phantom Span object.

    Returns T

    The return value of calling fn.

wrap

  • Binds the trace context to the given function. This is necessary in order to create child spans correctly in functions that are called asynchronously (for example, in a network response handler).

    Type parameters

    • T

    Parameters

    • fn: Func<T>

      A function to which to bind the trace context.

    Returns Func<T>

wrapEmitter

  • wrapEmitter(emitter: EventEmitter): void
  • Binds the trace context to the given event emitter. This is necessary in order to create child spans correctly in event handlers.

    Parameters

    • emitter: EventEmitter

      An event emitter whose handlers should have the trace context binded to them.

    Returns void

Generated using TypeDoc