From 09c28b7956c6c81944b6a8a41e18370640fddcb3 Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Tue, 23 Jul 2024 06:09:39 -0500 Subject: [PATCH] Change Span Names When No Message is Handled With the idea being to make these spans easier to drop. --- src/Otel/PmgQueueInstrumentation.php | 2 ++ test/integration/ConsumerOtelIntTest.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Otel/PmgQueueInstrumentation.php b/src/Otel/PmgQueueInstrumentation.php index 36900ec..3e8d849 100644 --- a/src/Otel/PmgQueueInstrumentation.php +++ b/src/Otel/PmgQueueInstrumentation.php @@ -112,6 +112,8 @@ public static function register(): bool $span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage()); } elseif ($result === false) { $span->setStatus(StatusCode::STATUS_ERROR, 'Message was not handled successfully'); + } elseif ($result === null) { + $span->updateName($queueName.' empty-receive'); } $span->end(); diff --git a/test/integration/ConsumerOtelIntTest.php b/test/integration/ConsumerOtelIntTest.php index 3eeec74..53dabe0 100644 --- a/test/integration/ConsumerOtelIntTest.php +++ b/test/integration/ConsumerOtelIntTest.php @@ -43,7 +43,7 @@ public function testConsumerOnceEmitsSpansWhenNoMessagesAreHandled() : void $this->assertFalse($called); $this->assertCount(1, $this->spans); $span = $this->spans[0]; - $this->assertSame(self::Q.' receive', $span->getName()); + $this->assertSame(self::Q.' empty-receive', $span->getName()); $attr = $span->getAttributes(); $this->assertSame(self::Q, $attr->get(TraceAttributes::MESSAGING_DESTINATION_NAME)); $this->assertSame('receive', $attr->get(PmgQueueInstrumentation::OPERATION_TYPE));