From 67ce8178849eb977f9c41f4b23428c2837741d79 Mon Sep 17 00:00:00 2001 From: Evandro Caetano Date: Fri, 4 Oct 2024 13:40:29 +0200 Subject: [PATCH] Add peer.service attribute to symfony http client spans (#302) --- src/Instrumentation/Symfony/src/HttpClientInstrumentation.php | 1 + .../Symfony/tests/Integration/HttpClientInstrumentationTest.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/Instrumentation/Symfony/src/HttpClientInstrumentation.php b/src/Instrumentation/Symfony/src/HttpClientInstrumentation.php index d62c1923..666ac67a 100644 --- a/src/Instrumentation/Symfony/src/HttpClientInstrumentation.php +++ b/src/Instrumentation/Symfony/src/HttpClientInstrumentation.php @@ -52,6 +52,7 @@ public static function register(): void ->tracer() ->spanBuilder(\sprintf('%s', $params[0])) ->setSpanKind(SpanKind::KIND_CLIENT) + ->setAttribute(TraceAttributes::PEER_SERVICE, parse_url((string) $params[1])['host'] ?? null) ->setAttribute(TraceAttributes::URL_FULL, (string) $params[1]) ->setAttribute(TraceAttributes::HTTP_REQUEST_METHOD, $params[0]) ->setAttribute(TraceAttributes::CODE_FUNCTION, $function) diff --git a/src/Instrumentation/Symfony/tests/Integration/HttpClientInstrumentationTest.php b/src/Instrumentation/Symfony/tests/Integration/HttpClientInstrumentationTest.php index 99522c61..2221b977 100644 --- a/src/Instrumentation/Symfony/tests/Integration/HttpClientInstrumentationTest.php +++ b/src/Instrumentation/Symfony/tests/Integration/HttpClientInstrumentationTest.php @@ -48,6 +48,8 @@ public function test_send_request(string $method, string $uri, int $statusCode, $this->assertNotNull($requestHeaders['HTTP_TRACEPARENT']); } + $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));