Skip to content

Commit 37c6b0b

Browse files
Update TraceAttributes to semconv to 1.22.0 (#204)
* Replace HTTP_FLAVOR with NETWORK_PROTOCOL_VERSION * Set SemConv version * Update deprecated attributes * Update NETWORK_PEER_ADDRESS
1 parent c29d317 commit 37c6b0b

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"php": "^8.0",
1212
"ext-opentelemetry": "*",
1313
"open-telemetry/api": "^1.0.0beta10",
14-
"open-telemetry/sem-conv": "^1",
14+
"open-telemetry/sem-conv": "^1.22",
1515
"symfony/http-kernel": "*",
1616
"symfony/http-client-contracts": "*"
1717
},

src/HttpClientInstrumentation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public static function register(): void
3838
->tracer()
3939
->spanBuilder(\sprintf('HTTP %s', $params[0]))
4040
->setSpanKind(SpanKind::KIND_CLIENT)
41-
->setAttribute(TraceAttributes::HTTP_URL, (string) $params[1])
42-
->setAttribute(TraceAttributes::HTTP_METHOD, $params[0])
41+
->setAttribute(TraceAttributes::URL_FULL, (string) $params[1])
42+
->setAttribute(TraceAttributes::HTTP_REQUEST_METHOD, $params[0])
4343
->setAttribute(TraceAttributes::CODE_FUNCTION, $function)
4444
->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)
4545
->setAttribute(TraceAttributes::CODE_FILEPATH, $filename)
@@ -72,10 +72,10 @@ public static function register(): void
7272
$statusCode = $info['http_code'];
7373

7474
if (0 !== $statusCode && null !== $statusCode && $span->isRecording()) {
75-
$span->setAttribute(TraceAttributes::HTTP_STATUS_CODE, $statusCode);
75+
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_STATUS_CODE, $statusCode);
7676

7777
if ($statusCode >= 400 && $statusCode < 600) {
78-
$span->setAttribute(TraceAttributes::HTTP_STATUS_CODE, $statusCode);
78+
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_STATUS_CODE, $statusCode);
7979
$span->setStatus(StatusCode::STATUS_ERROR);
8080
}
8181

src/SymfonyInstrumentation.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public static function register(): void
5252
$parent = Globals::propagator()->extract($request, RequestPropagationGetter::instance());
5353
$span = $builder
5454
->setParent($parent)
55-
->setAttribute(TraceAttributes::HTTP_URL, $request->getUri())
56-
->setAttribute(TraceAttributes::HTTP_METHOD, $request->getMethod())
57-
->setAttribute(TraceAttributes::HTTP_REQUEST_CONTENT_LENGTH, $request->headers->get('Content-Length'))
58-
->setAttribute(TraceAttributes::HTTP_SCHEME, $request->getScheme())
55+
->setAttribute(TraceAttributes::URL_FULL, $request->getUri())
56+
->setAttribute(TraceAttributes::HTTP_REQUEST_METHOD, $request->getMethod())
57+
->setAttribute(TraceAttributes::HTTP_REQUEST_BODY_SIZE, $request->headers->get('Content-Length'))
58+
->setAttribute(TraceAttributes::URL_SCHEME, $request->getScheme())
5959
->startSpan();
6060
$request->attributes->set(SpanInterface::class, $span);
6161
} else {
@@ -103,15 +103,15 @@ public static function register(): void
103103
if ($response->getStatusCode() >= Response::HTTP_BAD_REQUEST) {
104104
$span->setStatus(StatusCode::STATUS_ERROR);
105105
}
106-
$span->setAttribute(TraceAttributes::HTTP_STATUS_CODE, $response->getStatusCode());
107-
$span->setAttribute(TraceAttributes::HTTP_FLAVOR, $response->getProtocolVersion());
106+
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_STATUS_CODE, $response->getStatusCode());
107+
$span->setAttribute(TraceAttributes::NETWORK_PROTOCOL_VERSION, $response->getProtocolVersion());
108108
$contentLength = $response->headers->get('Content-Length');
109109
/** @psalm-suppress PossiblyFalseArgument */
110110
if (null === $contentLength && is_string($response->getContent())) {
111111
$contentLength = \strlen($response->getContent());
112112
}
113113

114-
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_CONTENT_LENGTH, $contentLength);
114+
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_BODY_SIZE, $contentLength);
115115

