Home Reference Source Repository
import Span from 'opentracing/src/span.js'
public class | source

Span

Span represents a logical unit of work as part of a broader Trace. Examples of span might include remote procedure calls or a in-process function calls to sub-components. A Trace has a single, top-level "root" Span that in turn may have zero or more child Spans, which in turn may have children.

Method Summary

Public Methods
public

addTags(keyValueMap: *): [type]

Adds the given key value pairs to the set of span tags.

public

Returns the SpanContext object associated with this Span.

public

finish(finishTime: number)

Sets the end timestamp and finalizes Span state.

public

Returns the value for a baggage item given its key.

public

log(keyValuePairs: object, timestamp: number): *

Add a log record to this Span, optionally at a user-provided timestamp.

public

logEvent(eventName: *, payload: *): *

DEPRECATED

public

setBaggageItem(key: string, value: string): *

Sets a key:value pair on this Span that also propagates to future children of the associated Span.

public

Sets the string name for the logical operation this span represents.

public

setTag(key: string, value: any): *

Adds a single tag to the span.

public

Returns the Tracer object used to create this Span.

Public Methods

public addTags(keyValueMap: *): [type] source

Adds the given key value pairs to the set of span tags.

Multiple calls to addTags() results in the tags being the superset of all calls.

The behavior of setting the same key multiple times on the same span is undefined.

The supported type of the values is implementation-dependent. Implementations are expected to safely handle all types of values but may choose to ignore unrecognized / unhandle-able values (e.g. objects with cyclic references, function objects).

Params:

NameTypeAttributeDescription
keyValueMap *

Return:

[type]

[description]

public context(): SpanContext source

Returns the SpanContext object associated with this Span.

Return:

SpanContext

public finish(finishTime: number) source

Sets the end timestamp and finalizes Span state.

With the exception of calls to Span.context() (which are always allowed), finish() must be the last call made to any span instance, and to do otherwise leads to undefined behavior.

Params:

NameTypeAttributeDescription
finishTime number

Optional finish time in milliseconds as a Unix timestamp. Decimal values are supported for timestamps with sub-millisecond accuracy. If not specified, the current time (as defined by the implementation) will be used.

public getBaggageItem(key: string): string source

Returns the value for a baggage item given its key.

Params:

NameTypeAttributeDescription
key string

The key for the given trace attribute.

Return:

string

String value for the given key, or undefined if the key does not correspond to a set trace attribute.

public log(keyValuePairs: object, timestamp: number): * source

Add a log record to this Span, optionally at a user-provided timestamp.

For example:

span.log({
    size: rpc.size(),  // numeric value
    URI: rpc.URI(),  // string value
    payload: rpc.payload(),  // Object value
    "keys can be arbitrary strings": rpc.foo(),
});

span.log({
    "error.description": someError.description(),
}, someError.timestampMillis());

Params:

NameTypeAttributeDescription
keyValuePairs object

An object mapping string keys to arbitrary value types. All Tracer implementations should support bool, string, and numeric value types, and some may also support Object values.

timestamp number

An optional parameter specifying the timestamp in milliseconds since the Unix epoch. Fractional values are allowed so that timestamps with sub-millisecond accuracy can be represented. If not specified, the implementation is expected to use its notion of the current time of the call.

Return:

*

public logEvent(eventName: *, payload: *): * source

DEPRECATED

Params:

NameTypeAttributeDescription
eventName *
payload *

Return:

*

public setBaggageItem(key: string, value: string): * source

Sets a key:value pair on this Span that also propagates to future children of the associated Span.

setBaggageItem() enables powerful functionality given a full-stack opentracing integration (e.g., arbitrary application data from a web client can make it, transparently, all the way into the depths of a storage system), and with it some powerful costs: use this feature with care.

IMPORTANT NOTE #1: setBaggageItem() will only propagate baggage items to future causal descendants of the associated Span.

IMPORTANT NOTE #2: Use this thoughtfully and with care. Every key and value is copied into every local and remote child of the associated Span, and that can add up to a lot of network and cpu overhead.

Params:

NameTypeAttributeDescription
key string
value string

Return:

*

public setOperationName(name: string): * source

Sets the string name for the logical operation this span represents.

Params:

NameTypeAttributeDescription
name string

Return:

*

public setTag(key: string, value: any): * source

Adds a single tag to the span. See addTags() for details.

Params:

NameTypeAttributeDescription
key string
value any

Return:

*

public tracer(): Tracer source

Returns the Tracer object used to create this Span.

Return:

Tracer