class ContextTracer implements TracerInterface

This implementation of the TracerInterface manages your trace context throughout the request. It maintains a stack of Span records that are currently open allowing you to know the current context at any moment.

Methods

__construct(SpanContext $initialContext = null)

Create a new ContextTracer

mixed
inSpan(array $spanOptions, callable $callable, array $arguments = [])

Instrument a callable by creating a Span that manages the startTime and endTime.

startSpan(array $spanOptions = [])

Create a new Span. The start time is already set to the current time.

Scope
withSpan(Span $span)

Attaches the provided span as the current span and returns a Scope object which must be closed.

spans()

Return the spans collected.

addAttribute(string $attribute, string $value, array $options = [])

Add an attribute to the provided Span

addAnnotation(string $description, array $options = [])

Add an annotation to the provided Span

addLink(string $traceId, string $spanId, array $options = [])

Add a link to the provided Span

addMessageEvent(string $type, string $id, array $options = [])

Add an message event to the provided Span

spanContext()

Returns the current SpanContext

bool
enabled()

Whether or not this tracer is enabled.

Details

at line 46
__construct(SpanContext $initialContext = null)

Create a new ContextTracer

Parameters

SpanContext $initialContext [optional] The starting span context.

at line 67
mixed inSpan(array $spanOptions, callable $callable, array $arguments = [])

Instrument a callable by creating a Span that manages the startTime and endTime.

Parameters

array $spanOptions Options for the span. OpenCensus\Trace\Span::__construct()
callable $callable The callable to instrument.
array $arguments [optional] Arguments for the callable.

Return Value

mixed The result of the callable

at line 88
startSpan(array $spanOptions = [])

Create a new Span. The start time is already set to the current time.

The newly created span is not attached to the current context.

Parameters

array $spanOptions [description]

at line 106
Scope withSpan(Span $span)

Attaches the provided span as the current span and returns a Scope object which must be closed.

Parameters

Span $span

Return Value

Scope

at line 131
SpanData[] spans()

Return the spans collected.

Return Value

SpanData[]

at line 147
addAttribute(string $attribute, string $value, array $options = [])

Add an attribute to the provided Span

Parameters

string $attribute
string $value
array $options [optional] Configuration options.

 @type Span $span The span to add the attribute to.

at line 163
addAnnotation(string $description, array $options = [])

Add an annotation to the provided Span

Parameters

string $description
array $options [optional] Configuration options.

 @type Span $span The span to add the annotation to.
 @type array $attributes Attributes for this annotation.
 @type \DateTimeInterface|int|float $time The time of this event.

Add a link to the provided Span

Parameters

string $traceId
string $spanId
array $options [optional] Configuration options.

 @type Span $span The span to add the link to.
 @type string $type The relationship of the current span relative to
       the linked span: child, parent, or unspecified.
 @type array $attributes Attributes for this annotation.
 @type \DateTimeInterface|int|float $time The time of this event.

at line 203
addMessageEvent(string $type, string $id, array $options = [])

Add an message event to the provided Span

Parameters

string $type
string $id
array $options [optional] Configuration options.

 @type Span $span The span to add the message event to.
 @type int $uncompressedSize The number of uncompressed bytes sent or
       received.
 @type int $compressedSize The number of compressed bytes sent or
       received. If missing assumed to be the same size as
       uncompressed.
 @type \DateTimeInterface|int|float $time The time of this event.

at line 214
SpanContext spanContext()

Returns the current SpanContext

Return Value

SpanContext

at line 230
bool enabled()

Whether or not this tracer is enabled.

Return Value

bool