116116
// Propagate traceresponse header to response, if TraceResponsePropagator is present
117117
if (class_exists('OpenTelemetry\Contrib\Propagation\TraceResponse\TraceResponsePropagator')) {

tests/Integration/HttpClientInstrumentationTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public function test_send_request(string $method, string $uri, int $statusCode,
4848
$this->assertNotNull($requestHeaders['HTTP_TRACEPARENT']);
4949
}
5050

51-
$this->assertTrue($span->getAttributes()->has(TraceAttributes::HTTP_URL));
52-
$this->assertSame($uri, $span->getAttributes()->get(TraceAttributes::HTTP_URL));
53-
$this->assertTrue($span->getAttributes()->has(TraceAttributes::HTTP_METHOD));
54-
$this->assertSame($method, $span->getAttributes()->get(TraceAttributes::HTTP_METHOD));
55-
$this->assertTrue($span->getAttributes()->has(TraceAttributes::HTTP_STATUS_CODE));
51+
$this->assertTrue($span->getAttributes()->has(TraceAttributes::URL_FULL));
52+
$this->assertSame($uri, $span->getAttributes()->get(TraceAttributes::URL_FULL));
53+
$this->assertTrue($span->getAttributes()->has(TraceAttributes::HTTP_REQUEST_METHOD));
54+
$this->assertSame($method, $span->getAttributes()->get(TraceAttributes::HTTP_REQUEST_METHOD));
55+
$this->assertTrue($span->getAttributes()->has(TraceAttributes::HTTP_RESPONSE_STATUS_CODE));
5656
$this->assertSame($spanStatus, $span->getStatus()->getCode());
57-
$this->assertSame($statusCode, $span->getAttributes()->get(TraceAttributes::HTTP_STATUS_CODE));
57+
$this->assertSame($statusCode, $span->getAttributes()->get(TraceAttributes::HTTP_RESPONSE_STATUS_CODE));
5858
}
5959

6060
public function test_throw_exception(): void
@@ -77,8 +77,8 @@ public function test_throw_exception(): void
7777
/** @var EventInterface $event */
7878
$event = $span->getEvents()[0];
7979

80-
$this->assertTrue($span->getAttributes()->has(TraceAttributes::HTTP_URL));
81-
$this->assertTrue($span->getAttributes()->has(TraceAttributes::HTTP_METHOD));
80+
$this->assertTrue($span->getAttributes()->has(TraceAttributes::URL_FULL));
81+
$this->assertTrue($span->getAttributes()->has(TraceAttributes::HTTP_REQUEST_METHOD));
8282
$this->assertSame(StatusCode::STATUS_ERROR, $span->getStatus()->getCode());
8383
$this->assertSame(InvalidArgumentException::class, $event->getAttributes()->get('exception.type'));
8484
}

tests/Integration/SymfonyInstrumentationTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ public function test_http_kernel_handle_attributes(): void
4949
$attributes = $this->storage[0]->getAttributes();
5050
$this->assertCount(1, $this->storage);
5151
$this->assertEquals('HTTP GET', $this->storage[0]->getName());
52-
$this->assertEquals('http://:/', $attributes->get(TraceAttributes::HTTP_URL));
53-
$this->assertEquals('GET', $attributes->get(TraceAttributes::HTTP_METHOD));
54-
$this->assertEquals('http', $attributes->get(TraceAttributes::HTTP_SCHEME));
52+
$this->assertEquals('http://:/', $attributes->get(TraceAttributes::URL_FULL));
53+
$this->assertEquals('GET', $attributes->get(TraceAttributes::HTTP_REQUEST_METHOD));
54+
$this->assertEquals('http', $attributes->get(TraceAttributes::URL_SCHEME));
5555
$this->assertEquals('test_route', $attributes->get(TraceAttributes::HTTP_ROUTE));
56-
$this->assertEquals(200, $attributes->get(TraceAttributes::HTTP_STATUS_CODE));
57-
$this->assertEquals('1.0', $attributes->get(TraceAttributes::HTTP_FLAVOR));
58-
$this->assertEquals(5, $attributes->get(TraceAttributes::HTTP_RESPONSE_CONTENT_LENGTH));
56+
$this->assertEquals(200, $attributes->get(TraceAttributes::HTTP_RESPONSE_STATUS_CODE));
57+
$this->assertEquals('1.0', $attributes->get(TraceAttributes::NETWORK_PROTOCOL_VERSION));
58+
$this->assertEquals(5, $attributes->get(TraceAttributes::HTTP_RESPONSE_BODY_SIZE));
5959

6060
$this->assertArrayHasKey(
6161
TraceResponsePropagator::TRACERESPONSE,
@@ -74,7 +74,7 @@ public function test_http_kernel_handle_stream_response(): void
7474

7575
$response = $kernel->handle(new Request());
7676
$this->assertCount(1, $this->storage);
77-
$this->assertNull($this->storage[0]->getAttributes()->get(TraceAttributes::HTTP_RESPONSE_CONTENT_LENGTH));
77+
$this->assertNull($this->storage[0]->getAttributes()->get(TraceAttributes::HTTP_RESPONSE_BODY_SIZE));
7878

7979
$this->assertArrayHasKey(
8080
TraceResponsePropagator::TRACERESPONSE,
@@ -90,7 +90,7 @@ public function test_http_kernel_handle_binary_file_response(): void
9090

9191
$response = $kernel->handle(new Request());
9292
$this->assertCount(1, $this->storage);
93-
$this->assertNull($this->storage[0]->getAttributes()->get(TraceAttributes::HTTP_RESPONSE_CONTENT_LENGTH));
93+
$this->assertNull($this->storage[0]->getAttributes()->get(TraceAttributes::HTTP_RESPONSE_BODY_SIZE));
9494

9595
$this->assertArrayHasKey(
9696
TraceResponsePropagator::TRACERESPONSE,

0 commit comments

Comments
 (0)