PHPackages                             vantt/opentracing-jaeger-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. vantt/opentracing-jaeger-php

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

vantt/opentracing-jaeger-php
============================

php opentracing client for jaeger

v2.1.1(5y ago)07Apache-2.0PHPPHP ^7.1||^8.0

Since Feb 18Pushed 5y agoCompare

[ Source](https://github.com/vantt/opentracing-jaeger-php)[ Packagist](https://packagist.org/packages/vantt/opentracing-jaeger-php)[ RSS](/packages/vantt-opentracing-jaeger-php/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (7)Used By (0)

[![Build Status](https://camo.githubusercontent.com/8af401c6a215ebea87888f3c4f7bfa81368d51cccb5c483ffca963f6971b7188/68747470733a2f2f7472617669732d63692e636f6d2f6a756b796c696e2f6a61656765722d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/jukylin/jaeger-php)[![Minimum PHP Version](https://camo.githubusercontent.com/4cbdbfeca62402b9ca3d48503f2bf66fc9809569bcd6de47196d39fecff71e72/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230352e362d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/cea7f9f03a2ba020aef891ad619ed47396a197d9e0a3a3b0c44c0d1ca1b09536/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a756b796c696e2f6a61656765722d7068702e737667)](https://github.com/jukylin/jaeger-php/blob/master/LICENSE)[![Coverage Status](https://camo.githubusercontent.com/b44a0e704f84576dbf74ab564000a06882e866b1dec13d73de50c1a862f3a1dd/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6a756b796c696e2f6a61656765722d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/jukylin/jaeger-php?branch=master)

jaeger-php
==========

[](#jaeger-php)

Install
-------

[](#install)

Install via composer.

```
composer config minimum-stability dev
composer require vantt/opentracing-jaeger-php

```

Init Jaeger-php
---------------

[](#init-jaeger-php)

```
$config = Config::getInstance();
$tracer = $config->initTracer('example', '0.0.0.0:6831');
```

128bit
------

[](#128bit)

```
$config->gen128bit();
```

Extracting span context from request header
-------------------------------------------

[](#extracting-span-context-from-request-header)

```
$rootContext = $tracer->extract(Formats\TEXT_MAP, getallheaders());
```

Injecting span context into request header
------------------------------------------

[](#injecting-span-context-into-request-header)

```
use OpenTracing\Formats;

$arrHeader = [];
$tracer->inject($span->getContext(), Formats\TEXT_MAP, $arrHeader);
$httpClient->request($url, $arrHeader);
```

Usage
-----

[](#usage)

### Using `SpanBuilder`

[](#using-spanbuilder)

This library extends the original api to add a new method `buildSpan(operationName):SpanBuilderInterface`. When consuming this library one really only need to worry about the `buildSpan(operationName)` on the `$tracer` instance: `Tracer::buildSpan(operationName)`

With SpanBuilder, we can leverage the power of editor to do auto code completion for us with following APIs:

- `asChildOf($parentContext)` is an object of type `OpenTracing\SpanContext` or `OpenTracing\Span`.
- `withStartTimestamp(time())` is a float, int or `\DateTime` representing a timestamp with arbitrary precision.
- `withTag(key,val)` is an array with string keys and scalar values that represent OpenTracing tags.
- `ignoreActiveSpan(bool)`
- `finishSpanOnClose()` is a boolean that determines whether a span should be finished or not when the scope is closed.
- `addReference()`

Here are code snippets demonstrating some important use cases:

```
$rootContext = $tracer->extract(Formats\TEXT_MAP, getallheaders());
$span = $tracer->buildSpan('my_span')
               ->asChildOf($rootContext)
               ->withTag('foo', 'bar')
               ->withStartTimestamp(time())
               ->start();

$scope = $tracer->buildSpan('my_span')
                ->asChildOf($rootContext)
                ->withTag('foo', 'bar')
                ->withStartTimestamp(time())
                ->startActive();
```

### Creating a Span given an existing Request

[](#creating-a-span-given-an-existing-request)

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

```
use OpenTracing\Formats;
use OpenTracing\GlobalTracer;

...

// extract the span context
$spanContext = GlobalTracer::get()->extract(
    Formats\TEXT_MAP,
    getallheaders()
);

function doSomething() {
    ...

    // start a new span called 'my_span' and make it a child of the $spanContext
    $span = GlobalTracer::get()->buildSpan('my_operation_span_name')
                               ->start();
    ...

    // add some logs to the span
    $span->log([
        'event' => 'soft error',
        'type' => 'cache timeout',
        'waiter.millis' => 1500,
    ]);

    // finish the the span
    $span->finish();
}
```

### Starting a new trace by creating a "root span"

[](#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.

```
$span = $tracer->buildSpan('my_first_span')->start();
...
$span->finish();
```

### Active Spans and Scope Manager

[](#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:

```
// At dispatcher level
$scope = $tracer->buildSpan('request')->start();
...
$scope->close();
```

```
// At controller level
$scope = $tracer->buildSpan('controller')->startActive();
...
$scope->close();
```

```
// At RPC calls level
$scope = $tracer->buildSpan('http')->startActive();
file_get_contents('http://php.net');
$scope->close();
```

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-assigning-parent-manually)

```
$tracer = GlobalTracer::get();
$parent = $tracer->startSpan('parent');

$child = $tracer->buildSpan('child_operation')
                ->asChildOf($parent)
                ->start();
...

$child->finish();

...

$parent->finish();
```

#### Creating a child span using automatic active span management

[](#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.

```
$parent = GlobalTracer::get()->buildSpan('parent')->startActive();

...

/*
 * Since the parent span has been created by using startActiveSpan we don't need
 * to pass a reference for this child span
 */
$child = GlobalTracer::get()->buildSpan('my_second_span')->startActive();

...

$child->close();

...

$parent->close();
```

### Serializing to the wire

[](#serializing-to-the-wire)

```
use GuzzleHttp\Client;
use OpenTracing\Formats;

...

$tracer = GlobalTracer::get();

$spanContext = $tracer->extract(
    Formats\HTTP_HEADERS,
    getallheaders()
);

try {
    $span = $tracer->buildSpan('my_span')->asChildOf($spanContext)->start();

    $client = new Client;

    $headers = [];

    $tracer->inject(
        $span->getContext(),
        Formats\HTTP_HEADERS,
        $headers
    );

    $request = new \GuzzleHttp\Psr7\Request('GET', 'http://myservice', $headers);
    $client->send($request);
    ...

} catch (\Exception $e) {
    ...
}
...
```

### Deserializing from the wire

[](#deserializing-from-the-wire)

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

```
use OpenTracing\GlobalTracer;
use OpenTracing\Formats;

$tracer = GlobalTracer::get();
$spanContext = $tracer->extract(Formats\TEXT_MAP, getallheaders());
$tracer->buildSpan('my_span')->asChildOf($spanContext)->startActive();
```

Start Span
----------

[](#start-span)

```
$serverSpan = $tracer->startSpan('example HTTP', ['child_of' => $spanContext]);
```

Distributed context propagation
-------------------------------

[](#distributed-context-propagation)

```
$serverSpan->addBaggageItem("version", "2.0.0");
```

Inject into Superglobals
------------------------

[](#inject-into-superglobals)

```
$clientTrace->inject($clientSpan1->spanContext, Formats\TEXT_MAP, $_SERVER);
```

Tags and Log
------------

[](#tags-and-log)

```
// tags are searchable in Jaeger UI
$span->setTag('http.status', '200');

// log record
$span->log(['error' => 'HTTP request timeout']);
```

Close Tracer
------------

[](#close-tracer)

```
$config->setDisabled(true);
```

Zipkin B3 Propagation
---------------------

[](#zipkin-b3-propagation)

*no support for* `Distributed context propagation`

```
$config::$propagator = \Jaeger\Constants\PROPAGATOR_ZIPKIN;
```

Finish span and flush Tracer
----------------------------

[](#finish-span-and-flush-tracer)

```
$span->finish();
$config->flush();
```

Features
--------

[](#features)

- Transports

    - via Thrift over UDP
- Sampling

    - ConstSampler
    - ProbabilisticSampler

Reference
---------

[](#reference)

[OpenTracing](https://opentracing.io/)

[Jaeger](https://uber.github.io/jaeger/)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 81.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

1905d ago

Major Versions

v1.0.0 → v2.0.02021-02-18

PHP version history (2 changes)v1.0.0PHP ^5.6||^7.0

v2.0.0PHP ^7.1||^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/fb74e84aa06d3a4181a60fc821d6ec52f52b14b4d2f27af4f3c7544c5a135bcf?d=identicon)[vantt](/maintainers/vantt)

---

Top Contributors

[![jky-yy](https://avatars.githubusercontent.com/u/185590763?v=4)](https://github.com/jky-yy "jky-yy (211 commits)")[![vantt](https://avatars.githubusercontent.com/u/940988?v=4)](https://github.com/vantt "vantt (12 commits)")[![dmnbars](https://avatars.githubusercontent.com/u/7151631?v=4)](https://github.com/dmnbars "dmnbars (7 commits)")[![gitsrc](https://avatars.githubusercontent.com/u/34047788?v=4)](https://github.com/gitsrc "gitsrc (6 commits)")[![cawolf](https://avatars.githubusercontent.com/u/1932623?v=4)](https://github.com/cawolf "cawolf (5 commits)")[![ttrig](https://avatars.githubusercontent.com/u/2156132?v=4)](https://github.com/ttrig "ttrig (3 commits)")[![monteiro](https://avatars.githubusercontent.com/u/74459?v=4)](https://github.com/monteiro "monteiro (3 commits)")[![vyuldashev](https://avatars.githubusercontent.com/u/1809081?v=4)](https://github.com/vyuldashev "vyuldashev (2 commits)")[![RunnerLee](https://avatars.githubusercontent.com/u/7436388?v=4)](https://github.com/RunnerLee "RunnerLee (2 commits)")[![xJakub](https://avatars.githubusercontent.com/u/1308245?v=4)](https://github.com/xJakub "xJakub (1 commits)")[![colin-at-kiva](https://avatars.githubusercontent.com/u/54085523?v=4)](https://github.com/colin-at-kiva "colin-at-kiva (1 commits)")[![corerman](https://avatars.githubusercontent.com/u/7157314?v=4)](https://github.com/corerman "corerman (1 commits)")[![ldjdd](https://avatars.githubusercontent.com/u/16792514?v=4)](https://github.com/ldjdd "ldjdd (1 commits)")[![sadok-f](https://avatars.githubusercontent.com/u/533384?v=4)](https://github.com/sadok-f "sadok-f (1 commits)")[![xbing2002](https://avatars.githubusercontent.com/u/37572472?v=4)](https://github.com/xbing2002 "xbing2002 (1 commits)")[![aogier](https://avatars.githubusercontent.com/u/321364?v=4)](https://github.com/aogier "aogier (1 commits)")

---

Tags

tracejaegeropentracing

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vantt-opentracing-jaeger-php/health.svg)

```
[![Health](https://phpackages.com/badges/vantt-opentracing-jaeger-php/health.svg)](https://phpackages.com/packages/vantt-opentracing-jaeger-php)
```

###  Alternatives

[jonahgeorge/jaeger-client-php

Jaeger Bindings for PHP OpenTracing API

1484.4M18](/packages/jonahgeorge-jaeger-client-php)[jukylin/jaeger-php

php client for jaeger

2261.6M6](/packages/jukylin-jaeger-php)[lvht/jaeger

php client for jaeger

1240.5k](/packages/lvht-jaeger)[koriym/xdebug-mcp

Universal PHP Xdebug MCP Server with AI-optimized debugging support

4011.6k1](/packages/koriym-xdebug-mcp)[kuria/error

Makes handling and debugging PHP errors suck less

1920.0k2](/packages/kuria-error)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
