Skip to content

Commit

Permalink
tracer cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mredolatti committed Dec 13, 2023
1 parent afb6991 commit b55f354
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1.3.1 (TBD):
- Support finer granularity timeouts and milliseconds granularity
1.4.0 (TBD):
- Add support for a custom tracer for client methods.
- Support finer granularity timeouts and milliseconds granularity.

1.3.0 (Nov 10, 2023):
- Added in-memory evaluation cache for the duration of a request.
Expand Down
14 changes: 7 additions & 7 deletions examples/tracer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
require_once '../vendor/autoload.php';

use \SplitIO\ThinSdk\Factory;
use \SplitIO\ThinSdk\Utils\Tracer;
use \SplitIO\ThinSdk\Utils\TracerHook;
use \SplitIO\ThinSdk\Utils\Tracing\Tracer;
use \SplitIO\ThinSdk\Utils\Tracing\TracerHook;

class CustomTracer implements TracerHook
{

private $events = [];

public function on(int $method, int $event, ?array $arguments)
public function on(array $event)
{
// assume we only care about getTreatment() calls...
if ($method != Tracer::METHOD_GET_TREATMENT) {
if ($event['method'] != Tracer::METHOD_GET_TREATMENT) {
return;
}

switch ($event) {
switch ($event['event']) {
case Tracer::EVENT_START:
array_push($this->events, "start (" . json_encode($arguments) . ") -- " . microtime(true));
array_push($this->events, "start (" . json_encode($event['arguments']) . ") -- " . microtime(true));
break;
case Tracer::EVENT_RPC_START:
array_push($this->events, "about to send rpc -- " . microtime(true));
Expand Down Expand Up @@ -54,7 +54,7 @@ public function getEvents(): array
'level' => \Psr\Log\LogLevel::INFO,
],
'utils' => [
'__tracer' => [
'tracer' => [
'hook' => $ct,
'forwardArgs' => true,
]
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function fromArray(array $config): Utils
return new Utils(
$config['impressionListener'] ?? $d->impressionListener(),
EvaluationCache::fromArray($config['evaluationCache'] ?? []),
Tracer::fromArray($config['__tracer'] ?? []),
Tracer::fromArray($config['tracer'] ?? []),
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Config/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testConfigParsing()
'maxSize' => 1234,
'customHash' => $ihMock,
],
'__tracer' => [
'tracer' => [
'hook' => $tMock,
'forwardArgs' => true,
],
Expand Down

0 comments on commit b55f354

Please sign in to comment.