diff --git a/src/Instrumentation/Psr18/src/Psr18Instrumentation.php b/src/Instrumentation/Psr18/src/Psr18Instrumentation.php index 0be3127aa..bf78917ce 100644 --- a/src/Instrumentation/Psr18/src/Psr18Instrumentation.php +++ b/src/Instrumentation/Psr18/src/Psr18Instrumentation.php @@ -49,6 +49,7 @@ public static function register(): void ->spanBuilder(sprintf('%s', $request->getMethod())) ->setParent($parentContext) ->setSpanKind(SpanKind::KIND_CLIENT) + ->setAttribute(TraceAttributes::PEER_SERVICE, $request->getUri()->getHost()) ->setAttribute(TraceAttributes::URL_FULL, (string) $request->getUri()) ->setAttribute(TraceAttributes::HTTP_REQUEST_METHOD, $request->getMethod()) ->setAttribute(TraceAttributes::NETWORK_PROTOCOL_VERSION, $request->getProtocolVersion()) diff --git a/src/Instrumentation/Psr18/tests/Integration/Psr18InstrumentationTest.php b/src/Instrumentation/Psr18/tests/Integration/Psr18InstrumentationTest.php index f00e9d17f..bd12e33f5 100644 --- a/src/Instrumentation/Psr18/tests/Integration/Psr18InstrumentationTest.php +++ b/src/Instrumentation/Psr18/tests/Integration/Psr18InstrumentationTest.php @@ -80,6 +80,8 @@ public function test_send_request(string $method, string $uri, int $statusCode): $span = $this->storage[0]; $this->assertStringContainsString($method, $span->getName()); + $this->assertTrue($span->getAttributes()->has(TraceAttributes::PEER_SERVICE)); + $this->assertSame(parse_url($uri)['host'] ?? null, $span->getAttributes()->get(TraceAttributes::PEER_SERVICE)); $this->assertTrue($span->getAttributes()->has(TraceAttributes::URL_FULL)); $this->assertSame($uri, $span->getAttributes()->get(TraceAttributes::URL_FULL)); $this->assertTrue($span->getAttributes()->has(TraceAttributes::HTTP_REQUEST_METHOD));