From 079be303aea204619fab7edf8f244737035dddf2 Mon Sep 17 00:00:00 2001 From: Thomas Hills Date: Tue, 24 Oct 2023 16:46:44 +0100 Subject: [PATCH 1/5] Added check for ignore active span option when starting a span --- src/ZipkinOpenTracing/Tracer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ZipkinOpenTracing/Tracer.php b/src/ZipkinOpenTracing/Tracer.php index b95f60d..0feae40 100644 --- a/src/ZipkinOpenTracing/Tracer.php +++ b/src/ZipkinOpenTracing/Tracer.php @@ -106,7 +106,7 @@ public function startSpan(string $operationName, $options = []): OTSpan $options = StartSpanOptions::create($options); } - if (!$this->hasParentInOptions($options) && $this->getActiveSpan() !== null) { + if (!$options->shouldIgnoreActiveSpan() && !$this->hasParentInOptions($options) && $this->getActiveSpan() !== null) { $parent = $this->getActiveSpan()->getContext(); $options = $options->withParent($parent); } From d34a96c2a59c51ee595a81f761681bb68d948b53 Mon Sep 17 00:00:00 2001 From: Thomas Hills Date: Wed, 25 Oct 2023 09:30:40 +0100 Subject: [PATCH 2/5] Added check to startActiveSpan and added line breaks --- src/ZipkinOpenTracing/Tracer.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ZipkinOpenTracing/Tracer.php b/src/ZipkinOpenTracing/Tracer.php index 0feae40..f8a24ee 100644 --- a/src/ZipkinOpenTracing/Tracer.php +++ b/src/ZipkinOpenTracing/Tracer.php @@ -85,7 +85,9 @@ public function startActiveSpan(string $operationName, $options = []): OTScope $options = StartSpanOptions::create($options); } - if (!$this->hasParentInOptions($options) && $this->getActiveSpan() !== null) { + if (!$options->shouldIgnoreActiveSpan() + && !$this->hasParentInOptions($options) + && $this->getActiveSpan() !== null) { $parent = $this->getActiveSpan()->getContext(); $options = $options->withParent($parent); } @@ -106,7 +108,9 @@ public function startSpan(string $operationName, $options = []): OTSpan $options = StartSpanOptions::create($options); } - if (!$options->shouldIgnoreActiveSpan() && !$this->hasParentInOptions($options) && $this->getActiveSpan() !== null) { + if (!$options->shouldIgnoreActiveSpan() + && !$this->hasParentInOptions($options) + && $this->getActiveSpan() !== null) { $parent = $this->getActiveSpan()->getContext(); $options = $options->withParent($parent); } From d87249a7c19b126cb3096e886bb712cb3a0c7c79 Mon Sep 17 00:00:00 2001 From: Thomas Hills Date: Wed, 25 Oct 2023 14:42:38 +0100 Subject: [PATCH 3/5] Added tests for ignore_active_span option in startSpan and startActiveSpan --- tests/Unit/TracerTest.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Unit/TracerTest.php b/tests/Unit/TracerTest.php index af2ddaa..c8afafa 100644 --- a/tests/Unit/TracerTest.php +++ b/tests/Unit/TracerTest.php @@ -108,6 +108,40 @@ public function testStartSpanWithNoParentSuccess() $this->assertInstanceOf(Span::class, $span); } + public function testStartSpanWithIgnoreActiveSpan() + { + $tracing = TracingBuilder::create()->build(); + $tracer = new Tracer($tracing); + $firstSpan = $tracer->startActiveSpan(self::OPERATION_NAME); + + $secondSpan = $tracer->startSpan(self::OPERATION_NAME, [ + 'ignore_active_span' => true, + ]); + + $firstContext = $firstSpan->getSpan()->getContext()->getContext(); + $secondContext = $secondSpan->getContext()->getContext(); + + $this->assertNotEquals($firstContext->getTraceId(), $secondContext->getTraceId()); + $this->assertTrue($secondContext->getParentId() === null); + } + + public function testStartActiveSpanWithIgnoreActiveSpan() + { + $tracing = TracingBuilder::create()->build(); + $tracer = new Tracer($tracing); + $firstSpan = $tracer->startActiveSpan(self::OPERATION_NAME); + + $secondSpan = $tracer->startActiveSpan(self::OPERATION_NAME, [ + 'ignore_active_span' => true, + ]); + + $firstContext = $firstSpan->getSpan()->getContext()->getContext(); + $secondContext = $secondSpan->getSpan()->getContext()->getContext(); + + $this->assertNotEquals($firstContext->getTraceId(), $secondContext->getTraceId()); + $this->assertTrue($secondContext->getParentId() === null); + } + public function testStartSpanWithParentSuccess() { $tracing = TracingBuilder::create()->build(); From f1d46ea1a54af34364367c19fd32299e83327593 Mon Sep 17 00:00:00 2001 From: Thomas Hills Date: Mon, 30 Oct 2023 10:12:59 +0000 Subject: [PATCH 4/5] Fixed missing return types --- tests/Unit/Request.php | 270 ++++++++++++++++++++--------------------- 1 file changed, 135 insertions(+), 135 deletions(-) diff --git a/tests/Unit/Request.php b/tests/Unit/Request.php index 39e4102..c7b408e 100644 --- a/tests/Unit/Request.php +++ b/tests/Unit/Request.php @@ -1,135 +1,135 @@ - $value) { - $this->headers[strtolower($key)] = [$value]; - } - } - - /** - * @return string[][] - */ - public function getHeaders() - { - return $this->headers; - } - - /** - * @return bool - */ - public function hasHeader($name) - { - foreach ($this->headers as $key => $value) { - if ($key === strtolower($name)) { - return true; - } - } - - return false; - } - - /** - * @return string[] - */ - public function getHeader($name) - { - foreach ($this->headers as $key => $value) { - if ($key === strtolower($name)) { - return $value; - } - } - - return []; - } - - public function withHeader($name, $value) - { - $this->headers[strtolower($name)] = [$value]; - return $this; - } - - // These functions are required by the interface but no used during - // parsing of headers - // - // phpcs:disable - public function withAddedHeader($name, $value) - { - throw new LogicException('not implemented'); - } - - public function getProtocolVersion() - { - throw new LogicException('not implemented'); - } - - public function withProtocolVersion($version) - { - throw new LogicException('not implemented'); - } - - public function getHeaderLine($name) - { - throw new LogicException('not implemented'); - } - - public function withoutHeader($name) - { - throw new LogicException('not implemented'); - } - - public function getBody() - { - throw new LogicException('not implemented'); - } - - public function withBody(StreamInterface $body) - { - throw new LogicException('not implemented'); - } - - public function getRequestTarget() - { - throw new LogicException('not implemented'); - } - - public function withRequestTarget($requestTarget) - { - throw new LogicException('not implemented'); - } - - public function getMethod() - { - throw new LogicException('not implemented'); - } - - public function withMethod($method) - { - throw new LogicException('not implemented'); - } - - public function getUri() - { - throw new LogicException('not implemented'); - } - - public function withUri(UriInterface $uri, $preserveHost = false) - { - throw new LogicException('not implemented'); - } - // phpcs:enable -} + $value) { + $this->headers[strtolower($key)] = [$value]; + } + } + + /** + * @return string[][] + */ + public function getHeaders(): array + { + return $this->headers; + } + + /** + * @return bool + */ + public function hasHeader($name): bool + { + foreach ($this->headers as $key => $value) { + if ($key === strtolower($name)) { + return true; + } + } + + return false; + } + + /** + * @return string[] + */ + public function getHeader($name): array + { + foreach ($this->headers as $key => $value) { + if ($key === strtolower($name)) { + return $value; + } + } + + return []; + } + + public function withHeader($name, $value): \Psr\Http\Message\MessageInterface + { + $this->headers[strtolower($name)] = [$value]; + return $this; + } + + // These functions are required by the interface but no used during + // parsing of headers + // + // phpcs:disable + public function withAddedHeader($name, $value): \Psr\Http\Message\MessageInterface + { + throw new LogicException('not implemented'); + } + + public function getProtocolVersion(): string + { + throw new LogicException('not implemented'); + } + + public function withProtocolVersion($version): \Psr\Http\Message\MessageInterface + { + throw new LogicException('not implemented'); + } + + public function getHeaderLine($name): string + { + throw new LogicException('not implemented'); + } + + public function withoutHeader($name): \Psr\Http\Message\MessageInterface + { + throw new LogicException('not implemented'); + } + + public function getBody(): StreamInterface + { + throw new LogicException('not implemented'); + } + + public function withBody(StreamInterface $body): \Psr\Http\Message\MessageInterface + { + throw new LogicException('not implemented'); + } + + public function getRequestTarget(): string + { + throw new LogicException('not implemented'); + } + + public function withRequestTarget($requestTarget): RequestInterface + { + throw new LogicException('not implemented'); + } + + public function getMethod(): string + { + throw new LogicException('not implemented'); + } + + public function withMethod($method): RequestInterface + { + throw new LogicException('not implemented'); + } + + public function getUri(): UriInterface + { + throw new LogicException('not implemented'); + } + + public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface + { + throw new LogicException('not implemented'); + } + // phpcs:enable +} From b8fe5c627e87193b941ceb479fea00997131862e Mon Sep 17 00:00:00 2001 From: Thomas Hills Date: Mon, 30 Oct 2023 10:26:46 +0000 Subject: [PATCH 5/5] Changed line seperators in Request to \n instead of \r\n --- tests/Unit/Request.php | 270 ++++++++++++++++++++--------------------- 1 file changed, 135 insertions(+), 135 deletions(-) diff --git a/tests/Unit/Request.php b/tests/Unit/Request.php index c7b408e..96f01b3 100644 --- a/tests/Unit/Request.php +++ b/tests/Unit/Request.php @@ -1,135 +1,135 @@ - $value) { - $this->headers[strtolower($key)] = [$value]; - } - } - - /** - * @return string[][] - */ - public function getHeaders(): array - { - return $this->headers; - } - - /** - * @return bool - */ - public function hasHeader($name): bool - { - foreach ($this->headers as $key => $value) { - if ($key === strtolower($name)) { - return true; - } - } - - return false; - } - - /** - * @return string[] - */ - public function getHeader($name): array - { - foreach ($this->headers as $key => $value) { - if ($key === strtolower($name)) { - return $value; - } - } - - return []; - } - - public function withHeader($name, $value): \Psr\Http\Message\MessageInterface - { - $this->headers[strtolower($name)] = [$value]; - return $this; - } - - // These functions are required by the interface but no used during - // parsing of headers - // - // phpcs:disable - public function withAddedHeader($name, $value): \Psr\Http\Message\MessageInterface - { - throw new LogicException('not implemented'); - } - - public function getProtocolVersion(): string - { - throw new LogicException('not implemented'); - } - - public function withProtocolVersion($version): \Psr\Http\Message\MessageInterface - { - throw new LogicException('not implemented'); - } - - public function getHeaderLine($name): string - { - throw new LogicException('not implemented'); - } - - public function withoutHeader($name): \Psr\Http\Message\MessageInterface - { - throw new LogicException('not implemented'); - } - - public function getBody(): StreamInterface - { - throw new LogicException('not implemented'); - } - - public function withBody(StreamInterface $body): \Psr\Http\Message\MessageInterface - { - throw new LogicException('not implemented'); - } - - public function getRequestTarget(): string - { - throw new LogicException('not implemented'); - } - - public function withRequestTarget($requestTarget): RequestInterface - { - throw new LogicException('not implemented'); - } - - public function getMethod(): string - { - throw new LogicException('not implemented'); - } - - public function withMethod($method): RequestInterface - { - throw new LogicException('not implemented'); - } - - public function getUri(): UriInterface - { - throw new LogicException('not implemented'); - } - - public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface - { - throw new LogicException('not implemented'); - } - // phpcs:enable -} + $value) { + $this->headers[strtolower($key)] = [$value]; + } + } + + /** + * @return string[][] + */ + public function getHeaders(): array + { + return $this->headers; + } + + /** + * @return bool + */ + public function hasHeader($name): bool + { + foreach ($this->headers as $key => $value) { + if ($key === strtolower($name)) { + return true; + } + } + + return false; + } + + /** + * @return string[] + */ + public function getHeader($name): array + { + foreach ($this->headers as $key => $value) { + if ($key === strtolower($name)) { + return $value; + } + } + + return []; + } + + public function withHeader($name, $value): \Psr\Http\Message\MessageInterface + { + $this->headers[strtolower($name)] = [$value]; + return $this; + } + + // These functions are required by the interface but no used during + // parsing of headers + // + // phpcs:disable + public function withAddedHeader($name, $value): \Psr\Http\Message\MessageInterface + { + throw new LogicException('not implemented'); + } + + public function getProtocolVersion(): string + { + throw new LogicException('not implemented'); + } + + public function withProtocolVersion($version): \Psr\Http\Message\MessageInterface + { + throw new LogicException('not implemented'); + } + + public function getHeaderLine($name): string + { + throw new LogicException('not implemented'); + } + + public function withoutHeader($name): \Psr\Http\Message\MessageInterface + { + throw new LogicException('not implemented'); + } + + public function getBody(): StreamInterface + { + throw new LogicException('not implemented'); + } + + public function withBody(StreamInterface $body): \Psr\Http\Message\MessageInterface + { + throw new LogicException('not implemented'); + } + + public function getRequestTarget(): string + { + throw new LogicException('not implemented'); + } + + public function withRequestTarget($requestTarget): RequestInterface + { + throw new LogicException('not implemented'); + } + + public function getMethod(): string + { + throw new LogicException('not implemented'); + } + + public function withMethod($method): RequestInterface + { + throw new LogicException('not implemented'); + } + + public function getUri(): UriInterface + { + throw new LogicException('not implemented'); + } + + public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface + { + throw new LogicException('not implemented'); + } + // phpcs:enable +}