Search code examples
phpdockerdocker-composeopentracingjaeger

PHP OpenTracing + Jaeger: service does not appear at Jaeger


I was trying to implement the OpenTracing + Jaeger to my PHP project, following the "Get started" example there https://github.com/jonahgeorge/jaeger-client-php

Tracer, spans and scopes have been created successfully, but Jaeger does not see my service.

There are my .php and docker-compose.yml files below:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Jaeger\Config;
use OpenTracing\GlobalTracer;

class OpenTracing
{
    public function __construct()
    {
            $config = new Config(
                [
                    'sampler' => [
                        'type' => 'const',
                        'param' => true,
                    ],
                    'logging' => true,
                    'local_agent' => [
                        'reporting_host' => 'localhost',
                        'reporting_port' => 5775
                    ]
                ],
                'test.service'
            );
            $config->initializeTracer();

            $tracer = GlobalTracer::get();

            $parent = $tracer->startActiveSpan('parent');
            sleep(1);
            $child = $tracer->startActiveSpan('child');
            $child->close();
            sleep(3);
            $parent->close();
    }
}
version: '3'
services:
  jaeger:
    image: jaegertracing/all-in-one:1.6
    container_name: as-jaeger
    ports:
      - "5775:5775/udp"
      - "6831:6831/udp"
      - "6832:6832/udp"
      - "5778:5778"
      - "16686:16686"
      - "14268:14268"
      - "9411:9411"
    environment:
      - COLLECTOR_ZIPKIN_HTTP_PORT=9411

Solution

  • 'reporting_host' must be not 'localhost', but 'jaeger', just as service in docker-compose.yml called. 'reporting_host' => 'jaeger',

    Also, I needed to add $tracer->flush(); after all, it closes all the entities and does sending via UDP behind the scenes.