Span represents a single operation within a trace. Spans are created by tracer.startSpan() or automatically by tracer.trace() and tracer.wrap().
Methods
setTag(key, value)
Sets a single tag on the span.
The tag key.
The tag value. Strings, numbers, and booleans are supported.
The
Span instance, for chaining.Setting
error: true marks the span as an error. You can also set error to an Error instance to capture the error message and stack trace.addTags(keyValuePairs)
Sets multiple tags on the span at once.
An object of key-value tag pairs to add to the span.
The
Span instance, for chaining.setOperationName(name)
Overrides the operation name of the span.
The new operation name.
The
Span instance, for chaining.finish(finishTime?)
Finishes the span, marking the end of the operation. After calling finish(), no further modifications to the span should be made.
An optional explicit finish time in milliseconds since epoch. Defaults to the current time.
When using
tracer.trace() or tracer.wrap(), spans are finished automatically. Only call finish() manually when using tracer.startSpan().log(keyValuePairs, timestamp?)
Adds a log event to the span.
Key-value pairs to log on the span.
Optional timestamp in milliseconds since epoch.
The
Span instance, for chaining.context()
Returns the SpanContext associated with this span. The context is safe to use even after the span has finished.
The
SpanContext for this span, containing the trace ID and span ID.tracer()
Returns the Tracer instance that created this span.
The
Tracer instance.addLink(link)
Adds a causal link to another span. Span links express relationships between spans that are not parent-child.
A link object.
Links added after span creation do not affect the sampling decision. Add links at span creation (via
SpanOptions.links) when possible.addLinks(links)
Adds multiple causal links to the span.
An array of link objects, each with a
context and optional attributes.