Skip to content

add Doctrine span links and more SemConv #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

brettmc
Copy link
Collaborator

@brettmc brettmc commented May 21, 2025

  • track doctrine prepared statements, and when they are executed create a span link back to the span that prepared.
  • add some more SemConv to db spans, particularly db.operation.name
  • align span names with how PDO does it (eg Doctrine::prepare)

Fixes: open-telemetry/opentelemetry-php#1578

track doctrine prepared statements, and when they are executed create a span link back to the span that
prepared.
add some more SemConv to db spans, particularly db.operation.name
align span names with how PDO does it (eg Doctrine::prepare)
@brettmc brettmc requested a review from a team as a code owner May 21, 2025 06:48
Copy link

codecov bot commented May 21, 2025

Codecov Report

Attention: Patch coverage is 93.24324% with 5 lines in your changes missing coverage. Please review.

Project coverage is 83.16%. Comparing base (3f003f3) to head (b7e4f9b).
Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
...nstrumentation/Doctrine/src/AttributesResolver.php 90.90% 2 Missing ⚠️
...c/Instrumentation/Doctrine/src/DoctrineTracker.php 66.66% 2 Missing ⚠️
...mentation/Doctrine/src/DoctrineInstrumentation.php 97.82% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #374      +/-   ##
============================================
+ Coverage     81.68%   83.16%   +1.47%     
- Complexity     1741     1957     +216     
============================================
  Files           133      143      +10     
  Lines          7307     8190     +883     
============================================
+ Hits           5969     6811     +842     
- Misses         1338     1379      +41     
Flag Coverage Δ
Aws 92.59% <ø> (ø)
Context/Swoole 0.00% <ø> (ø)
Instrumentation/AwsSdk 81.13% <ø> (?)
Instrumentation/CakePHP 20.40% <ø> (ø)
Instrumentation/CodeIgniter 73.55% <ø> (ø)
Instrumentation/Curl 90.42% <ø> (?)
Instrumentation/Doctrine 91.98% <93.24%> (-0.75%) ⬇️
Instrumentation/ExtAmqp 88.48% <ø> (ø)
Instrumentation/ExtRdKafka 86.11% <ø> (ø)
Instrumentation/Guzzle 75.58% <ø> (+6.44%) ⬆️
Instrumentation/HttpAsyncClient 78.04% <ø> (ø)
Instrumentation/IO 70.68% <ø> (ø)
Instrumentation/Laravel 66.82% <ø> (+2.90%) ⬆️
Instrumentation/MongoDB 74.28% <ø> (ø)
Instrumentation/MySqli 95.81% <ø> (ø)
Instrumentation/OpenAIPHP 87.21% <ø> (?)
Instrumentation/PDO 94.21% <ø> (ø)
Instrumentation/Psr14 76.47% <ø> (ø)
Instrumentation/Psr15 89.15% <ø> (ø)
Instrumentation/Psr16 97.50% <ø> (ø)
Instrumentation/Psr18 77.46% <ø> (ø)
Instrumentation/Psr3 67.01% <ø> (ø)
Instrumentation/Psr6 97.61% <ø> (ø)
Instrumentation/ReactPHP 99.45% <ø> (?)
Instrumentation/Slim 86.11% <ø> (ø)
Instrumentation/Symfony 84.74% <ø> (ø)
Instrumentation/Yii 77.50% <ø> (ø)
Logs/Monolog 100.00% <ø> (ø)
Propagation/Instana 98.11% <ø> (ø)
Propagation/ServerTiming 100.00% <ø> (?)
Propagation/TraceResponse 100.00% <ø> (ø)
ResourceDetectors/Azure 91.66% <ø> (ø)
ResourceDetectors/Container 93.02% <ø> (ø)
ResourceDetectors/DigitalOcean 100.00% <ø> (?)
Sampler/RuleBased 33.51% <ø> (ø)
Shims/OpenTracing 92.45% <ø> (ø)
Symfony 87.81% <ø> (ø)
Utils/Test 87.53% <ø> (ø)

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

Files with missing lines Coverage Δ
...mentation/Doctrine/src/DoctrineInstrumentation.php 96.77% <97.82%> (+0.02%) ⬆️
...nstrumentation/Doctrine/src/AttributesResolver.php 80.39% <90.90%> (-0.57%) ⬇️
...c/Instrumentation/Doctrine/src/DoctrineTracker.php 66.66% <66.66%> (ø)

... and 19 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

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

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

@brettmc
Copy link
Collaborator Author

brettmc commented Jun 13, 2025

@open-telemetry/php-approvers ping!


public function trackStatement(Statement $statement, SpanContextInterface $context): void
{
$this->statementToSpanContextMap[$statement] = WeakReference::create($context);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it will return null after the ::prepare() span is flushed and exported? Should be testable by something like:

$stmt = $connection->prepare('SELECT * FROM `technology` WHERE name = :name');
$this->storage->exchangeArray([]);

$stmt->bindValue('name', 'PHP');
$stmt->executeQuery();
$execute = $this->storage->offsetGet(0);
$this->assertCount(1, $execute->getLinks());
Suggested change
$this->statementToSpanContextMap[$statement] = WeakReference::create($context);
$this->statementToSpanContextMap[$statement] = $context;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you're right. I've used SplObjectStorage now, and added a test. It doesn't look like prepared statements can be destroyed easily, so I guess holding on to span context forever is okay...

Copy link
Contributor

Choose a reason for hiding this comment

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

Should revert the WeakMap->SplObjectStorage change to avoid leaking memory; only the usage of WeakReference was problematic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reverted to WeakMap

brettmc added 2 commits June 17, 2025 17:35
- tidy constructor
- do not use a WeakMap to track prepared statements, as the SpanContext is lost when prepare span flushed/exported
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.

[opentelemetry-php-contrib] Doctrine connection spans not appearing in New Relic
3 participants