All Projects → jcchavezs → Opentracing Php

jcchavezs / Opentracing Php

Licence: gpl-3.0
MOVED TO https://github.com/opentracing/opentracing-php

Projects that are alternatives of or similar to Opentracing Php

Haystack
Top level repository for Haystack, containing documentation and deployment scripts
Stars: ✭ 261 (+1350%)
Mutual labels:  opentracing
Go Microservice Helpers
A collection of handy snippets that simplify creation of GRPC servers and clients
Stars: ✭ 400 (+2122.22%)
Mutual labels:  opentracing
Inspectit
inspectIT is the leading Open Source APM (Application Performance Management) tool for analyzing your Java (EE) applications.
Stars: ✭ 513 (+2750%)
Mutual labels:  opentracing
Pandora
A Manageable, Measurable and Traceable Node.js Application Manager represented by Alibaba powered by TypeScript
Stars: ✭ 3,084 (+17033.33%)
Mutual labels:  opentracing
Hyperf
🚀 A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.
Stars: ✭ 4,206 (+23266.67%)
Mutual labels:  opentracing
Opentracing Php
OpenTracing API for PHP
Stars: ✭ 407 (+2161.11%)
Mutual labels:  opentracing
go-jaeger-trace
Simple demo on OpenTracing with Go
Stars: ✭ 18 (+0%)
Mutual labels:  opentracing
Opentracing Specification Zh
OpenTracing标准(中文版) `zh` (Chinese) translation of the opentracing/specification
Stars: ✭ 717 (+3883.33%)
Mutual labels:  opentracing
Sqlhooks
Attach hooks to any database/sql driver
Stars: ✭ 397 (+2105.56%)
Mutual labels:  opentracing
Jaeger Client Node
Jaeger Bindings for OpenTracing API for Node.js
Stars: ✭ 485 (+2594.44%)
Mutual labels:  opentracing
Java Spring Cloud
Distributed tracing for Spring Boot, Cloud and other Spring projects
Stars: ✭ 326 (+1711.11%)
Mutual labels:  opentracing
Go Project Sample
Introduce the best practice experience of Go project with a complete project example.通过一个完整的项目示例介绍Go语言项目的最佳实践经验.
Stars: ✭ 344 (+1811.11%)
Mutual labels:  opentracing
Echo Web
Go web framework Echo example. 在线演示☞迁移ing❌
Stars: ✭ 409 (+2172.22%)
Mutual labels:  opentracing
Jaeger Client Csharp
C# client (tracer) for Jaeger
Stars: ✭ 284 (+1477.78%)
Mutual labels:  opentracing
Gf
GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
Stars: ✭ 6,501 (+36016.67%)
Mutual labels:  opentracing
microprofile.training
home of http://microprofile.training sample app
Stars: ✭ 19 (+5.56%)
Mutual labels:  opentracing
Jaeger Kubernetes
Support for deploying Jaeger into Kubernetes
Stars: ✭ 402 (+2133.33%)
Mutual labels:  opentracing
Molten
php probe for zipkin and opentracing
Stars: ✭ 740 (+4011.11%)
Mutual labels:  opentracing
Jaeger Ui
Web UI for Jaeger
Stars: ✭ 639 (+3450%)
Mutual labels:  opentracing
Zipkin Go Opentracing
OpenTracing Bridge for Zipkin Go
Stars: ✭ 472 (+2522.22%)
Mutual labels:  opentracing

OpenTracing API for PHP

Build Status OpenTracing Badge Total Downloads

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:

composer require jcchavezs/opentracing-php

Usage

When consuming this library one really only need to worry about a couple of key abstractions: the Tracer::startSpan method, the Span 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:

    use OpenTracing\GlobalTracer;
    use AnOpenTracingImplementation\MyTracer;
    
    GlobalTracer::set(new MyTracer());

Creating a Span given an existing Request

To start a new Span, you can use the StartSpanFromContext method.

    use Psr\Http\Message\RequestInterface;

    ...

    $spanContext = GlobalTracer::get()->extract(
        Propagator::HTTP_HEADERS,
        HttpHeaders::withHeaders($request->getHeaders())
    );
    
    function doSomething(SpanContext $spanContext, ...) {
        ...
        
        $span = GlobalTracer::get()->startSpan('my_span', ChildOf::withContext($spanContext));
        
        ...
        
        $span->log([
            'event' => 'soft error',
            'type' => 'cache timeout',
            'waiter.millis' => 1500,
        ])
        
        $span->finish();
    }

Starting an empty trace by creating a "root span"

It's always possible to create a "root" Span with no parent or other causal reference.

    $span = $tracer->startSpan('my_span');
    ...
    $span->finish();

Creating a (child) Span given an existing (parent) Span

    use OpenTracing\SpanReference\ChildOf;

    function xyz(Span $parentSpan, ...) {
        ...
        $span = GlobalTracer::get()->startSpan(
            'my_span',
            ChildOf::withContext($span->context())
        );
        
        $span->finish();
        ...
    }

Serializing to the wire

    use OpenTracing\Carriers\HttpHeaders as HttpHeadersCarrier;
    use OpenTracing\Context;
    use OpenTracing\GlobalTracer;
    
    ...
    
    $tracer = GlobalTracer::get(); 
    
    $spanContext = $tracer->extract(
        Propagator::HTTP_HEADERS,
        HttpHeaders::withHeaders($request->getHeaders())
    );
    
    try {
        $span = $tracer->startSpanWithOptions('my_span', ['child_of' => $spanContext]);

        $client = new GuzzleHttp\Client;
        
        $request = new \GuzzleHttp\Psr7\Request('GET', 'http://myservice');
        
        $tracer->inject(
            $span->context(),
            Propagator::HTTP_HEADERS,
            HttpHeadersCarrier::withHeaders($request->getHeaders())
        )

        $client->send($request);
        ...
    } catch (\Exception $e) {
        ...
    }
    ...        

Deserializing from the wire

When using http header for context propagation you can use either the Request or the $_SERVER variable:

    use OpenTracing\Carriers\HttpHeaders;
    use OpenTracing\SpanReference\ChildOf;
    use OpenTracing\GlobalTracer;
    
    $request = Request::createFromGlobals();
    $tracer = GlobalTracer::get();
    $spanContext = $tracer->extract(Propagator::HTTP_HEADERS, HttpHeaders::fromRequest($request));
    $tracer->startSpan('my_span', ChildOf::withContext($spanContext)); 

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.

<?php

use OpenTracing\GlobalTracer;

// Do application work, buffer spans in memory
$application->run();

fastcgi_finish_request();

$tracer = GlobalTracer::get();
$tracer->flush(); // release buffer to backend

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 Span Options

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 type OpenTracing\SpanContext or OpenTracing\Span.
  • references is an array of OpenTracing\SpanReference.
  • tags is an array with string keys and scalar values that represent OpenTracing tags.
<?php

use OpenTracing\SpanOptions;

$span = $tracer->createSpan('my_span', SpanOptions::create([
    'child_of' => $parentContext,
    'tags' => ['foo' => 'bar'],
    'start_time' => time(),
]));

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 represents 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 to curl and file_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.

Coding Style

Opentracing PHP follows the PSR-2 coding standard and the PSR-4 autoloading standard.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].