diff options
Diffstat (limited to 'vendor/opentracing/opentracing/src/OpenTracing')
24 files changed, 1774 insertions, 0 deletions
diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Formats.php b/vendor/opentracing/opentracing/src/OpenTracing/Formats.php new file mode 100644 index 000000000..f26c5ecf1 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Formats.php @@ -0,0 +1,49 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Formats; + +/** + * Used a (single) arbitrary binary blob representing a SpanContext + * + * For both Tracer::inject() and Tracer::extract() the carrier must be a `string`. + */ +const BINARY = 'binary'; + +/** + * Used for an arbitrary string-to-string map with an unrestricted character set for both keys and values + * + * Unlike `HTTP_HEADERS`, the `TEXT_MAP` format does not restrict the key or + * value character sets in any way. + * + * For both Tracer::inject() and Tracer::extract() the carrier must be a `array|ArrayObject`. + */ +const TEXT_MAP = 'text_map'; + +/** + * Used for a string-to-string map with keys and values that are suitable for use in HTTP headers (a la RFC 7230. + * In practice, since there is such "diversity" in the way that HTTP headers are treated in the wild, it is strongly + * recommended that Tracer implementations use a limited HTTP header key space and escape values conservatively. + * + * Unlike `TEXT_MAP`, the `HTTP_HEADERS` format requires that the keys and values be valid as HTTP headers as-is + * (i.e., character casing may be unstable and special characters are disallowed in keys, values should be + * URL-escaped, etc). + * + * For both Tracer::inject() and Tracer::extract() the carrier must be a `array|ArrayObject`. + * + * For example, Tracer::inject(): + * + * $headers = [] + * $tracer->inject($span->getContext(), Formats\HTTP_HEADERS, $headers) + * $request = new GuzzleHttp\Psr7\Request($uri, $body, $headers); + * + * Or Tracer::extract(): + * + * $headers = $request->getHeaders() + * $clientContext = $tracer->extract(Formats\HTTP_HEADERS, $headers) + * + * @see http://www.php-fig.org/psr/psr-7/#12-http-headers + * @see http://php.net/manual/en/function.getallheaders.php + */ +const HTTP_HEADERS = 'http_headers'; diff --git a/vendor/opentracing/opentracing/src/OpenTracing/GlobalTracer.php b/vendor/opentracing/opentracing/src/OpenTracing/GlobalTracer.php new file mode 100644 index 000000000..aafdba121 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/GlobalTracer.php @@ -0,0 +1,60 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +final class GlobalTracer +{ + /** + * @var Tracer + */ + private static $instance; + + /** + * @var bool + */ + private static $isRegistered = false; + + /** + * GlobalTracer::set sets the [singleton] Tracer returned by get(). + * Those who use GlobalTracer (rather than directly manage a Tracer instance) + * should call GlobalTracer::set as early as possible in bootstrap, prior to + * start a new span. Prior to calling GlobalTracer::set, any Spans started + * via the `Tracer::startActiveSpan` (etc) globals are noops. + * + * @param Tracer $tracer + * @return void + */ + public static function set(Tracer $tracer): void + { + self::$instance = $tracer; + self::$isRegistered = true; + } + + /** + * GlobalTracer::get returns the global singleton `Tracer` implementation. + * Before `GlobalTracer::set` is called, the `GlobalTracer::get` is a noop + * implementation that drops all data handed to it. + * + * @return Tracer + */ + public static function get(): Tracer + { + if (self::$instance === null) { + self::$instance = new NoopTracer(); + } + + return self::$instance; + } + + /** + * Returns true if a global tracer has been registered, otherwise returns false. + * + * @return bool + */ + public static function isRegistered(): bool + { + return self::$isRegistered; + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/InvalidReferenceArgumentException.php b/vendor/opentracing/opentracing/src/OpenTracing/InvalidReferenceArgumentException.php new file mode 100644 index 000000000..128360393 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/InvalidReferenceArgumentException.php @@ -0,0 +1,33 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use InvalidArgumentException; + +/** + * Thrown when passing an invalid argument for a reference + */ +final class InvalidReferenceArgumentException extends InvalidArgumentException +{ + /** + * @return InvalidReferenceArgumentException + */ + public static function forEmptyType(): InvalidReferenceArgumentException + { + return new self('Reference type can not be an empty string'); + } + + /** + * @param mixed $context + * @return InvalidReferenceArgumentException + */ + public static function forInvalidContext($context): InvalidReferenceArgumentException + { + return new self(sprintf( + 'Reference expects \OpenTracing\Span or \OpenTracing\SpanContext as context, got %s', + is_object($context) ? get_class($context) : gettype($context) + )); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/InvalidReferencesSetException.php b/vendor/opentracing/opentracing/src/OpenTracing/InvalidReferencesSetException.php new file mode 100644 index 000000000..de7d907c8 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/InvalidReferencesSetException.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use DomainException; + +/** + * Thrown when a reference has more than one parent in the SpanOptions + */ +final class InvalidReferencesSetException extends DomainException +{ + /** + * @param string $message + * @return InvalidReferencesSetException + */ + public static function create(string $message): InvalidReferencesSetException + { + return new self($message); + } + + /** + * @return InvalidReferencesSetException + */ + public static function forMoreThanOneParent(): InvalidReferencesSetException + { + return new self('Span can not have more than one parent, either one as child_of or either one as follows_from'); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/InvalidSpanOptionException.php b/vendor/opentracing/opentracing/src/OpenTracing/InvalidSpanOptionException.php new file mode 100644 index 000000000..f9b8003ff --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/InvalidSpanOptionException.php @@ -0,0 +1,131 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use InvalidArgumentException; + +/** + * Thrown when passing an invalid option on Span creation + */ +final class InvalidSpanOptionException extends InvalidArgumentException +{ + /** + * @return InvalidSpanOptionException + */ + public static function forIncludingBothChildOfAndReferences(): InvalidSpanOptionException + { + return new self('Either "childOf" or "references" options are accepted but not both.'); + } + + /** + * @param mixed $reference + * @return InvalidSpanOptionException + */ + public static function forInvalidReference($reference): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid reference. Expected OpenTracing\Reference, got %s.', + is_object($reference) ? get_class($reference) : gettype($reference) + )); + } + + /** + * @return InvalidSpanOptionException + */ + public static function forInvalidStartTime(): InvalidSpanOptionException + { + return new self('Invalid start_time option. Expected int or float got string.'); + } + + /** + * @param mixed $childOfOption + * @return InvalidSpanOptionException + */ + public static function forInvalidChildOf($childOfOption): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid child_of option. Expected Span or SpanContext, got %s', + is_object($childOfOption) ? get_class($childOfOption) : gettype($childOfOption) + )); + } + + /** + * @param string $key + * @return InvalidSpanOptionException + */ + public static function forUnknownOption(string $key): InvalidSpanOptionException + { + return new self(sprintf('Invalid option %s.', $key)); + } + + /** + * @param mixed $tag + * @return InvalidSpanOptionException + */ + public static function forInvalidTag($tag): InvalidSpanOptionException + { + return new self(sprintf('Invalid tag. Expected string, got %s', gettype($tag))); + } + + /** + * @param mixed $tagValue + * @return InvalidSpanOptionException + */ + public static function forInvalidTagValue($tagValue): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid tag value. Expected scalar or object with __toString method, got %s', + is_object($tagValue) ? get_class($tagValue) : gettype($tagValue) + )); + } + + /** + * @param mixed $value + * @return InvalidSpanOptionException + */ + public static function forInvalidTags($value): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid tags value. Expected a associative array of tags, got %s', + is_object($value) ? get_class($value) : gettype($value) + )); + } + + /** + * @param mixed $value + * @return InvalidSpanOptionException + */ + public static function forInvalidReferenceSet($value): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid references set. Expected Reference or Reference[], got %s', + is_object($value) ? get_class($value) : gettype($value) + )); + } + + /** + * @param mixed $value + * @return InvalidSpanOptionException + */ + public static function forFinishSpanOnClose($value): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid type for finish_span_on_close. Expected bool, got %s', + is_object($value) ? get_class($value) : gettype($value) + )); + } + + /** + * @param mixed $value + * @return InvalidSpanOptionException + */ + public static function forIgnoreActiveSpan($value): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid type for ignore_active_span. Expected bool, got %s', + is_object($value) ? get_class($value) : gettype($value) + )); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockScope.php b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockScope.php new file mode 100644 index 000000000..a814b45b5 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockScope.php @@ -0,0 +1,62 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Mock; + +use OpenTracing\Scope; +use OpenTracing\Span; + +final class MockScope implements Scope +{ + /** + * @var Span + */ + private $span; + + /** + * @var MockScopeManager + */ + private $scopeManager; + + /** + * @var bool + */ + private $finishSpanOnClose; + + /** + * @param MockScopeManager $scopeManager + * @param Span $span + * @param bool $finishSpanOnClose + */ + public function __construct( + MockScopeManager $scopeManager, + Span $span, + bool $finishSpanOnClose + ) { + $this->scopeManager = $scopeManager; + $this->span = $span; + $this->finishSpanOnClose = $finishSpanOnClose; + } + + /** + * {@inheritdoc} + */ + public function close(): void + { + if ($this->finishSpanOnClose) { + $this->span->finish(); + } + + $this->scopeManager->deactivate($this); + } + + /** + * {@inheritdoc} + * @return Span|MockSpan + */ + public function getSpan(): Span + { + return $this->span; + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockScopeManager.php b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockScopeManager.php new file mode 100644 index 000000000..c75c71942 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockScopeManager.php @@ -0,0 +1,49 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Mock; + +use OpenTracing\Scope; +use OpenTracing\ScopeManager; +use OpenTracing\Span; + +final class MockScopeManager implements ScopeManager +{ + /** + * @var Scope[] + */ + private $scopes = []; + + /** + * {@inheritdoc} + */ + public function activate(Span $span, bool $finishSpanOnClose = ScopeManager::DEFAULT_FINISH_SPAN_ON_CLOSE): Scope + { + $scope = new MockScope($this, $span, $finishSpanOnClose); + $this->scopes[] = $scope; + + return $scope; + } + + /** + * {@inheritdoc} + */ + public function getActive(): ?Scope + { + if (empty($this->scopes)) { + return null; + } + + return $this->scopes[count($this->scopes) - 1]; + } + + public function deactivate(MockScope $scope): void + { + foreach ($this->scopes as $scopeIndex => $scopeItem) { + if ($scope === $scopeItem) { + unset($this->scopes[$scopeIndex]); + } + } + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockSpan.php b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockSpan.php new file mode 100644 index 000000000..db53649bf --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockSpan.php @@ -0,0 +1,145 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Mock; + +use OpenTracing\Span; +use OpenTracing\SpanContext; + +final class MockSpan implements Span +{ + /** + * @var string + */ + private $operationName; + + /** + * @var SpanContext + */ + private $context; + + /** + * @var array + */ + private $tags = []; + + /** + * @var array + */ + private $logs = []; + + /** + * @var int + */ + private $startTime; + + /** + * @var int|null + */ + private $duration; + + public function __construct( + string $operationName, + SpanContext $context, + ?int $startTime = null + ) { + $this->operationName = $operationName; + $this->context = $context; + $this->startTime = $startTime ?: time(); + } + + /** + * {@inheritdoc} + */ + public function getOperationName(): string + { + return $this->operationName; + } + + /** + * {@inheritdoc} + * @return SpanContext|MockSpanContext + */ + public function getContext(): SpanContext + { + return $this->context; + } + + public function getStartTime(): ?int + { + return $this->startTime; + } + + /** + * {@inheritdoc} + */ + public function finish($finishTime = null): void + { + $finishTime = ($finishTime ?: time()); + $this->duration = $finishTime - $this->startTime; + } + + public function isFinished(): bool + { + return $this->duration !== null; + } + + public function getDuration(): ?int + { + return $this->duration; + } + + /** + * {@inheritdoc} + */ + public function overwriteOperationName(string $newOperationName): void + { + $this->operationName = (string)$newOperationName; + } + + /** + * {@inheritdoc} + */ + public function setTag(string $key, $value): void + { + $this->tags[$key] = $value; + } + + public function getTags(): array + { + return $this->tags; + } + + /** + * {@inheritdoc} + */ + public function log(array $fields = [], $timestamp = null): void + { + $this->logs[] = [ + 'timestamp' => $timestamp ?: time(), + 'fields' => $fields, + ]; + } + + public function getLogs(): array + { + return $this->logs; + } + + /** + * {@inheritdoc} + */ + public function addBaggageItem(string $key, string $value): void + { + $this->context = $this->context->withBaggageItem($key, $value); + } + + /** + * {@inheritdoc} + */ + public function getBaggageItem(string $key): ?string + { + return $this->context->getBaggageItem($key); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockSpanContext.php b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockSpanContext.php new file mode 100644 index 000000000..d094ea0e0 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockSpanContext.php @@ -0,0 +1,100 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Mock; + +use OpenTracing\SpanContext; +use ArrayIterator; + +final class MockSpanContext implements SpanContext +{ + /** + * @var int + */ + private $traceId; + + /** + * @var int + */ + private $spanId; + + /** + * @var bool + */ + private $isSampled; + + /** + * @var array + */ + private $items; + + private function __construct(int $traceId, int $spanId, bool $isSampled, array $items) + { + $this->traceId = $traceId; + $this->spanId = $spanId; + $this->isSampled = $isSampled; + $this->items = $items; + } + + public static function create(int $traceId, int $spanId, bool $sampled = true, array $items = []): SpanContext + { + return new self($traceId, $spanId, $sampled, $items); + } + + public static function createAsRoot(bool $sampled = true, array $items = []): SpanContext + { + $traceId = $spanId = self::nextId(); + return new self($traceId, $spanId, $sampled, $items); + } + + public static function createAsChildOf(MockSpanContext $spanContext): SpanContext + { + $spanId = self::nextId(); + return new self($spanContext->traceId, $spanId, $spanContext->isSampled, $spanContext->items); + } + + public function getTraceId(): int + { + return $this->traceId; + } + + public function getSpanId(): int + { + return $this->spanId; + } + + public function isSampled(): bool + { + return $this->isSampled; + } + + /** + * {@inheritdoc} + */ + public function getIterator(): ArrayIterator + { + return new ArrayIterator($this->items); + } + + /** + * {@inheritdoc} + */ + public function getBaggageItem(string $key): ?string + { + return array_key_exists($key, $this->items) ? $this->items[$key] : null; + } + + /** + * {@inheritdoc} + */ + public function withBaggageItem(string $key, string $value): SpanContext + { + return new self($this->traceId, $this->spanId, $this->isSampled, array_merge($this->items, [$key => $value])); + } + + private static function nextId(): int + { + return mt_rand(0, 99999); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockTracer.php b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockTracer.php new file mode 100644 index 000000000..f4f4577a1 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockTracer.php @@ -0,0 +1,152 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Mock; + +use OpenTracing\InvalidReferenceArgumentException; +use OpenTracing\UnsupportedFormatException; +use OpenTracing\Scope; +use OpenTracing\ScopeManager; +use OpenTracing\Span; +use OpenTracing\SpanContext; +use OpenTracing\StartSpanOptions; +use OpenTracing\Tracer; + +final class MockTracer implements Tracer +{ + /** + * @var array|MockSpan[] + */ + private $spans = []; + + /** + * @var array|callable[] + */ + private $injectors; + + /** + * @var array|callable[] + */ + private $extractors; + + /** + * @var ScopeManager + */ + private $scopeManager; + + public function __construct(array $injectors = [], array $extractors = []) + { + $this->injectors = $injectors; + $this->extractors = $extractors; + $this->scopeManager = new MockScopeManager(); + } + + /** + * {@inheritdoc} + */ + public function startActiveSpan(string $operationName, $options = []): Scope + { + if (!($options instanceof StartSpanOptions)) { + $options = StartSpanOptions::create($options); + } + + if (($activeSpan = $this->getActiveSpan()) !== null) { + $options = $options->withParent($activeSpan); + } + + $span = $this->startSpan($operationName, $options); + + return $this->scopeManager->activate($span, $options->shouldFinishSpanOnClose()); + } + + /** + * {@inheritdoc} + */ + public function startSpan(string $operationName, $options = []): Span + { + if (!($options instanceof StartSpanOptions)) { + $options = StartSpanOptions::create($options); + } + + if (empty($options->getReferences())) { + $spanContext = MockSpanContext::createAsRoot(); + } else { + $referenceContext = $options->getReferences()[0]->getSpanContext(); + if (!$referenceContext instanceof MockSpanContext) { + throw InvalidReferenceArgumentException::forInvalidContext($referenceContext); + } + $spanContext = MockSpanContext::createAsChildOf($referenceContext); + } + + $span = new MockSpan($operationName, $spanContext, $options->getStartTime()); + + foreach ($options->getTags() as $key => $value) { + $span->setTag($key, $value); + } + + $this->spans[] = $span; + + return $span; + } + + /** + * {@inheritdoc} + */ + public function inject(SpanContext $spanContext, string $format, &$carrier): void + { + if (!array_key_exists($format, $this->injectors)) { + throw UnsupportedFormatException::forFormat($format); + } + + $this->injectors[$format]($spanContext, $carrier); + } + + /** + * {@inheritdoc} + */ + public function extract(string $format, $carrier): ?SpanContext + { + if (!array_key_exists($format, $this->extractors)) { + throw UnsupportedFormatException::forFormat($format); + } + + return $this->extractors[$format]($carrier); + } + + /** + * {@inheritdoc} + */ + public function flush(): void + { + $this->spans = []; + } + + /** + * @return array|MockSpan[] + */ + public function getSpans(): array + { + return $this->spans; + } + + /** + * {@inheritdoc} + */ + public function getScopeManager(): ScopeManager + { + return $this->scopeManager; + } + + /** + * {@inheritdoc} + */ + public function getActiveSpan(): ?Span + { + if (null !== ($activeScope = $this->scopeManager->getActive())) { + return $activeScope->getSpan(); + } + + return null; + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/NoopScope.php b/vendor/opentracing/opentracing/src/OpenTracing/NoopScope.php new file mode 100644 index 000000000..7170c846a --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/NoopScope.php @@ -0,0 +1,23 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +final class NoopScope implements Scope +{ + /** + * {@inheritdoc} + */ + public function close(): void + { + } + + /** + * {@inheritdoc} + */ + public function getSpan(): Span + { + return new NoopSpan(); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/NoopScopeManager.php b/vendor/opentracing/opentracing/src/OpenTracing/NoopScopeManager.php new file mode 100644 index 000000000..5576171a8 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/NoopScopeManager.php @@ -0,0 +1,24 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +final class NoopScopeManager implements ScopeManager +{ + /** + * {@inheritdoc} + */ + public function activate(Span $span, bool $finishSpanOnClose = ScopeManager::DEFAULT_FINISH_SPAN_ON_CLOSE): Scope + { + return new NoopScope(); + } + + /** + * {@inheritdoc} + */ + public function getActive(): ?Scope + { + return new NoopScope(); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/NoopSpan.php b/vendor/opentracing/opentracing/src/OpenTracing/NoopSpan.php new file mode 100644 index 000000000..c1af8dfc7 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/NoopSpan.php @@ -0,0 +1,67 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +final class NoopSpan implements Span +{ + /** + * {@inheritdoc} + */ + public function getOperationName(): string + { + return 'noop_span'; + } + + /** + * {@inheritdoc} + */ + public function getContext(): SpanContext + { + return new NoopSpanContext(); + } + + /** + * {@inheritdoc} + */ + public function finish($finishTime = null): void + { + } + + /** + * {@inheritdoc} + */ + public function overwriteOperationName(string $newOperationName): void + { + } + + /** + * {@inheritdoc} + */ + public function setTag(string $key, $value): void + { + } + + /** + * {@inheritdoc} + */ + public function log(array $fields = [], $timestamp = null): void + { + } + + /** + * {@inheritdoc} + */ + public function addBaggageItem(string $key, string $value): void + { + } + + /** + * {@inheritdoc} + */ + public function getBaggageItem(string $key): ?string + { + return null; + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/NoopSpanContext.php b/vendor/opentracing/opentracing/src/OpenTracing/NoopSpanContext.php new file mode 100644 index 000000000..5b0de7c93 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/NoopSpanContext.php @@ -0,0 +1,35 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use EmptyIterator; +use Traversable; + +final class NoopSpanContext implements SpanContext +{ + /** + * {@inheritdoc} + */ + public function getIterator(): Traversable + { + return new EmptyIterator(); + } + + /** + * {@inheritdoc} + */ + public function getBaggageItem(string $key): ?string + { + return null; + } + + /** + * {@inheritdoc} + */ + public function withBaggageItem(string $key, string $value): SpanContext + { + return new self(); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/NoopTracer.php b/vendor/opentracing/opentracing/src/OpenTracing/NoopTracer.php new file mode 100644 index 000000000..267823bb9 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/NoopTracer.php @@ -0,0 +1,62 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +final class NoopTracer implements Tracer +{ + /** + * {@inheritdoc} + */ + public function getActiveSpan(): ?Span + { + return new NoopSpan(); + } + + /** + * {@inheritdoc} + */ + public function getScopeManager(): ScopeManager + { + return new NoopScopeManager(); + } + + /** + * {@inheritdoc} + */ + public function startSpan(string $operationName, $options = []): Span + { + return new NoopSpan(); + } + + /** + * {@inheritdoc} + */ + public function startActiveSpan(string $operationName, $options = []): Scope + { + return new NoopScope(); + } + + /** + * {@inheritdoc} + */ + public function inject(SpanContext $spanContext, string $format, &$carrier): void + { + } + + /** + * {@inheritdoc} + */ + public function extract(string $format, $carrier): ?SpanContext + { + return new NoopSpanContext(); + } + + /** + * {@inheritdoc} + */ + public function flush(): void + { + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Reference.php b/vendor/opentracing/opentracing/src/OpenTracing/Reference.php new file mode 100644 index 000000000..7dadf1785 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Reference.php @@ -0,0 +1,77 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use OpenTracing\InvalidReferenceArgumentException; + +final class Reference +{ + /** + * A Span may be the ChildOf a parent Span. In a ChildOf reference, + * the parent Span depends on the child Span in some capacity. + */ + public const CHILD_OF = 'child_of'; + + /** + * Some parent Spans do not depend in any way on the result of their + * child Spans. In these cases, we say merely that the child Span + * FollowsFrom the parent Span in a causal sense. + */ + public const FOLLOWS_FROM = 'follows_from'; + + /** + * @var string + */ + private $type; + + /** + * @var SpanContext + */ + private $spanContext; + + /** + * @param string $type + * @param SpanContext $spanContext + */ + public function __construct(string $type, SpanContext $spanContext) + { + if (empty($type)) { + throw InvalidReferenceArgumentException::forEmptyType(); + } + + $this->type = $type; + $this->spanContext = $spanContext; + } + + /** + * @param string $type + * @param Span $span + * @return Reference when context is invalid + * @throws InvalidReferenceArgumentException on empty type + */ + public static function createForSpan(string $type, Span $span): Reference + { + return new self($type, $span->getContext()); + } + + /** + * @return SpanContext + */ + public function getSpanContext(): SpanContext + { + return $this->spanContext; + } + + /** + * Checks whether a Reference is of one type. + * + * @param string $type the type for the reference + * @return bool + */ + public function isType(string $type): bool + { + return $this->type === $type; + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Scope.php b/vendor/opentracing/opentracing/src/OpenTracing/Scope.php new file mode 100644 index 000000000..174495434 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Scope.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +/** + * A {@link Scope} formalizes the activation and deactivation of a {@link Span}, usually from a CPU standpoint. + * + * Many times a {@link Span} will be extant (in that {@link Span#finish()} has not been called) despite being in a + * non-runnable state from a CPU/scheduler standpoint. For instance, a {@link Span} representing the client side of an + * RPC will be unfinished but blocked on IO while the RPC is still outstanding. A {@link Scope} defines when a given + * {@link Span} <em>is</em> scheduled and on the path. + */ +interface Scope +{ + /** + * Mark the end of the active period for the current thread and {@link Scope}, + * updating the {@link ScopeManager#active()} in the process. + * + * NOTE: Calling {@link #close} more than once on a single {@link Scope} instance leads to undefined + * behavior. + * + * @return void + */ + public function close(): void; + + /** + * @return Span the {@link Span} that's been scoped by this {@link Scope} + */ + public function getSpan(): Span; +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/ScopeManager.php b/vendor/opentracing/opentracing/src/OpenTracing/ScopeManager.php new file mode 100644 index 000000000..db5fcaa47 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/ScopeManager.php @@ -0,0 +1,40 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +/** + * Keeps track of the current active `Span`. + */ +interface ScopeManager +{ + public const DEFAULT_FINISH_SPAN_ON_CLOSE = true; + + /** + * Activates an `Span`, so that it is used as a parent when creating new spans. + * The implementation must keep track of the active spans sequence, so + * that previous spans can be resumed after a deactivation. + * + * @param Span $span the {@link Span} that should become the {@link #active()} + * @param bool $finishSpanOnClose whether span should automatically be finished + * when {@link Scope#close()} is called. Its default value is true. + * + * @return Scope instance to control the end of the active period for the {@link Span}. It is a + * programming error to neglect to call {@link Scope#close()} on the returned instance. + */ + public function activate(Span $span, bool $finishSpanOnClose = self::DEFAULT_FINISH_SPAN_ON_CLOSE): Scope; + + /** + * Return the currently active {@link Scope} which can be used to access the + * currently active {@link Scope#getSpan()}. + * + * If there is an {@link Scope non-null scope}, its wrapped {@link Span} becomes an implicit parent + * (as {@link References#CHILD_OF} reference) of any + * newly-created {@link Span} at {@link Tracer.SpanBuilder#startActive(boolean)} or {@link SpanBuilder#start()} + * time rather than at {@link Tracer#buildSpan(String)} time. + * + * @return Scope|null + */ + public function getActive(): ?Scope; +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Span.php b/vendor/opentracing/opentracing/src/OpenTracing/Span.php new file mode 100644 index 000000000..9fa8c2bc2 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Span.php @@ -0,0 +1,95 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use DateTimeInterface; + +interface Span +{ + /** + * @return string + */ + public function getOperationName(): string; + + /** + * Yields the SpanContext for this Span. Note that the return value of + * Span::getContext() is still valid after a call to Span::finish(), as is + * a call to Span::getContext() after a call to Span::finish(). + * + * @return SpanContext + */ + public function getContext(): SpanContext; + + /** + * Sets the end timestamp and finalizes Span state. + * + * With the exception of calls to getContext() (which are always allowed), + * finish() must be the last call made to any span instance, and to do + * otherwise leads to undefined behavior but not returning an exception. + * + * As an implementor, make sure you call {@see Tracer::deactivate()} + * otherwise new spans might try to be child of this one. + * + * If the span is already finished, a warning should be logged. + * + * @param float|int|DateTimeInterface|null $finishTime if passing float or int + * it should represent the timestamp (including as many decimal places as you need) + * @return void + */ + public function finish($finishTime = null): void; + + /** + * If the span is already finished, a warning should be logged. + * + * @param string $newOperationName + * @return void + */ + public function overwriteOperationName(string $newOperationName): void; + + /** + * Adds a tag to the span. + * + * If there is a pre-existing tag set for key, it is overwritten. + * + * As an implementor, consider using "standard tags" listed in {@see \OpenTracing\Tags} + * + * If the span is already finished, a warning should be logged. + * + * @param string $key + * @param string|bool|int|float $value + * @return void + */ + public function setTag(string $key, $value): void; + + /** + * Adds a log record to the span in key => value format, key must be a string and tag must be either + * a string, a boolean value, or a numeric type. + * + * If the span is already finished, a warning should be logged. + * + * @param array $fields + * @param int|float|DateTimeInterface $timestamp + * @return void + */ + public function log(array $fields = [], $timestamp = null): void; + + /** + * Adds a baggage item to the SpanContext which is immutable so it is required to use + * SpanContext::withBaggageItem to get a new one. + * + * If the span is already finished, a warning should be logged. + * + * @param string $key + * @param string $value + * @return void + */ + public function addBaggageItem(string $key, string $value): void; + + /** + * @param string $key + * @return string|null returns null when there is not a item under the provided key + */ + public function getBaggageItem(string $key): ?string; +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/SpanContext.php b/vendor/opentracing/opentracing/src/OpenTracing/SpanContext.php new file mode 100644 index 000000000..ca05ff9ac --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/SpanContext.php @@ -0,0 +1,37 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use IteratorAggregate; + +/** + * SpanContext must be immutable in order to avoid complicated lifetime + * issues around Span finish and references. + * + * Baggage items are key => value string pairs that apply to the given Span, + * its SpanContext, and all Spans which directly or transitively reference + * the local Span. That is, baggage items propagate in-band along with the + * trace itself. + */ +interface SpanContext extends IteratorAggregate +{ + /** + * Returns the value of a baggage item based on its key. If there is no + * value with such key it will return null. + * + * @param string $key + * @return string|null + */ + public function getBaggageItem(string $key): ?string; + + /** + * Creates a new SpanContext out of the existing one and the new key => value pair. + * + * @param string $key + * @param string $value + * @return SpanContext + */ + public function withBaggageItem(string $key, string $value): SpanContext; +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/StartSpanOptions.php b/vendor/opentracing/opentracing/src/OpenTracing/StartSpanOptions.php new file mode 100644 index 000000000..28b73ff0a --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/StartSpanOptions.php @@ -0,0 +1,206 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use DateTime; +use DateTimeInterface; +use OpenTracing\InvalidReferencesSetException; +use OpenTracing\InvalidSpanOptionException; + +final class StartSpanOptions +{ + /** + * @var Reference[] + */ + private $references = []; + + /** + * @var array + */ + private $tags = []; + + /** + * @var int|float|DateTimeInterface + */ + private $startTime; + + /** + * Only used for spans that are actively managed by scope manager. + * + * @var bool + */ + private $finishSpanOnClose = ScopeManager::DEFAULT_FINISH_SPAN_ON_CLOSE; + + /** + * @var bool + */ + private $ignoreActiveSpan = false; + + /** + * @param array $options + * @return StartSpanOptions + * @throws InvalidReferencesSetException when there are inconsistencies about the references + * @throws InvalidSpanOptionException when one of the options is invalid + */ + public static function create(array $options): StartSpanOptions + { + $spanOptions = new self(); + + foreach ($options as $key => $value) { + switch ($key) { + case 'child_of': + if (!empty($spanOptions->references)) { + throw InvalidSpanOptionException::forIncludingBothChildOfAndReferences(); + } + + $spanOptions->references[] = self::buildChildOf($value); + break; + + case 'references': + if (!empty($spanOptions->references)) { + throw InvalidSpanOptionException::forIncludingBothChildOfAndReferences(); + } + + if ($value instanceof Reference) { + $spanOptions->references = [$value]; + } elseif (is_array($value)) { + $spanOptions->references = self::buildReferences($value); + } else { + throw InvalidSpanOptionException::forInvalidReferenceSet($value); + } + + break; + + case 'tags': + if (!is_array($value)) { + throw InvalidSpanOptionException::forInvalidTags($value); + } + + foreach ($value as $tag => $tagValue) { + if ($tag !== (string)$tag) { + throw InvalidSpanOptionException::forInvalidTag($tag); + } + + $spanOptions->tags[$tag] = $tagValue; + } + break; + + case 'start_time': + if (is_scalar($value) && !is_numeric($value)) { + throw InvalidSpanOptionException::forInvalidStartTime(); + } + + $spanOptions->startTime = $value; + break; + + case 'finish_span_on_close': + if (!is_bool($value)) { + throw InvalidSpanOptionException::forFinishSpanOnClose($value); + } + + $spanOptions->finishSpanOnClose = $value; + break; + + case 'ignore_active_span': + if (!is_bool($value)) { + throw InvalidSpanOptionException::forIgnoreActiveSpan($value); + } + + $spanOptions->ignoreActiveSpan = $value; + break; + + default: + throw InvalidSpanOptionException::forUnknownOption($key); + } + } + + return $spanOptions; + } + + /** + * @param Span|SpanContext $parent + * @return StartSpanOptions + */ + public function withParent($parent): StartSpanOptions + { + $newSpanOptions = new StartSpanOptions(); + $newSpanOptions->references[] = self::buildChildOf($parent); + $newSpanOptions->tags = $this->tags; + $newSpanOptions->startTime = $this->startTime; + $newSpanOptions->finishSpanOnClose = $this->finishSpanOnClose; + $newSpanOptions->ignoreActiveSpan = $this->ignoreActiveSpan; + + return $newSpanOptions; + } + + /** + * @return Reference[] + */ + public function getReferences(): array + { + return $this->references; + } + + /** + * @return array + */ + public function getTags(): array + { + return $this->tags; + } + + /** + * @return int|float|DateTime|null if returning float or int it should represent + * the timestamp (including as many decimal places as you need) + */ + public function getStartTime() + { + return $this->startTime; + } + + /** + * @return bool + */ + public function shouldFinishSpanOnClose(): bool + { + return $this->finishSpanOnClose; + } + + /** + * @return bool + */ + public function shouldIgnoreActiveSpan(): bool + { + return $this->ignoreActiveSpan; + } + + private static function buildChildOf($value): Reference + { + if ($value instanceof Span) { + return Reference::createForSpan(Reference::CHILD_OF, $value); + } + + if ($value instanceof SpanContext) { + return new Reference(Reference::CHILD_OF, $value); + } + + throw InvalidSpanOptionException::forInvalidChildOf($value); + } + + private static function buildReferences(array $referencesArray): array + { + $references = []; + + foreach ($referencesArray as $reference) { + if (!($reference instanceof Reference)) { + throw InvalidSpanOptionException::forInvalidReference($reference); + } + + $references[] = $reference; + } + + return $references; + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Tags.php b/vendor/opentracing/opentracing/src/OpenTracing/Tags.php new file mode 100644 index 000000000..5d06627de --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Tags.php @@ -0,0 +1,124 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Tags; + +/** + * SpanKind hints at relationship between spans, e.g. client/server + */ +const SPAN_KIND = 'span.kind'; + +/** + * Marks a span representing the client-side of an RPC or other remote call + */ +const SPAN_KIND_RPC_CLIENT = 'client'; + +/** + * Marks a span representing the server-side of an RPC or other remote call + */ +const SPAN_KIND_RPC_SERVER = 'server'; + +/** + * Marks a span as representing the producer within a messaging context + */ +const SPAN_KIND_MESSAGE_BUS_PRODUCER = 'producer'; + +/** + * Marks a span as representing the consumer within a messaging context + */ +const SPAN_KIND_MESSAGE_BUS_CONSUMER = 'consumer'; + +/** + * Component is a low-cardinality identifier of the module, library, + * or package that is generating a span. + */ +const COMPONENT = 'component'; + +/** + * SAMPLING_PRIORITY (uint16) determines the priority of sampling this Span. + */ +const SAMPLING_PRIORITY = 'sampling.priority'; + +/** + * PeerService records the service name of the peer + */ +const PEER_SERVICE = 'peer.service'; + +/** + * PeerHostname records the host name of the peer + */ +const PEER_HOSTNAME = 'peer.hostname'; + +/** + * PEER_ADDRESS (string) suitable for use in a networking client library. + * This may be a "ip:port", a bare "hostname", a FQDN, or even a # JDBC + * substring like "mysql://prod-db:3306" + */ +const PEER_ADDRESS = 'peer.address'; + +/** + * PEER_HOST_IPV4 (uint32) records IP v4 host address of the peer + */ +const PEER_HOST_IPV4 = 'peer.ipv4'; + +/** + * PEER_HOST_IPV6 (string) records IP v6 host address of the peer + */ +const PEER_HOST_IPV6 = 'peer.ipv6'; + +/** PEER_PORT (uint16) records port number of the peer */ +const PEER_PORT = 'peer.port'; + +/** + * HTTPUrl should be the URL of the request being handled in this segment + * of the trace, in standard URI format. The protocol is optional. + */ +const HTTP_URL = 'http.url'; + +/** + * HTTPMethod is the HTTP method of the request, and is case-insensitive. + */ +const HTTP_METHOD = 'http.method'; + +/** + * HTTPStatusCode is the numeric HTTP status code (200, 404, etc) of the + * HTTP response. + */ +const HTTP_STATUS_CODE = 'http.status_code'; + +/** + * DATABASE_INSTANCE (string) The database instance name. + */ +const DATABASE_INSTANCE = 'db.instance'; + +/** + * DATABASE_STATEMENT (string) A database statement for the given database + * type. E.g., for db.type="SQL", "SELECT * FROM user_table"; # for + * db.type="redis", "SET mykey 'WuValue'". */ +const DATABASE_STATEMENT = 'db.statement'; + +/** + * DATABASE_TYPE (string) For any SQL database, "sql". For others, the lower-case + * database category, e.g. "cassandra", "hbase", or "redis". + */ +const DATABASE_TYPE = 'db.type'; + +/** + * DATABASE_USER (string) Username for accessing database. E.g., "readonly_user" or + * "reporting_user" + */ +const DATABASE_USER = 'db.user'; + +/** + * MESSAGE_BUS_DESTINATION (string) An address at which messages can be # + * exchanged. E.g. A Kafka record has an associated "topic name" that can # + * be extracted by the instrumented producer or consumer and stored # using + * this tag. + */ +const MESSAGE_BUS_DESTINATION = 'message_bus.destination'; + +/** + * Error indicates that operation represented by the span resulted in an error. + */ +const ERROR = 'error'; diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Tracer.php b/vendor/opentracing/opentracing/src/OpenTracing/Tracer.php new file mode 100644 index 000000000..391a5159b --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Tracer.php @@ -0,0 +1,119 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use OpenTracing\UnsupportedFormatException; +use OpenTracing\InvalidSpanOptionException; +use OpenTracing\InvalidReferencesSetException; + +interface Tracer +{ + /** + * Returns the current {@link ScopeManager}, which may be a noop but may not be null. + * + * @return ScopeManager + */ + public function getScopeManager(): ScopeManager; + + /** + * Returns the active {@link Span}. This is a shorthand for + * Tracer::getScopeManager()->getActive()->getSpan(), + * and null will be returned if {@link Scope#active()} is null. + * + * @return Span|null + */ + public function getActiveSpan(): ?Span; + + /** + * Starts a new span that is activated on a scope manager. + * + * It's also possible to not finish the {@see \OpenTracing\Span} when + * {@see \OpenTracing\Scope} context expires: + * + * $scope = $tracer->startActiveSpan('...', [ + * 'finish_span_on_close' => false, + * ]); + * $span = $scope->getSpan(); + * try { + * $span->setTag(Tags\HTTP_METHOD, 'GET'); + * // ... + * } finally { + * $scope->close(); + * } + * // $span->finish() is not called as part of Scope deactivation as + * // finish_span_on_close is false + * + * @param string $operationName + * @param array|StartSpanOptions $options Same as for startSpan() with + * additional option of `finish_span_on_close` that enables finishing + * of span whenever a scope is closed. It is true by default. + * + * @return Scope A Scope that holds newly created Span and is activated on + * a ScopeManager. + */ + public function startActiveSpan(string $operationName, $options = []): Scope; + + /** + * Starts and returns a new span representing a unit of work. + * + * Whenever `child_of` reference is not passed then + * {@see \OpenTracing\ScopeManager::getActive()} span is used as `child_of` + * reference. In order to ignore implicit parent span pass in + * `ignore_active_span` option set to true. + * + * Starting a span with explicit parent: + * + * $tracer->startSpan('...', [ + * 'child_of' => $parentSpan, + * ]); + * + * @param string $operationName + * @param array|StartSpanOptions $options See StartSpanOptions for + * available options. + * + * @return Span + * + * @throws InvalidSpanOptionException for invalid option + * @throws InvalidReferencesSetException for invalid references set + * @see \OpenTracing\StartSpanOptions + */ + public function startSpan(string $operationName, $options = []): Span; + + /** + * @param SpanContext $spanContext + * @param string $format + * @param mixed $carrier + * @return void + * + * @throws UnsupportedFormatException when the format is not recognized by the tracer + * implementation + * @see Formats + */ + public function inject(SpanContext $spanContext, string $format, &$carrier): void; + + /** + * @param string $format + * @param mixed $carrier + * @return SpanContext|null + * + * @throws UnsupportedFormatException when the format is not recognized by the tracer + * implementation + * @see Formats + */ + public function extract(string $format, $carrier): ?SpanContext; + + /** + * Allow tracer to send span data to be instrumented. + * + * This method might not be needed depending on the tracing implementation + * but one should make sure this method is called after the request is delivered + * to the client. + * + * As an implementor, a good idea would be to use {@see register_shutdown_function} + * or {@see fastcgi_finish_request} in order to not to delay the end of the request + * to the client. + */ + public function flush(): void; +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/UnsupportedFormatException.php b/vendor/opentracing/opentracing/src/OpenTracing/UnsupportedFormatException.php new file mode 100644 index 000000000..dd4ef56a3 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/UnsupportedFormatException.php @@ -0,0 +1,22 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use UnexpectedValueException; + +/** + * Thrown when trying to inject or extract in an invalid format + */ +final class UnsupportedFormatException extends UnexpectedValueException +{ + /** + * @param string $format + * @return UnsupportedFormatException + */ + public static function forFormat(string $format): UnsupportedFormatException + { + return new self(sprintf('The format "%s" is not supported.', $format)); + } +} |