diff options
author | Andrew Dolgov <[email protected]> | 2023-04-09 20:50:33 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2023-04-09 20:50:33 +0300 |
commit | 8f3646a9c93a06f76f6abb31020fdb74b4b1fc59 (patch) | |
tree | 4e6c9f39e0623ef70bedfee014f1bd20603f89ad /classes/tracer.php | |
parent | a37eab2610a0a2bcb655258781c1c7e925dc94c0 (diff) |
exp: jaeger tracing
Diffstat (limited to 'classes/tracer.php')
-rw-r--r-- | classes/tracer.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/classes/tracer.php b/classes/tracer.php new file mode 100644 index 000000000..fde99927d --- /dev/null +++ b/classes/tracer.php @@ -0,0 +1,49 @@ +<?php +use OpenTracing\GlobalTracer; +use OpenTracing\Scope; + +class Tracer { + private static $instance; + + public function __construct() { + $config = new \Jaeger\Config( + [ + 'sampler' => [ + 'type' => \Jaeger\SAMPLER_TYPE_CONST, + 'param' => true, + ], + 'logging' => true, + "local_agent" => [ + "reporting_host" => "172.17.172.39", + "reporting_port" => 6832 + ], + 'dispatch_mode' => \Jaeger\Config::JAEGER_OVER_BINARY_UDP, + ], + 'tt-rss' + ); + + $config->initializeTracer(); + + register_shutdown_function(function() { + $tracer = GlobalTracer::get(); + $tracer->flush(); + }); + } + + private function _start(string $name, array $options = []) { + $tracer = GlobalTracer::get(); + return $tracer->startActiveSpan($name, $options); + } + + public static function start(string $name, array $options = []) : Scope { + return self::get_instance()->_start($name, $options); + } + + public static function get_instance() : Tracer { + if (self::$instance == null) + self::$instance = new self(); + + return self::$instance; + } + +} |