class RequestHandler

This class manages the logic for sampling and reporting a trace within a single request. It is not meant to be used directly -- instead, it should be managed by the Tracer as its singleton instance.

Constants

DEFAULT_ROOT_SPAN_NAME

ATTRIBUTE_MAP

Methods

__construct(ExporterInterface $exporter, SamplerInterface $sampler, PropagatorInterface $propagator, array $options = [])

Create a new RequestHandler.

onExit()

The function registered as the shutdown function. Cleans up the trace and reports using the provided ExporterInterface. Adds additional attributes to the root span detected from the response.

tracer()

Return the tracer used for this request.

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

Instrument a callable by creating a Span that manages the startTime and endTime. If an exception is thrown while executing the callable, the exception will be caught, the span will be closed, and the exception will be re-thrown.

startSpan(array $spanOptions = [])

Explicitly start a new Span. You will need to manage finishing the Span, including handling any thrown exceptions.

withSpan(Span $span)

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

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

addCommonRequestAttributes(array $headers)

No description

Details

at line 87
__construct(ExporterInterface $exporter, SamplerInterface $sampler, PropagatorInterface $propagator, array $options = [])

Create a new RequestHandler.

Parameters

ExporterInterface $exporter How to report the trace at the end of the request
SamplerInterface $sampler Which sampler to use for sampling requests
PropagatorInterface $propagator SpanContext propagator
array $options [optional] { Configuration options. See OpenCensus\Trace\Span::__construct() for the other available options.

 @type array $headers Optional array of headers to use in place of $_SERVER
 @type bool $skipReporting If true, skips registering of onExit handler.

}

at line 135
onExit()

The function registered as the shutdown function. Cleans up the trace and reports using the provided ExporterInterface. Adds additional attributes to the root span detected from the response.

at line 149
TracerInterface tracer()

Return the tracer used for this request.

Return Value

TracerInterface

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

Instrument a callable by creating a Span that manages the startTime and endTime. If an exception is thrown while executing the callable, the exception will be caught, the span will be closed, and the exception will be re-thrown.

Parameters

array $spanOptions
callable $callable
array $arguments

Return Value

mixed Returns whatever the callable returns

at line 178
Span startSpan(array $spanOptions = [])

Explicitly start a new Span. You will need to manage finishing the Span, including handling any thrown exceptions.

Parameters

array $spanOptions [optional] Options for the span. See OpenCensus\Trace\Span::__construct()

Return Value

Span

at line 190
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 204
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 219
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 257
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 262
addCommonRequestAttributes(array $headers)

Parameters

array $headers