Coder Social home page Coder Social logo

zipkin-php-opentracing's Introduction

Zipkin PHP OpenTracing

Travis CI OpenTracing Badge Total Downloads Minimum PHP Version License

Zipkin implementation for OpenTracingTracer in PHP.

This library allows OpenTracing API consumers to use Zipkin as their tracing backend. For details on how to work with spans and traces we suggest looking at the documentation and README from the OpenTracing API.

Getting started

Required Reading

In order to understand OpenTracing API, one must first be familiar with the OpenTracing project and terminology more generally.

To understand how Zipkin works, you can look at Zipkin Architecture and Zipkin PHP documentation.

Installation

composer require jcchavezs/zipkin-opentracing

Usage

Firstly, we need to setup a tracer:

use OpenTracing\GlobalTracer;
use Psr\Log\NullLogger;
use Zipkin\Endpoint;
use Zipkin\Samplers\BinarySampler;
use Zipkin\TracingBuilder;
use Zipkin\Reporters\Http;

$endpoint = Endpoint::create('my_service', '127.0.0.1', null, 8081);
$reporter = new Zipkin\Reporters\Http();
$sampler = BinarySampler::createAsAlwaysSample();
$tracing = TracingBuilder::create()
    ->havingLocalEndpoint($endpoint)
    ->havingSampler($sampler)
    ->havingReporter($reporter)
    ->build();

$zipkinTracer = new ZipkinOpenTracing\Tracer($tracing);

GlobalTracer::set($zipkinTracer); // optional

Creating Spans

Propagation of context

Flushing Spans to the agent

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. It is mandatory to execute the Tracer::flush() after the response is served to the client by using register_shutdown_function.

use OpenTracing\GlobalTracer;

$application->run();

register_shutdown_function(function() {
    GlobalTracer::get()->flush();
});

Contribution

Run tests

composer test

Fix lint

composer fix-lint

zipkin-php-opentracing's People

Contributors

jcchavezs avatar eligijusvitkauskas-home24 avatar alexeyshockov avatar limingxinleo avatar cjone0102 avatar ellisv avatar peter279k avatar johanneskonst avatar reasno avatar lpf32 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.