Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/API/Instrumentation/WithSpanHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could unify this with the span $name logic above:

$functionName = $class !== null ? $class . '::' . $function : $function;
$name = $span_args['name'] ?? $functionName;

->setAttribute('code.file.path', $filename)
->setAttribute('code.line.number', $lineno)
->setAttributes($attributes ?? [])
->startSpan();
$context = $span->storeInContext(Context::getCurrent());
Expand Down
7 changes: 3 additions & 4 deletions tests/Unit/API/Instrumentation/WithSpanHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down