summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/sdk/Trace/StatusData.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2023-10-20 17:12:29 +0300
committerAndrew Dolgov <[email protected]>2023-10-20 21:13:39 +0300
commitcdd7ad020e165fe680703b6d3319b908b682fb7a (patch)
treeb51eb09b7b4587e8fbc5624ac8d88d28cfcd0b04 /vendor/open-telemetry/sdk/Trace/StatusData.php
parent45a9ff0c88cbd33892ff16ab837e9059937d656e (diff)
jaeger-client -> opentelemetry
Diffstat (limited to 'vendor/open-telemetry/sdk/Trace/StatusData.php')
-rw-r--r--vendor/open-telemetry/sdk/Trace/StatusData.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/vendor/open-telemetry/sdk/Trace/StatusData.php b/vendor/open-telemetry/sdk/Trace/StatusData.php
new file mode 100644
index 000000000..c28ea22ab
--- /dev/null
+++ b/vendor/open-telemetry/sdk/Trace/StatusData.php
@@ -0,0 +1,84 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OpenTelemetry\SDK\Trace;
+
+use OpenTelemetry\API\Trace as API;
+
+final class StatusData implements StatusDataInterface
+{
+ private static ?self $ok = null;
+ private static ?self $unset = null;
+ private static ?self $error = null;
+ private string $code;
+ private string $description;
+
+ /** @psalm-param API\StatusCode::STATUS_* $code */
+ public function __construct(
+ string $code,
+ string $description
+ ) {
+ $this->code = $code;
+ $this->description = $description;
+ }
+
+ /** @psalm-param API\StatusCode::STATUS_* $code */
+ public static function create(string $code, ?string $description = null): self
+ {
+ if (empty($description)) {
+ switch ($code) {
+ case API\StatusCode::STATUS_UNSET:
+ return self::unset();
+ case API\StatusCode::STATUS_ERROR:
+ return self::error();
+ case API\StatusCode::STATUS_OK:
+ return self::ok();
+ }
+ }
+
+ // Ignore description for non Error statuses.
+ if (API\StatusCode::STATUS_ERROR !== $code) {
+ $description = '';
+ }
+
+ return new self($code, $description); /** @phan-suppress-current-line PhanTypeMismatchArgumentNullable */
+ }
+
+ public static function ok(): self
+ {
+ if (null === self::$ok) {
+ self::$ok = new self(API\StatusCode::STATUS_OK, '');
+ }
+
+ return self::$ok;
+ }
+
+ public static function error(): self
+ {
+ if (null === self::$error) {
+ self::$error = new self(API\StatusCode::STATUS_ERROR, '');
+ }
+
+ return self::$error;
+ }
+
+ public static function unset(): self
+ {
+ if (null === self::$unset) {
+ self::$unset = new self(API\StatusCode::STATUS_UNSET, '');
+ }
+
+ return self::$unset;
+ }
+
+ public function getCode(): string
+ {
+ return $this->code;
+ }
+
+ public function getDescription(): string
+ {
+ return $this->description;
+ }
+}