Skip to content

Commit

Permalink
added tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
mmelograno committed Jan 10, 2024
1 parent 54870d6 commit a774876
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,14 @@ public function getTreatmentsByFlagSet(
?array $attributes
): array {
try {
$id = $this->tracer->makeId();
$method = Tracer::METHOD_GET_TREATMENTS_BY_FLAG_SET;
$this->tracer->trace(TEF::forStart($method, $id, $this->tracer->includeArgs() ? func_get_args() : []));
// @TODO implement cache for this method

$this->tracer->trace(TEF::forRPCStart($method, $id));
$results = $this->lm->getTreatmentsByFlagSet($key, $bucketingKey, $flagSet, $attributes);
$this->tracer->trace(TEF::forRPCEnd($method, $id));
foreach ($results as $feature => $result) {
list($treatment, $ilData) = $result;
$toReturn[$feature] = $treatment;
Expand All @@ -174,8 +179,11 @@ public function getTreatmentsByFlagSet(
$this->cache->setMany($key, $attributes, $toReturn);
return $toReturn;
} catch (\Exception $exc) {
$this->tracer->trace(TEF::forException($method, $id, $exc));
$this->logger->error($exc);
return array();
} finally {
$this->tracer->trace(TEF::forEnd($method, $id));
}
}

Expand All @@ -186,9 +194,14 @@ public function getTreatmentsWithConfigByFlagSet(
?array $attributes = null
): array {
try {
$id = $this->tracer->makeId();
$method = Tracer::METHOD_GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET;
$this->tracer->trace(TEF::forStart($method, $id, $this->tracer->includeArgs() ? func_get_args() : []));
// @TODO implement cache for this method

$this->tracer->trace(TEF::forRPCStart($method, $id));
$results = $this->lm->getTreatmentsWithConfigByFlagSet($key, $bucketingKey, $flagSet, $attributes);
$this->tracer->trace(TEF::forRPCEnd($method, $id));
foreach ($results as $feature => $result) {
list($treatment, $ilData, $config) = $result;
$toReturn[$feature] = ['treatment' => $treatment, 'config' => $config];
Expand All @@ -197,8 +210,11 @@ public function getTreatmentsWithConfigByFlagSet(
$this->cache->setMany($key, $attributes, $toReturn);
return $toReturn;
} catch (\Exception $exc) {
$this->tracer->trace(TEF::forException($method, $id, $exc));
$this->logger->error($exc);
return array();
} finally {
$this->tracer->trace(TEF::forEnd($method, $id));
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Utils/Tracing/Tracer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Tracer
public const METHOD_GET_TREATMENT_WITH_CONFIG = 12;
public const METHOD_GET_TREATMENTS_WITH_CONFIG = 13;
public const METHOD_TRACK = 14;
public const METHOD_GET_TREATMENTS_BY_FLAG_SET = 15;
public const METHOD_GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET = 16;

public const EVENT_START = 30;
public const EVENT_RPC_START = 31;
Expand Down

0 comments on commit a774876

Please sign in to comment.