Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/FlagUpdatesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function connectAndRead(Closure $stop, ?Closure $onEvent = null): void
try {
$response = $this->http->sendRequest(new Request('GET', $url, $headers));
} catch (Throwable $error) {
$this->logger->warning('Failed to connect to Reflag flag updates: {error}: {message}', ['error' => $error::class, 'message' => $error->getMessage()]);
$this->logger->warning('Failed to connect to Reflag flag updates: {error}: {message}', ['error' => $error::class, 'message' => $error->getMessage(), 'exception' => $error]);

return;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ private function read(StreamInterface $body, Closure $stop, ?Closure $onEvent):
}
} catch (Throwable $error) {
// Proxies and load balancers routinely end long-lived streams; like the .NET SDK, this is not a warning.
$this->logger->debug('Reflag flag updates stream failed; reconnecting: {error}: {message}', ['error' => $error::class, 'message' => $error->getMessage()]);
$this->logger->debug('Reflag flag updates stream failed; reconnecting: {error}: {message}', ['error' => $error::class, 'message' => $error->getMessage(), 'exception' => $error]);
} finally {
$body->close();
}
Expand Down Expand Up @@ -242,6 +242,7 @@ private function dispatch(string $event, string $payload, ?Closure $onEvent): vo

if ($version !== null) {
$this->client->refreshFlags($version);
$this->logger->debug('Reflag flags updated to version {version}', ['version' => $version]);
$onEvent?->__invoke('updated', ['flagStateVersion' => $version]);
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/ListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static function (string $event, array $data) use (&$updates): void {
$this->assertSame([2], $updates);
$this->assertSame(2, $client->flagStateVersion());
$this->assertSame([], array_values(array_filter($logger->messages(), static fn (string $m): bool => str_contains($m, 'stream failed'))));
$this->assertContains(['debug', 'Reflag flags updated to version {version}', ['version' => 2]], $logger->records);
}

/** Log levels follow the .NET SDK: only connect failures, bad responses and bad messages warn. */
Expand Down Expand Up @@ -92,6 +93,9 @@ static function (string $event) use (&$disconnects): void {
['warning', 'Failed to connect to Reflag flag updates: {error}: {message}'],
], array_map(static fn (array $r): array => [$r[0], $r[1]], $listener));
$this->assertSame(['status' => 503, 'reason' => 'Service Unavailable'], $listener[5][2]);
// PSR-3: exceptions go in the 'exception' context key so Monolog, Sentry and Flare keep the trace.
$this->assertInstanceOf(\RuntimeException::class, $listener[4][2]['exception']);
$this->assertInstanceOf(\Throwable::class, $listener[6][2]['exception']);
$this->assertStringNotContainsString('not json', json_encode($logger->records), 'payloads are never logged');

// Like the .NET SDK's HandleReconnect: every successful (re)connection refetches flags, so
Expand Down