PHP code example of yuanlj-tea / jaeger

1. Go to this page and download the library: Download yuanlj-tea/jaeger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yuanlj-tea / jaeger example snippets




aeger\Config;
use OpenTracing\GlobalTracer;

$config = new Config(
    [
        'sampler' => [
            'type' => Jaeger\SAMPLER_TYPE_CONST,
            'param' => true,
        ],
        'logging' => true,
    ],
    'your-app-name'
);
$config->initializeTracer();

$tracer = GlobalTracer::get();

$scope = $tracer->startActiveSpan('TestSpan', []);
$scope->close();

$tracer->flush();

class Config
{
    const ZIPKIN_OVER_COMPACT_UDP   = "zipkin_over_compact_udp";
    const JAEGER_OVER_BINARY_UDP    = "jaeger_over_binary_udp";
    const JAEGER_OVER_BINARY_HTTP   = "jaeger_over_binary_http";
    ...
}

// config.php

use Jaeger\Config;

return [
    'sampler' => [
        'type' => Jaeger\SAMPLER_TYPE_CONST,
        'param' => true,
    ],
    'logging' => true,
    "tags" => [
        // process. prefix works only with JAEGER_OVER_HTTP, JAEGER_OVER_BINARY
        // otherwise it will be shown as simple global tag
        "process.process-tag-key-1" => "process-value-1", // all tags with `process.` prefix goes to process section
        "process.process-tag-key-2" => "process-value-2", // all tags with `process.` prefix goes to process section
        "global-tag-key-1" => "global-tag-value-1", // this tag will be appended to all spans
        "global-tag-key-2" => "global-tag-value-2", // this tag will be appended to all spans
    ],
    "local_agent" => [
        "reporting_host" => "localhost", 
//        You can override port by setting local_agent.reporting_port value   
        "reporting_port" => 6832
    ],
//     Different ways to send data to Jaeger. Config::ZIPKIN_OVER_COMPACT - default):
    'dispatch_mode' => Config::JAEGER_OVER_BINARY_UDP,
];

use Jaeger\Config;

$config = new Config(
    [
        "ip_version" => Config::IPV6, // <-- or use Config::IP_VERSION constant
        'logging' => true,
        'dispatch_mode' => Config::JAEGER_OVER_BINARY_UDP,
    ],
    'serviceNameExample',
);
$config->initializeTracer();

use Jaeger\Config;

$config = new Config(
    [
        Config::IP_VERSION => Config::IPV6, // <--
        'logging' => true,
        'dispatch_mode' => Config::JAEGER_OVER_BINARY_UDP,
    ],
    'serviceNameExample',
);
$config->initializeTracer();
bash
composer