diff --git a/src/API/Instrumentation/WithSpanHandler.php b/src/API/Instrumentation/WithSpanHandler.php index 979ebcd73..63718e469 100644 --- a/src/API/Instrumentation/WithSpanHandler.php +++ b/src/API/Instrumentation/WithSpanHandler.php @@ -21,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) { @@ -36,10 +36,9 @@ public static function pre(mixed $target, array $params, ?string $class, string ->tracer() ->spanBuilder($name) ->setSpanKind($kind) - ->setAttribute('code.function', $function) - ->setAttribute('code.namespace', $class) - ->setAttribute('code.filepath', $filename) - ->setAttribute('code.lineno', $lineno) + ->setAttribute('code.function.name', $class !== null ? $class . '::' . $function : $function) + ->setAttribute('code.file.path', $filename) + ->setAttribute('code.line.number', $lineno) ->setAttributes($attributes ?? []) ->startSpan(); $context = $span->storeInContext(Context::getCurrent()); 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()); }