Skip to content

Commit

Permalink
Add peer.service attribute to psr18 spans
Browse files Browse the repository at this point in the history
  • Loading branch information
Evandro Poianas committed Oct 5, 2024
1 parent 67ce817 commit d83f8e0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Instrumentation/Psr18/src/Psr18Instrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit d83f8e0

Please sign in to comment.