From aeb9734a13a374bdbda26746a89d393651eae436 Mon Sep 17 00:00:00 2001 From: mdomansky Date: Wed, 25 Mar 2026 17:23:32 +0300 Subject: [PATCH 1/5] Remove hardcode, add constants --- src/API/Instrumentation/WithSpanHandler.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/API/Instrumentation/WithSpanHandler.php b/src/API/Instrumentation/WithSpanHandler.php index 979ebcd73..db0969e35 100644 --- a/src/API/Instrumentation/WithSpanHandler.php +++ b/src/API/Instrumentation/WithSpanHandler.php @@ -8,6 +8,7 @@ use OpenTelemetry\API\Trace\SpanKind; use OpenTelemetry\API\Trace\StatusCode; use OpenTelemetry\Context\Context; +use OpenTelemetry\SemConv\Attributes\CodeAttributes; use Throwable; /** @@ -36,10 +37,10 @@ public static function pre(mixed $target, array $params, ?string $class, string ->tracer() ->spanBuilder($name) ->setSpanKind($kind) - ->setAttribute('code.function', $function) + ->setAttribute(CodeAttributes::CODE_FUNCTION_NAME, $function) ->setAttribute('code.namespace', $class) - ->setAttribute('code.filepath', $filename) - ->setAttribute('code.lineno', $lineno) + ->setAttribute(CodeAttributes::CODE_FILE_PATH, $filename) + ->setAttribute(CodeAttributes::CODE_LINE_NUMBER, $lineno) ->setAttributes($attributes ?? []) ->startSpan(); $context = $span->storeInContext(Context::getCurrent()); From 4fea6903ce27ddf84307a10b2ee44eefe24bd531 Mon Sep 17 00:00:00 2001 From: mdomansky Date: Thu, 9 Apr 2026 16:01:33 +0300 Subject: [PATCH 2/5] update otel schema to 1.40 and update span attributes within the schema --- src/API/Instrumentation/WithSpanHandler.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/API/Instrumentation/WithSpanHandler.php b/src/API/Instrumentation/WithSpanHandler.php index db0969e35..c3fc2afd4 100644 --- a/src/API/Instrumentation/WithSpanHandler.php +++ b/src/API/Instrumentation/WithSpanHandler.php @@ -8,7 +8,6 @@ use OpenTelemetry\API\Trace\SpanKind; use OpenTelemetry\API\Trace\StatusCode; use OpenTelemetry\Context\Context; -use OpenTelemetry\SemConv\Attributes\CodeAttributes; use Throwable; /** @@ -22,7 +21,7 @@ class WithSpanHandler public static function pre(mixed $target, array $params, ?string $class, string $function, ?string $filename, ?int $lineno, ?array $span_args = [], ?array $attributes = []): void { static $instrumentation; - $instrumentation ??= new CachedInstrumentation(name: 'io.opentelemetry.php.with-span', schemaUrl: 'https://opentelemetry.io/schemas/1.25.0'); + $instrumentation ??= new CachedInstrumentation(name: 'io.opentelemetry.php.with-span', schemaUrl: 'https://opentelemetry.io/schemas/1.40.0'); $name = $span_args['name'] ?? null; if ($name === null) { @@ -37,10 +36,11 @@ public static function pre(mixed $target, array $params, ?string $class, string ->tracer() ->spanBuilder($name) ->setSpanKind($kind) - ->setAttribute(CodeAttributes::CODE_FUNCTION_NAME, $function) + ->setAttribute('code.function.name', $function) ->setAttribute('code.namespace', $class) - ->setAttribute(CodeAttributes::CODE_FILE_PATH, $filename) - ->setAttribute(CodeAttributes::CODE_LINE_NUMBER, $lineno) + ->setAttribute('code.file.path', $filename) + ->setAttribute('code.line.number', $lineno) + ->setAttribute('code.column.number', $lineno) ->setAttributes($attributes ?? []) ->startSpan(); $context = $span->storeInContext(Context::getCurrent()); From 7400f5f0f0713e8adc768d0a56fa732feabaca55 Mon Sep 17 00:00:00 2001 From: Mike Domansky <54438138+mdomansky@users.noreply.github.com> Date: Thu, 9 Apr 2026 16:34:19 +0300 Subject: [PATCH 3/5] Update src/API/Instrumentation/WithSpanHandler.php Co-authored-by: Tobias Bachert --- src/API/Instrumentation/WithSpanHandler.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/API/Instrumentation/WithSpanHandler.php b/src/API/Instrumentation/WithSpanHandler.php index c3fc2afd4..ba6d6fb29 100644 --- a/src/API/Instrumentation/WithSpanHandler.php +++ b/src/API/Instrumentation/WithSpanHandler.php @@ -36,8 +36,7 @@ public static function pre(mixed $target, array $params, ?string $class, string ->tracer() ->spanBuilder($name) ->setSpanKind($kind) - ->setAttribute('code.function.name', $function) - ->setAttribute('code.namespace', $class) + ->setAttribute('code.function.name', $class !== null ? $class . '::' . $function : $function) ->setAttribute('code.file.path', $filename) ->setAttribute('code.line.number', $lineno) ->setAttribute('code.column.number', $lineno) From 9efbcfb4f3fc5de833174d03bc1ef72b388e0c41 Mon Sep 17 00:00:00 2001 From: mdomansky Date: Mon, 13 Apr 2026 14:42:32 +0300 Subject: [PATCH 4/5] update otel schema to 1.40 and update span attributes within the schema --- src/API/Instrumentation/WithSpanHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/API/Instrumentation/WithSpanHandler.php b/src/API/Instrumentation/WithSpanHandler.php index ba6d6fb29..63718e469 100644 --- a/src/API/Instrumentation/WithSpanHandler.php +++ b/src/API/Instrumentation/WithSpanHandler.php @@ -39,7 +39,6 @@ public static function pre(mixed $target, array $params, ?string $class, string ->setAttribute('code.function.name', $class !== null ? $class . '::' . $function : $function) ->setAttribute('code.file.path', $filename) ->setAttribute('code.line.number', $lineno) - ->setAttribute('code.column.number', $lineno) ->setAttributes($attributes ?? []) ->startSpan(); $context = $span->storeInContext(Context::getCurrent()); From b665a5a88eb7fec5aebb63c711a9a36e79468ee6 Mon Sep 17 00:00:00 2001 From: mdomansky Date: Wed, 22 Apr 2026 15:46:51 +0300 Subject: [PATCH 5/5] update tests --- tests/Unit/API/Instrumentation/WithSpanHandlerTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Unit/API/Instrumentation/WithSpanHandlerTest.php b/tests/Unit/API/Instrumentation/WithSpanHandlerTest.php index a6cfd5ca0..d7cd17f1e 100644 --- a/tests/Unit/API/Instrumentation/WithSpanHandlerTest.php +++ b/tests/Unit/API/Instrumentation/WithSpanHandlerTest.php @@ -69,10 +69,9 @@ public function test_creates_span_with_all_values(): void $this->assertSame($name, $span->getName()); $this->assertSame($kind, $span->getKind()); $this->assertSame([ - 'code.function' => 'some_function', - 'code.namespace' => 'My\Class', - 'code.filepath' => 'a_file.php', - 'code.lineno' => 99, + 'code.function.name' => 'My\Class::some_function', + 'code.file.path' => 'a_file.php', + 'code.line.number' => 99, 'foo' => 'bar', ], $span->getAttributes()->toArray()); }