Instrumenter interface
Represents an implementation agnostic instrumenter.
Methods
create |
Provides an implementation-specific method to serialize a TracingSpan to a set of headers. |
parse |
Provides an implementation-specific method to parse a https://www.w3.org/TR/trace-context/#traceparent-header into a <xref:TracingSpanContext> which can be used to link non-parented spans together. |
start |
Creates a new TracingSpan with the given name and options and sets it on a new context. |
with |
Wraps a callback with an active context and calls the callback. Depending on the implementation, this may set the globally available active context. |
Method Details
createRequestHeaders(TracingContext)
Provides an implementation-specific method to serialize a TracingSpan to a set of headers.
function createRequestHeaders(tracingContext?: TracingContext): Record<string, string>
Parameters
- tracingContext
- TracingContext
The context containing the span to serialize.
Returns
Record<string, string>
parseTraceparentHeader(string)
Provides an implementation-specific method to parse a https://www.w3.org/TR/trace-context/#traceparent-header into a <xref:TracingSpanContext> which can be used to link non-parented spans together.
function parseTraceparentHeader(traceparentHeader: string): undefined | TracingContext
Parameters
- traceparentHeader
-
string
Returns
undefined | TracingContext
startSpan(string, InstrumenterSpanOptions)
Creates a new TracingSpan with the given name and options and sets it on a new context.
function startSpan(name: string, spanOptions: InstrumenterSpanOptions): { span: TracingSpan, tracingContext: TracingContext }
Parameters
- name
-
string
The name of the span. By convention this should be ${className}.${methodName}
.
- spanOptions
- InstrumenterSpanOptions
The options to use when creating the span.
Returns
{ span: TracingSpan, tracingContext: TracingContext }
A TracingSpan that can be used to end the span, and the context this span has been set on.
withContext<CallbackArgs, Callback>(TracingContext, Callback, CallbackArgs)
Wraps a callback with an active context and calls the callback. Depending on the implementation, this may set the globally available active context.
function withContext<CallbackArgs, Callback>(context: TracingContext, callback: Callback, callbackArgs: CallbackArgs): ReturnType<Callback>
Parameters
- context
- TracingContext
The TracingContext to use as the active context in the scope of the callback.
- callback
-
Callback
The callback to be invoked with the given context set as the globally active context.
- callbackArgs
-
CallbackArgs
The callback arguments.
Returns
ReturnType<Callback>