Skip to content

fix(laravel): fix trailing space in span name for unknown SQL operations in QueryWatcher#627

Merged
bobstrecansky merged 2 commits into
open-telemetry:mainfrom
zigzagdev:fix/laravel-query-watcher-unknown-operation-span-name
Jun 21, 2026
Merged

fix(laravel): fix trailing space in span name for unknown SQL operations in QueryWatcher#627
bobstrecansky merged 2 commits into
open-telemetry:mainfrom
zigzagdev:fix/laravel-query-watcher-unknown-operation-span-name

Conversation

@zigzagdev

Copy link
Copy Markdown
Contributor

Summary

Content

  • When a SQL statement starts with an unrecognised operation (e.g. PRAGMA, EXPLAIN, CREATE), $operationName was set to null, causing the span name to be built as 'sql ' . null = 'sql '(trailing space)
  • Since PHP 8.1, this also emits a deprecation notice for implicit null-to-string coercion.
  • Fixed by building the span name explicitly: 'sql <OPERATION>' for known operations, 'sql' for unknown ones.

What I have done

  • Built the span name explicitly to avoid null concatenation:

Before

$span = $this->instrumentation->tracer()->spanBuilder('sql ' . $operationName) // 'sql ' when null

After

$spanName = $operationName !== null ? 'sql ' . $operationName : 'sql';
$span = $this->instrumentation->tracer()->spanBuilder($spanName)

Test Results

php@33736e758e63:/usr/src/myapp/src/Instrumentation/Laravel$ vendor/bin/phpunit --filter test_unknown_sql_operation_span_name tests/Integration/LaravelInstrumentationTest.php
PHPUnit 9.6.34 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.34
Configuration: /usr/src/myapp/src/Instrumentation/Laravel/phpunit.xml.dist

.                                                                   1 / 1 (100%)

Time: 00:02.467, Memory: 24.00 MB

OK (1 test, 2 assertions)
php@33736e758e63:/usr/src/myapp/src/Instrumentation/Laravel$

@zigzagdev
zigzagdev requested a review from a team as a code owner June 21, 2026 07:35
@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.46%. Comparing base (ad7e675) to head (0e46610).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##               main     #627   +/-   ##
=========================================
  Coverage     80.45%   80.46%           
- Complexity     1668     1669    +1     
=========================================
  Files           116      116           
  Lines          6264     6265    +1     
=========================================
+ Hits           5040     5041    +1     
  Misses         1224     1224           
Flag Coverage Δ
Context/Swoole 0.00% <ø> (ø)
Exporter/Instana 49.80% <ø> (ø)
Instrumentation/AwsSdk 82.14% <ø> (ø)
Instrumentation/CakePHP 20.42% <ø> (ø)
Instrumentation/CodeIgniter 79.31% <ø> (ø)
Instrumentation/Curl 86.88% <ø> (ø)
Instrumentation/Doctrine 92.82% <ø> (ø)
Instrumentation/ExtAmqp 88.80% <ø> (ø)
Instrumentation/Guzzle 76.25% <ø> (ø)
Instrumentation/HttpAsyncClient 78.94% <ø> (ø)
Instrumentation/HttpConfig 28.76% <ø> (ø)
Instrumentation/IO 0.00% <ø> (ø)
Instrumentation/Laravel 76.37% <100.00%> (+0.02%) ⬆️
Instrumentation/MongoDB 76.84% <ø> (ø)
Instrumentation/MySqli 93.39% <ø> (ø)
Instrumentation/OpenAIPHP 86.71% <ø> (ø)
Instrumentation/PostgreSql 91.36% <ø> (ø)
Instrumentation/Psr14 77.41% <ø> (ø)
Instrumentation/Psr15 89.74% <ø> (ø)
Instrumentation/Psr16 97.43% <ø> (ø)
Instrumentation/Psr18 79.41% <ø> (ø)
Instrumentation/Psr6 97.56% <ø> (ø)
Instrumentation/Session 94.28% <ø> (ø)
Instrumentation/Slim 84.21% <ø> (ø)
Propagation/CloudTrace 90.69% <ø> (ø)
Propagation/Instana 98.07% <ø> (ø)
Propagation/ServerTiming 94.73% <ø> (ø)
Propagation/TraceResponse 94.73% <ø> (ø)
ResourceDetectors/Azure 91.66% <ø> (ø)
ResourceDetectors/DigitalOcean 100.00% <ø> (ø)
Sampler/Xray 78.38% <ø> (ø)
Shims/OpenTracing 92.99% <ø> (ø)
SqlCommenter 95.58% <ø> (ø)
Utils/Test 87.79% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...trumentation/Laravel/src/Watchers/QueryWatcher.php 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ad7e675...0e46610. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bobstrecansky
bobstrecansky merged commit 1761833 into open-telemetry:main Jun 21, 2026
131 of 175 checks passed
@zigzagdev
zigzagdev deleted the fix/laravel-query-watcher-unknown-operation-span-name branch July 3, 2026 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants