Skip to content

Commit 9fe9fd5

Browse files
authored
http server semconv 1.23 updates (#208)
* update http server span names to match spec ("GET" or "GET <route>"), per https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0/docs/http/http-spans.md#name * adding http client/server span attributes * do not normalize hyphen to underscore for http request/response header key, per https://opentelemetry.io/blog/2023/http-conventions-declared-stable/#common-attributes-across-http-client-and-server-spans
1 parent 6044b4f commit 9fe9fd5

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/HttpInstrumentation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function register(CachedInstrumentation $instrumentation): void
2929
$request = ($params[0] instanceof Request) ? $params[0] : null;
3030
/** @psalm-suppress ArgumentTypeCoercion */
3131
$builder = $instrumentation->tracer()
32-
->spanBuilder(sprintf('HTTP %s', $request?->method() ?? 'unknown'))
32+
->spanBuilder(sprintf('%s', $request?->method() ?? 'unknown'))
3333
->setSpanKind(SpanKind::KIND_SERVER)
3434
->setAttribute(TraceAttributes::CODE_FUNCTION, $function)
3535
->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)

src/Watchers/ClientRequestWatcher.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public function register(Application $app): void
3636
$app['events']->listen(ResponseReceived::class, [$this, 'recordResponse']);
3737
}
3838

39+
/**
40+
* @psalm-suppress ArgumentTypeCoercion
41+
*/
3942
public function recordRequest(RequestSending $request): void
4043
{
4144
$parsedUrl = collect(parse_url($request->request->url()));
@@ -44,7 +47,7 @@ public function recordRequest(RequestSending $request): void
4447
if ($parsedUrl->has('query')) {
4548
$processedUrl .= '?' . $parsedUrl->get('query');
4649
}
47-
$span = $this->instrumentation->tracer()->spanBuilder('HTTP ' . $request->request->method())
50+
$span = $this->instrumentation->tracer()->spanBuilder($request->request->method())
4851
->setSpanKind(SpanKind::KIND_CLIENT)
4952
->setAttributes([
5053
TraceAttributes::HTTP_REQUEST_METHOD => $request->request->method(),

tests/Integration/LaravelInstrumentationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public function test_request_response(): void
5555
$this->assertEquals(200, $response->status());
5656
$this->assertCount(1, $this->storage);
5757
$span = $this->storage->offsetGet(0);
58-
$this->assertSame('HTTP GET', $span->getName());
58+
$this->assertSame('GET', $span->getName());
5959

6060
$response = Http::get('opentelemetry.io');
6161
$this->assertEquals(200, $response->status());
6262
$span = $this->storage->offsetGet(1);
63-
$this->assertSame('HTTP GET', $span->getName());
63+
$this->assertSame('GET', $span->getName());
6464
}
6565
public function test_cache_log_db(): void
6666
{
@@ -81,7 +81,7 @@ public function test_cache_log_db(): void
8181
$this->assertEquals(200, $response->status());
8282
$this->assertCount(2, $this->storage);
8383
$span = $this->storage->offsetGet(1);
84-
$this->assertSame('HTTP GET', $span->getName());
84+
$this->assertSame('GET', $span->getName());
8585
$this->assertSame('http://localhost/hello', $span->getAttributes()->get(TraceAttributes::URL_FULL));
8686
$this->assertCount(5, $span->getEvents());
8787
$this->assertSame('cache set', $span->getEvents()[0]->getName());

0 commit comments

Comments
 (0)