Download the PHP package mix/opentracing without Composer
On this page you can find all versions of the php package mix/opentracing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package opentracing
OpenTracing API for PHP
PHP library for the OpenTracing's API.
Required Reading
In order to understand the library, one must first be familiar with the OpenTracing project and specification more specifically.
Installation
OpenTracing-PHP can be installed via Composer:
Usage
When consuming this library one really only need to worry about a couple of key
abstractions: the Tracer::startActiveSpan
and Tracer::startSpan
method,
the Span
interface, the Scope
interface and binding a Tracer
at bootstrap time. Here are code snippets
demonstrating some important use cases:
Singleton initialization
The simplest starting point is to set the global tracer. As early as possible, do:
Creating a Span given an existing Request
To start a new Span
, you can use the startSpan
method.
Starting a new trace by creating a "root span"
It's always possible to create a "root" Span
with no parent or other causal reference.
Active Spans and Scope Manager
For most use cases, it is recommended that you use the Tracer::startActiveSpan
function for
creating new spans.
An example of a linear, two level deep span tree using active spans looks like this in PHP code:
When using the Tracer::startActiveSpan
function the underlying tracer uses an
abstraction called scope manager to keep track of the currently active span.
Starting an active span will always use the currently active span as a parent. If no parent is available, then the newly created span is considered to be the root span of the trace.
Unless you are using asynchronous code that tracks multiple spans at the same
time, such as when using cURL Multi Exec or MySQLi Polling it is recommended that you
use Tracer::startActiveSpan
everywhere in your application.
The currently active span gets automatically finished when you call $scope->close()
as you can see in the previous examples.
If you don't want a span to automatically close when $scope->close()
is called
then you must specify 'finish_span_on_close'=> false,
in the $options
argument of startActiveSpan
.
Creating a child span assigning parent manually
Creating a child span using automatic active span management
Every new span will take the active span as parent and it will take its spot.
Serializing to the wire
Deserializing from the wire
When using http header for context propagation you can use either the Request
or the $_SERVER
variable:
Flushing Spans
PHP as a request scoped language has no simple means to pass the collected spans
data to a background process without blocking the main request thread/process.
The OpenTracing API makes no assumptions about this, but for PHP that might
cause problems for Tracer implementations. This is why the PHP API contains a
flush
method that allows to trigger a span sending out of process.
This is optional, tracers can decide to immediately send finished spans to a backend. The flush call can be implemented as a NO-OP for these tracers.
Using StartSpanOptions
Passing options to the pass can be done using either an array or the SpanOptions wrapper object. The following keys are valid:
start_time
is a float, int or\DateTime
representing a timestamp with arbitrary precision.child_of
is an object of typeOpenTracing\SpanContext
orOpenTracing\Span
.references
is an array ofOpenTracing\Reference
.tags
is an array with string keys and scalar values that represent OpenTracing tags.finish_span_on_close
is a boolean that determines whether a span should be finished or not when the scope is closed.
Propagation Formats
The propagation formats should be implemented consistently across all tracers. If you want to implement your own format, then don't reuse the existing constants. Tracers will throw an exception if the requested format is not handled by them.
-
Tracer::FORMAT_TEXT_MAP
should represent the span context as a key value map. There is no assumption about the semantics where the context is coming from and sent to. -
Tracer::FORMAT_HTTP_HEADERS
should represent the span context as HTTP header lines in an array list. For two context details "Span-Id" and "Trace-Id", the result would be['Span-Id: abc123', 'Trace-Id: def456']
. This definition can be passed directly tocurl
andfile_get_contents
. Tracer::FORMAT_BINARY
makes no assumptions about the data format other than it is proprietary and each Tracer can handle it as it wants.
Mock implementation
OpenTracing PHP comes with a mock implementation, it has three purposes:
- Helps to iron the API.
- Works as a reference implementation.
- Enhances vendor agnostic unit testing as it allows developers to inspect the tracing objects in order to do assertions about them.
Coding Style
OpenTracing PHP follows the PSR-2 coding standard and the PSR-4 autoloading standard.
License
All the open source contributions are under the terms of the Apache-2.0 License.