summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2023-04-09 21:20:35 +0300
committerAndrew Dolgov <[email protected]>2023-04-09 21:20:35 +0300
commitc1b3c99667c743d63317748d6338647eaf213184 (patch)
tree3e84f114096df8cd1b158a459f5fe5581f64cd96 /classes
parent8f3646a9c93a06f76f6abb31020fdb74b4b1fc59 (diff)
some tracer class fixes / unhardcode jaeger IP
Diffstat (limited to 'classes')
-rw-r--r--classes/config.php4
-rwxr-xr-xclasses/feeds.php2
-rwxr-xr-xclasses/pref/feeds.php2
-rw-r--r--classes/tracer.php62
4 files changed, 47 insertions, 23 deletions
diff --git a/classes/config.php b/classes/config.php
index dee6caa38..a9c75ae7b 100644
--- a/classes/config.php
+++ b/classes/config.php
@@ -192,6 +192,9 @@ class Config {
/** delay updates for this feed if received HTTP 429 (Too Many Requests) for this amount of seconds (base value, actual delay is base...base*2) */
const HTTP_429_THROTTLE_INTERVAL = "HTTP_429_THROTTLE_INTERVAL";
+ /** host running Jaeger collector to receive traces (disabled if empty) */
+ const JAEGER_REPORTING_HOST = "JAEGER_REPORTING_HOST";
+
/** default values for all global configuration options */
private const _DEFAULTS = [
Config::DB_TYPE => [ "pgsql", Config::T_STRING ],
@@ -249,6 +252,7 @@ class Config {
Config::HTTP_USER_AGENT => [ 'Tiny Tiny RSS/%s (https://tt-rss.org/)',
Config::T_STRING ],
Config::HTTP_429_THROTTLE_INTERVAL => [ 3600, Config::T_INT ],
+ Config::JAEGER_REPORTING_HOST => [ "", Config::T_STRING ],
];
/** @var Config|null */
diff --git a/classes/feeds.php b/classes/feeds.php
index 1ce19b098..9707d5e45 100755
--- a/classes/feeds.php
+++ b/classes/feeds.php
@@ -987,7 +987,7 @@ class Feeds extends Handler_Protected {
* @throws PDOException
*/
static function _get_counters($feed, bool $is_cat = false, bool $unread_only = false, ?int $owner_uid = null): int {
- $scope = Tracer::start(__FUNCTION__, ['tags' => ['args' => json_encode(func_get_args())]]);
+ $scope = Tracer::start(__FUNCTION__, [], func_get_args());
$n_feed = (int) $feed;
$need_entries = false;
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
index 00d26d4f6..42adf23ca 100755
--- a/classes/pref/feeds.php
+++ b/classes/pref/feeds.php
@@ -1104,7 +1104,7 @@ class Pref_Feeds extends Handler_Protected {
* @return array<string, mixed>
*/
private function feedlist_init_feed(int $feed_id, ?string $title = null, bool $unread = false, string $error = '', string $updated = ''): array {
- $scope = Tracer::start(__FUNCTION__, ['tags' => ['args' => json_encode(func_get_args())]]);
+ $scope = Tracer::start(__FUNCTION__, [], func_get_args());
if (!$title)
$title = Feeds::_get_title($feed_id, false);
diff --git a/classes/tracer.php b/classes/tracer.php
index fde99927d..1326f4344 100644
--- a/classes/tracer.php
+++ b/classes/tracer.php
@@ -3,39 +3,59 @@ use OpenTracing\GlobalTracer;
use OpenTracing\Scope;
class Tracer {
+ /** @var Tracer $instance */
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
+ $jaeger_host = Config::get(Config::JAEGER_REPORTING_HOST);
+
+ if ($jaeger_host) {
+ $config = new \Jaeger\Config(
+ [
+ 'sampler' => [
+ 'type' => \Jaeger\SAMPLER_TYPE_CONST,
+ 'param' => true,
+ ],
+ 'logging' => true,
+ "local_agent" => [
+ "reporting_host" => $jaeger_host,
+ "reporting_port" => 6832
+ ],
+ 'dispatch_mode' => \Jaeger\Config::JAEGER_OVER_BINARY_UDP,
],
- 'dispatch_mode' => \Jaeger\Config::JAEGER_OVER_BINARY_UDP,
- ],
- 'tt-rss'
- );
+ 'tt-rss'
+ );
- $config->initializeTracer();
+ $config->initializeTracer();
- register_shutdown_function(function() {
- $tracer = GlobalTracer::get();
- $tracer->flush();
- });
+ register_shutdown_function(function() {
+ $tracer = GlobalTracer::get();
+ $tracer->flush();
+ });
+ }
}
- private function _start(string $name, array $options = []) {
+ /**
+ * @param string $name
+ * @param array<mixed> $options
+ * @param array<string> $args
+ * @return Scope
+ */
+ private function _start(string $name, array $options = [], array $args = []): Scope {
$tracer = GlobalTracer::get();
+
+ $options['tags']['args'] = json_encode($args);
+
return $tracer->startActiveSpan($name, $options);
}
- public static function start(string $name, array $options = []) : Scope {
+ /**
+ * @param string $name
+ * @param array<string> $options
+ * @param array<string> $args
+ * @return Scope
+ */
+ public static function start(string $name, array $options = [], array $args = []) : Scope {
return self::get_instance()->_start($name, $options);
}