diff --git a/composer.json b/composer.json index e72035b1..6d28b17b 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "require": { - "php": ">=8.0.0 <9.0", + "php": ">=8.1.0 <9.0", "ext-curl": "*", "psr/log": "^1 || ^2 || ^3", "monolog/monolog": "^2 || ^3" diff --git a/src/Payload/TelemetryEvent.php b/src/Payload/TelemetryEvent.php index 6754473e..a3ce387e 100644 --- a/src/Payload/TelemetryEvent.php +++ b/src/Payload/TelemetryEvent.php @@ -3,7 +3,8 @@ namespace Rollbar\Payload; use Rollbar\SerializerInterface; -use Rollbar\Telemetry\DataType; +use Rollbar\Telemetry\EventLevel; +use Rollbar\Telemetry\EventType; use Rollbar\UtilitiesTrait; /** @@ -25,22 +26,21 @@ class TelemetryEvent implements SerializerInterface * * Some types should be accompanied by specific data in the body. * - * - If $type is {@see DataType::LOG}, the body should contain "message" key. - * - If $type is {@see DataType::NETWORK}, the body should contain "method", "url", and "status_code" keys. - * - If $type is {@see DataType::NAVIGATION}, the body should contain "from" and "to" keys. - * - If $type is {@see DataType::ERROR}, the body should contain "message" key. + * - If $type is {@see EventType::Log}, the body should contain "message" key. + * - If $type is {@see EventType::Network}, the body should contain "method", "url", and "status_code" keys. + * - If $type is {@see EventType::Navigation}, the body should contain "from" and "to" keys. + * - If $type is {@see EventType::Error}, the body should contain "message" key. * - * @param string $type The type of telemetry data. One of: {@see DataType}. - * @param string $level The severity level of the telemetry data. One of: "critical", "error", - * "warning", "info", or "debug". + * @param EventType $type The type of telemetry data. + * @param EventLevel $level The severity level of the telemetry data. * @param array|TelemetryBody $body Additional data for the telemetry event. If an array is provided, it will * be converted to a {@see TelemetryBody} object. * @param float|null $timestamp When this occurred, as a unix timestamp in milliseconds. If not provided, * Rollbar will use the current time. */ public function __construct( - public string $type, - public string $level, + public EventType $type, + public EventLevel $level, array|TelemetryBody $body, public ?float $timestamp = null, ) { @@ -55,8 +55,8 @@ public function serialize(): array $result = array_filter([ 'uuid' => $this->uuid, 'source' => $this->source, - 'level' => $this->level, - 'type' => $this->type, + 'level' => $this->level->value, + 'type' => $this->type->value, 'body' => $this->body->serialize(), 'timestamp_ms' => $this->timestamp, ]); diff --git a/src/Rollbar.php b/src/Rollbar.php index 1c6ffcba..d4211734 100644 --- a/src/Rollbar.php +++ b/src/Rollbar.php @@ -10,6 +10,8 @@ use Rollbar\Handlers\ExceptionHandler; use Rollbar\Payload\TelemetryBody; use Rollbar\Payload\TelemetryEvent; +use Rollbar\Telemetry\EventLevel; +use Rollbar\Telemetry\EventType; use Rollbar\Telemetry\Telemeter; use Stringable; use Throwable; @@ -403,10 +405,8 @@ public static function emergency(string|Stringable $message, array $context = ar /** * Captures a telemetry event that may be sent with future payloads. * - * @param string $type The type of telemetry data. One of: "log", "network", "dom", "navigation", - * "error", or "manual". - * @param string $level The severity level of the telemetry data. One of: "critical", "error", - * "warning", "info", or "debug". + * @param EventType $type The type of telemetry data + * @param EventLevel $level The severity level of the telemetry data. * @param array|TelemetryBody $metadata Additional data about the telemetry event. * @param string|null $uuid The Rollbar UUID to associate with this telemetry event. * @param int|null $timestamp When this occurred, as a unix timestamp in milliseconds. If not provided, @@ -418,8 +418,8 @@ public static function emergency(string|Stringable $message, array $context = ar * @since 4.1.0 */ public static function captureTelemetryEvent( - string $type, - string $level, + EventType $type, + EventLevel $level, array|TelemetryBody $metadata, ?string $uuid = null, ?int $timestamp = null, diff --git a/src/RollbarLogger.php b/src/RollbarLogger.php index 3b101823..1cc505cf 100644 --- a/src/RollbarLogger.php +++ b/src/RollbarLogger.php @@ -7,6 +7,8 @@ use Psr\Log\LoggerInterface; use Rollbar\Payload\TelemetryBody; use Rollbar\Payload\TelemetryEvent; +use Rollbar\Telemetry\EventLevel; +use Rollbar\Telemetry\EventType; use Rollbar\Telemetry\Telemeter; use Stringable; use Throwable; @@ -305,10 +307,8 @@ public function report( /** * Captures a telemetry event that may be sent with future payloads. * - * @param string $type The type of telemetry data. One of: "log", "network", "dom", "navigation", - * "error", or "manual". - * @param string $level The severity level of the telemetry data. One of: "critical", "error", - * "warning", "info", or "debug". + * @param EventType $type The type of telemetry data. + * @param EventLevel $level The severity level of the telemetry data. * @param array|TelemetryBody $metadata Additional data about the telemetry event. * @param string|null $uuid The Rollbar UUID to associate with this telemetry event. * @param int|null $timestamp When this occurred, as a unix timestamp in milliseconds. If not provided, @@ -320,8 +320,8 @@ public function report( * @since 4.1.0 */ public function captureTelemetryEvent( - string $type, - string $level, + EventType $type, + EventLevel $level, array|TelemetryBody $metadata, ?string $uuid = null, ?int $timestamp = null, diff --git a/src/Telemetry/EventLevel.php b/src/Telemetry/EventLevel.php new file mode 100644 index 00000000..2195be58 --- /dev/null +++ b/src/Telemetry/EventLevel.php @@ -0,0 +1,21 @@ += 8.1. - * * @since 4.1.0 */ -class DataType +enum EventType: string { - const LOG = 'log'; + case Log = 'log'; - const NETWORK = 'network'; + case Network = 'network'; /** * This is intended for use with browsers, and is only included here for API completeness. Generally, this should * not be used in a PHP context. */ - const DOM = 'dom'; + case DOM = 'dom'; - const NAVIGATION = 'navigation'; + case Navigation = 'navigation'; - const ERROR = 'error'; + case Error = 'error'; - const MANUAL = 'manual'; + case Manual = 'manual'; } diff --git a/src/Telemetry/Telemeter.php b/src/Telemetry/Telemeter.php index ec1cf675..2869fcea 100644 --- a/src/Telemetry/Telemeter.php +++ b/src/Telemetry/Telemeter.php @@ -53,14 +53,14 @@ public function __construct( * Returns the Rollbar telemetry type that corresponds to the given PSR-3 log level. * * @param string $level The PSR-3 log level. - * @return string + * @return EventType */ - private static function getTypeFromLevel(string $level): string + private static function getTypeFromLevel(string $level): EventType { return match ($level) { - Level::EMERGENCY, Level::ALERT, Level::CRITICAL, Level::ERROR, Level::WARNING => DataType::ERROR, - Level::NOTICE, Level::INFO => DataType::LOG, - default => DataType::MANUAL, + Level::EMERGENCY, Level::ALERT, Level::CRITICAL, Level::ERROR, Level::WARNING => EventType::Error, + Level::NOTICE, Level::INFO => EventType::Log, + default => EventType::Manual, }; } @@ -68,16 +68,16 @@ private static function getTypeFromLevel(string $level): string * Returns the Rollbar telemetry level that corresponds to the given PSR-3 log level. * * @param string $level The PSR-3 log level. - * @return string + * @return EventLevel */ - private static function getLevelFromLevel(string $level): string + private static function getLevelFromPsrLevel(string $level): EventLevel { return match ($level) { - Level::EMERGENCY, Level::ALERT, Level::CRITICAL => 'critical', - Level::ERROR => 'error', - Level::WARNING => 'warning', - Level::DEBUG => 'debug', - default => 'info', + Level::EMERGENCY, Level::ALERT, Level::CRITICAL => EventLevel::Critical, + Level::ERROR => EventLevel::Error, + Level::WARNING => EventLevel::Warning, + Level::DEBUG => EventLevel::Debug, + default => EventLevel::Info, }; } @@ -161,10 +161,8 @@ public function push(TelemetryEvent $event): void /** * Captures a telemetry event and adds it to the queue. * - * @param string $type The type of telemetry data. One of: "log", "network", "dom", "navigation", - * "error", or "manual". - * @param string $level The severity level of the telemetry data. One of: "critical", "error", - * "warning", "info", or "debug". + * @param EventType $type The type of telemetry data. + * @param EventLevel $level The severity level of the telemetry data. * @param array|TelemetryBody $metadata Additional data about the telemetry event. * @param string|null $uuid The Rollbar UUID to associate with this telemetry event. * @param int|null $timestamp When this occurred, as a unix timestamp in milliseconds. If not provided, @@ -173,8 +171,8 @@ public function push(TelemetryEvent $event): void * @return TelemetryEvent|null */ public function capture( - string $type, - string $level, + EventType $type, + EventLevel $level, array|TelemetryBody $metadata, ?string $uuid = null, ?int $timestamp = null, @@ -200,9 +198,7 @@ public function capture( * as the message. If an array is given, it will be used as * the metadata body. If an ErrorWrapper is given, it will be * parsed for the message and stack trace. - * @param string $level The severity level of the telemetry data. One of: - * "critical", "error", "warning", "info", or "debug". - * Defaults to "error". + * @param EventLevel $level The severity level of the telemetry data. * @param string|null $uuid The Rollbar UUID to associate with this telemetry event. * @param int|null $timestamp When this occurred, as a unix timestamp in milliseconds. If * not provided, the current time will be used. @@ -212,12 +208,12 @@ public function capture( */ public function captureError( array|string|ErrorWrapper|Throwable $error, - string $level = 'error', + EventLevel $level = EventLevel::Error, ?string $uuid = null, ?int $timestamp = null, ): ?TelemetryEvent { if (is_string($error)) { - return $this->capture('error', $level, new TelemetryBody(message: $error), $uuid, $timestamp); + return $this->capture(EventType::Error, $level, new TelemetryBody(message: $error), $uuid, $timestamp); } if ($error instanceof ErrorWrapper) { $metadata = new TelemetryBody( @@ -225,7 +221,7 @@ public function captureError( subtype: 'error', stack: $this->stringifyBacktrace($error->getBacktrace()), ); - return $this->capture('error', $level, $metadata, $uuid, $timestamp); + return $this->capture(EventType::Error, $level, $metadata, $uuid, $timestamp); } if ($error instanceof Throwable) { $metadata = new TelemetryBody( @@ -233,17 +229,16 @@ public function captureError( subtype: 'exception', stack: $this->stringifyBacktrace($error->getTrace()) ); - return $this->capture('error', $level, $metadata, $uuid, $timestamp); + return $this->capture(EventType::Error, $level, $metadata, $uuid, $timestamp); } - return $this->capture('error', $level, $error, $uuid, $timestamp); + return $this->capture(EventType::Error, $level, $error, $uuid, $timestamp); } /** * Captures a log message as a telemetry event and adds it to the queue. * * @param string $message The log message to capture. - * @param string $level The severity level of the telemetry data. One of: "critical", "error", "warning", - * "info", or "debug". Defaults to "info". + * @param EventLevel $level The severity level of the telemetry data. * @param string|null $uuid The Rollbar UUID to associate with this telemetry event. * @param int|null $timestamp When this occurred, as a unix timestamp in milliseconds. If not provided, the * current time will be used. @@ -252,11 +247,11 @@ public function captureError( */ public function captureLog( string $message, - string $level = 'info', + EventLevel $level = EventLevel::Info, ?string $uuid = null, ?int $timestamp = null, ): ?TelemetryEvent { - return $this->capture('log', $level, new TelemetryBody(message: $message), $uuid, $timestamp); + return $this->capture(EventType::Log, $level, new TelemetryBody(message: $message), $uuid, $timestamp); } /** @@ -265,8 +260,7 @@ public function captureLog( * @param string $method The HTTP method. E.g. GET, POST, etc. * @param string $url The URL of the request. * @param string $status_code The HTTP status code. - * @param string $level The severity level of the telemetry data. One of: "critical", "error", "warning", - * "info", or "debug". Defaults to "info". + * @param EventLevel $level The severity level of the telemetry data. * @param string|null $uuid The Rollbar UUID to associate with this telemetry event. * @param int|null $timestamp When this occurred, as a unix timestamp in milliseconds. If not provided, the * current time will be used. @@ -277,12 +271,12 @@ public function captureNetwork( string $method, string $url, string $status_code, - string $level = 'info', + EventLevel $level = EventLevel::Info, ?string $uuid = null, ?int $timestamp = null, ): ?TelemetryEvent { return $this->capture( - type: 'log', + type: EventType::Log, level: $level, metadata: new TelemetryBody( method: $method, @@ -299,8 +293,7 @@ public function captureNetwork( * * @param string $from The URL of the previous page. * @param string $to The URL of the next page. - * @param string $level The severity level of the telemetry data. One of: "critical", "error", "warning", - * "info", or "debug". Defaults to "info". + * @param EventLevel $level The severity level of the telemetry data. * @param string|null $uuid The Rollbar UUID to associate with this telemetry event. * @param int|null $timestamp When this occurred, as a unix timestamp in milliseconds. If not provided, the * current time will be used. @@ -310,11 +303,11 @@ public function captureNetwork( public function captureNavigation( string $from, string $to, - string $level = 'info', + EventLevel $level = EventLevel::Info, ?string $uuid = null, ?int $timestamp = null, ): ?TelemetryEvent { - return $this->capture('log', $level, new TelemetryBody(from: $from, to: $to), $uuid, $timestamp); + return $this->capture(EventType::Log, $level, new TelemetryBody(from: $from, to: $to), $uuid, $timestamp); } /** @@ -348,7 +341,7 @@ public function captureRollbarItem( } // Make sure to respect the PSR exception context. See https://www.php-fig.org/psr/psr-3/#13-context. if (($context['exception'] ?? null) instanceof Throwable) { - $event = $this->captureError($context['exception'], self::getLevelFromLevel($level), $uuid); + $event = $this->captureError($context['exception'], self::getLevelFromPsrLevel($level), $uuid); if (null === $event) { return null; } @@ -361,12 +354,12 @@ public function captureRollbarItem( } // If the rollbar item is an exception, we should capture it as an error event. if ($message instanceof Throwable) { - return $this->captureError($message, self::getLevelFromLevel($level), $uuid); + return $this->captureError($message, self::getLevelFromPsrLevel($level), $uuid); } // Otherwise, we will capture it based on the level. return $this->capture( type: self::getTypeFromLevel($level), - level: self::getLevelFromLevel($level), + level: self::getLevelFromPsrLevel($level), metadata: new TelemetryBody(message: $this->getRollbarItemMessage($message)), uuid: $uuid, ); diff --git a/tests/Payload/TelemetryEventTest.php b/tests/Payload/TelemetryEventTest.php index 4f94e1d6..ddf3d103 100644 --- a/tests/Payload/TelemetryEventTest.php +++ b/tests/Payload/TelemetryEventTest.php @@ -4,7 +4,8 @@ use Rollbar\BaseRollbarTest; use Rollbar\Payload\TelemetryEvent; -use Rollbar\Telemetry\DataType; +use Rollbar\Telemetry\EventLevel; +use Rollbar\Telemetry\EventType; class TelemetryEventTest extends BaseRollbarTest { @@ -12,7 +13,7 @@ public function testConstruct(): void { // Make sure the timestamp is automatically created if it is null. $before = floor(microtime(true) * 1000); - $event = new TelemetryEvent(DataType::LOG, 'info', ['message' => 'foo']); + $event = new TelemetryEvent(EventType::Log, EventLevel::Info, ['message' => 'foo']); $after = floor(microtime(true) * 1000); self::assertNotNull($event->timestamp); diff --git a/tests/RollbarLoggerTest.php b/tests/RollbarLoggerTest.php index 818d89cc..4cbc48a9 100644 --- a/tests/RollbarLoggerTest.php +++ b/tests/RollbarLoggerTest.php @@ -4,6 +4,8 @@ use Monolog\Handler\NoopHandler; use Rollbar\Payload\Level; use Rollbar\Payload\Payload; +use Rollbar\Telemetry\EventLevel; +use Rollbar\Telemetry\EventType; use Rollbar\TestHelpers\ArrayLogger; use Rollbar\TestHelpers\Exceptions\SilentExceptionSampleRate; use StdClass; @@ -204,8 +206,8 @@ public function testReportTelemetry(): void Rollbar::logger()->report(Level::WARNING, "Testing PHP Notifier", isUncaught: true); $events = Rollbar::getTelemeter()->copyEvents(); $this->assertCount(1, $events); - $this->assertSame($events[0]->type, 'error'); - $this->assertSame($events[0]->level, 'warning'); + $this->assertSame($events[0]->type, EventType::Error); + $this->assertSame($events[0]->level, EventLevel::Warning); $this->assertSame($events[0]->body->message, 'Testing PHP Notifier'); } diff --git a/tests/RollbarTest.php b/tests/RollbarTest.php index 642a022e..0a59be4c 100644 --- a/tests/RollbarTest.php +++ b/tests/RollbarTest.php @@ -3,7 +3,8 @@ use Rollbar\Payload\Payload; use Rollbar\Payload\Level; use Rollbar\Payload\TelemetryEvent; -use Rollbar\Telemetry\DataType; +use Rollbar\Telemetry\EventLevel; +use Rollbar\Telemetry\EventType; use Rollbar\Telemetry\Telemeter; use Rollbar\TestHelpers\ArrayLogger; @@ -173,15 +174,15 @@ public function testCaptureTelemetryEvent(): void Rollbar::init(self::$simpleConfig); $event = Rollbar::captureTelemetryEvent( - type: DataType::LOG, - level: 'info', + type: EventType::Log, + level: EventLevel::Info, metadata: ['message' => 'test message'], ); self::assertInstanceOf(TelemetryEvent::class, $event); - self::assertEquals(DataType::LOG, $event->type); + self::assertEquals(EventType::Log, $event->type); self::assertEquals('test message', $event->body->message); - self::assertEquals('info', $event->level); + self::assertEquals(EventLevel::Info, $event->level); } protected function shortcutMethodTestHelper($level): void diff --git a/tests/Telemetry/TelemeterTest.php b/tests/Telemetry/TelemeterTest.php index 71015cd5..784c51ad 100644 --- a/tests/Telemetry/TelemeterTest.php +++ b/tests/Telemetry/TelemeterTest.php @@ -45,10 +45,10 @@ public function testPush(): void self::assertSame(100, $telemeter->getMaxQueueSize()); self::assertSame(0, $telemeter->getQueueSize()); - $telemeter->push(new TelemetryEvent(DataType::LOG, 'info', ['message' => 'foo'])); + $telemeter->push(new TelemetryEvent(EventType::Log, EventLevel::Info, ['message' => 'foo'])); self::assertSame(1, $telemeter->getQueueSize()); - $telemeter->push(new TelemetryEvent(DataType::LOG, 'info', new TelemetryBody('bar'))); + $telemeter->push(new TelemetryEvent(EventType::Log, EventLevel::Info, new TelemetryBody('bar'))); self::assertSame(2, $telemeter->getQueueSize()); } @@ -56,8 +56,8 @@ public function testCopyEvents(): void { $telemeter = new Telemeter(); - $event1 = new TelemetryEvent(DataType::LOG, 'info', ['message' => 'foo']); - $event2 = new TelemetryEvent(DataType::LOG, 'info', new TelemetryBody('bar')); + $event1 = new TelemetryEvent(EventType::Log, EventLevel::Info, ['message' => 'foo']); + $event2 = new TelemetryEvent(EventType::Log, EventLevel::Info, new TelemetryBody('bar')); $telemeter->push($event1); $telemeter->push($event2); @@ -77,8 +77,8 @@ public function testCopyEventsFilter(): void $telemeter = new Telemeter(filter: $filter); - $event1 = new TelemetryEvent(DataType::LOG, 'info', ['message' => 'foo']); - $event2 = new TelemetryEvent(DataType::LOG, 'info', new TelemetryBody('bar')); + $event1 = new TelemetryEvent(EventType::Log, EventLevel::Info, ['message' => 'foo']); + $event2 = new TelemetryEvent(EventType::Log, EventLevel::Info, new TelemetryBody('bar')); $telemeter->push($event1); $telemeter->push($event2); @@ -91,13 +91,13 @@ public function testCopyEventsFilter(): void public function testCapture(): void { $telemeter = new Telemeter(); - $telemeter->capture(DataType::LOG, 'info', ['message' => 'foo']); + $telemeter->capture(EventType::Log, EventLevel::Info, ['message' => 'foo']); $events = $telemeter->copyEvents(); self::assertSame(1, count($events)); self::assertSame('foo', $events[0]->body->message); - self::assertSame('info', $events[0]->level); - self::assertSame(DataType::LOG, $events[0]->type); + self::assertSame(EventLevel::Info, $events[0]->level); + self::assertSame(EventType::Log, $events[0]->type); self::assertNotNull($events[0]->timestamp); } @@ -109,8 +109,8 @@ public function testCaptureFilter(): void }); $telemeter = new Telemeter(filter: $filter); - $telemeter->capture(DataType::LOG, 'info', ['message' => 'foo']); - $telemeter->capture(DataType::LOG, 'info', ['message' => 'bar']); + $telemeter->capture(EventType::Log, EventLevel::Info, ['message' => 'foo']); + $telemeter->capture(EventType::Log, EventLevel::Info, ['message' => 'bar']); // Because the filter is also applied on the copyEvents() call, we want to make sure that the 'foo' event is // filtered out, but the 'bar' event is not. @@ -125,39 +125,39 @@ public function testCaptureError(): void { $telemeter = new Telemeter(); $telemeter->captureError('foo'); - $telemeter->captureError(['message' => 'bar'], 'warning'); - $telemeter->captureError(['message' => 'baz'], 'critical'); + $telemeter->captureError(['message' => 'bar'], EventLevel::Warning); + $telemeter->captureError(['message' => 'baz'], EventLevel::Critical); $events = $telemeter->copyEvents(); self::assertSame(3, count($events)); self::assertSame('foo', $events[0]->body->message); - self::assertSame('error', $events[0]->type); - self::assertSame('error', $events[0]->level); + self::assertSame(EventType::Error, $events[0]->type); + self::assertSame(EventLevel::Error, $events[0]->level); self::assertSame('bar', $events[1]->body->message); - self::assertSame('error', $events[1]->type); - self::assertSame('warning', $events[1]->level); + self::assertSame(EventType::Error, $events[1]->type); + self::assertSame(EventLevel::Warning, $events[1]->level); self::assertSame('baz', $events[2]->body->message); - self::assertSame('error', $events[2]->type); - self::assertSame('critical', $events[2]->level); + self::assertSame(EventType::Error, $events[2]->type); + self::assertSame(EventLevel::Critical, $events[2]->level); } public function testCaptureLog(): void { $telemeter = new Telemeter(); $telemeter->captureLog('foo'); - $telemeter->captureLog('bar', 'debug'); + $telemeter->captureLog('bar', EventLevel::Debug); $events = $telemeter->copyEvents(); self::assertSame(2, count($events)); self::assertSame('foo', $events[0]->body->message); - self::assertSame('log', $events[0]->type); - self::assertSame('info', $events[0]->level); + self::assertSame(EventType::Log, $events[0]->type); + self::assertSame(EventLevel::Info, $events[0]->level); self::assertSame('bar', $events[1]->body->message); - self::assertSame('log', $events[1]->type); - self::assertSame('debug', $events[1]->level); + self::assertSame(EventType::Log, $events[1]->type); + self::assertSame(EventLevel::Debug, $events[1]->level); } public function testCaptureNetwork(): void @@ -201,36 +201,36 @@ public function testCaptureRollbarItem(): void $telemeter = new Telemeter(); $error = new Exception('oops'); $event = $telemeter->captureRollbarItem(Level::DEBUG, 'baz', context: ['exception' => $error]); - self::assertSame(DataType::ERROR, $event->type); + self::assertSame(EventType::Error, $event->type); self::assertSame('oops', $event->body->extra['error_message']); self::assertSame('baz', $event->body->message); // Test a Throwable $message is treated as an error $event = $telemeter->captureRollbarItem(Level::DEBUG, $error); - self::assertSame(DataType::ERROR, $event->type); + self::assertSame(EventType::Error, $event->type); self::assertSame('oops', $event->body->message); // Test telemetry type dynamically determined from the Rollbar level. - self::assertSame(DataType::ERROR, $telemeter->captureRollbarItem(Level::EMERGENCY, 'foo')->type); - self::assertSame(DataType::ERROR, $telemeter->captureRollbarItem(Level::ALERT, 'foo')->type); - self::assertSame(DataType::ERROR, $telemeter->captureRollbarItem(Level::CRITICAL, 'foo')->type); - self::assertSame(DataType::ERROR, $telemeter->captureRollbarItem(Level::ERROR, 'foo')->type); - self::assertSame(DataType::ERROR, $telemeter->captureRollbarItem(Level::WARNING, 'foo')->type); - self::assertSame(DataType::LOG, $telemeter->captureRollbarItem(Level::NOTICE, 'foo')->type); - self::assertSame(DataType::LOG, $telemeter->captureRollbarItem(Level::INFO, 'foo')->type); - self::assertSame(DataType::MANUAL, $telemeter->captureRollbarItem(Level::DEBUG, 'foo')->type); - self::assertSame(DataType::MANUAL, $telemeter->captureRollbarItem('bar', 'foo')->type); + self::assertSame(EventType::Error, $telemeter->captureRollbarItem(Level::EMERGENCY, 'foo')->type); + self::assertSame(EventType::Error, $telemeter->captureRollbarItem(Level::ALERT, 'foo')->type); + self::assertSame(EventType::Error, $telemeter->captureRollbarItem(Level::CRITICAL, 'foo')->type); + self::assertSame(EventType::Error, $telemeter->captureRollbarItem(Level::ERROR, 'foo')->type); + self::assertSame(EventType::Error, $telemeter->captureRollbarItem(Level::WARNING, 'foo')->type); + self::assertSame(EventType::Log, $telemeter->captureRollbarItem(Level::NOTICE, 'foo')->type); + self::assertSame(EventType::Log, $telemeter->captureRollbarItem(Level::INFO, 'foo')->type); + self::assertSame(EventType::Manual, $telemeter->captureRollbarItem(Level::DEBUG, 'foo')->type); + self::assertSame(EventType::Manual, $telemeter->captureRollbarItem('bar', 'foo')->type); // Test telemetry level dynamically determined from the Rollbar level. - self::assertSame('critical', $telemeter->captureRollbarItem(Level::EMERGENCY, 'foo')->level); - self::assertSame('critical', $telemeter->captureRollbarItem(Level::ALERT, 'foo')->level); - self::assertSame('critical', $telemeter->captureRollbarItem(Level::CRITICAL, 'foo')->level); - self::assertSame('error', $telemeter->captureRollbarItem(Level::ERROR, 'foo')->level); - self::assertSame('warning', $telemeter->captureRollbarItem(Level::WARNING, 'foo')->level); - self::assertSame('info', $telemeter->captureRollbarItem(Level::NOTICE, 'foo')->level); - self::assertSame('info', $telemeter->captureRollbarItem(Level::INFO, 'foo')->level); - self::assertSame('debug', $telemeter->captureRollbarItem(Level::DEBUG, 'foo')->level); - self::assertSame('info', $telemeter->captureRollbarItem('bar', 'foo')->level); + self::assertSame(EventLevel::Critical, $telemeter->captureRollbarItem(Level::EMERGENCY, 'foo')->level); + self::assertSame(EventLevel::Critical, $telemeter->captureRollbarItem(Level::ALERT, 'foo')->level); + self::assertSame(EventLevel::Critical, $telemeter->captureRollbarItem(Level::CRITICAL, 'foo')->level); + self::assertSame(EventLevel::Error, $telemeter->captureRollbarItem(Level::ERROR, 'foo')->level); + self::assertSame(EventLevel::Warning, $telemeter->captureRollbarItem(Level::WARNING, 'foo')->level); + self::assertSame(EventLevel::Info, $telemeter->captureRollbarItem(Level::NOTICE, 'foo')->level); + self::assertSame(EventLevel::Info, $telemeter->captureRollbarItem(Level::INFO, 'foo')->level); + self::assertSame(EventLevel::Debug, $telemeter->captureRollbarItem(Level::DEBUG, 'foo')->level); + self::assertSame(EventLevel::Info, $telemeter->captureRollbarItem('bar', 'foo')->level); } public function testGetMaxQueueSize(): void @@ -354,8 +354,8 @@ public function testSetFilterWithFilterableEvents(): void }); $telemeter = new Telemeter(); - $event1 = new TelemetryEvent(DataType::LOG, 'info', ['message' => 'foo']); - $event2 = new TelemetryEvent(DataType::LOG, 'info', new TelemetryBody('bar')); + $event1 = new TelemetryEvent(EventType::Log, EventLevel::Info, ['message' => 'foo']); + $event2 = new TelemetryEvent(EventType::Log, EventLevel::Info, new TelemetryBody('bar')); $telemeter->push($event1); $telemeter->push($event2);