Skip to content

Commit e7be267

Browse files
committed
Move tracing to its own main directory and apply comments review
1 parent 6aa45ad commit e7be267

File tree

8 files changed

+39
-37
lines changed

8 files changed

+39
-37
lines changed

.github/workflows/static-analysis.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ jobs:
2323
- name: Install dependencies
2424
run: composer update --no-progress --no-interaction --prefer-dist
2525

26-
- name: Install suggested packages
27-
run: composer suggests sentry/sentry-symfony --list | xargs -i composer require {}
28-
2926
- name: Run script
3027
run: composer phpcs
3128

@@ -42,9 +39,6 @@ jobs:
4239
- name: Install dependencies
4340
run: composer update --no-progress --no-interaction --prefer-dist
4441

45-
- name: Install suggested packages
46-
run: composer suggests sentry/sentry-symfony --list | xargs -i composer require {}
47-
4842
- name: Run script
4943
run: composer phpstan
5044

@@ -61,8 +55,5 @@ jobs:
6155
- name: Install dependencies
6256
run: composer update --no-progress --no-interaction --prefer-dist
6357

64-
- name: Install suggested packages
65-
run: composer suggests sentry/sentry-symfony --list | xargs -i composer require {}
66-
6758
- name: Run script
6859
run: composer psalm

.github/workflows/tests.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ jobs:
5858
- run: composer remove --dev symfony/messenger --no-update
5959
if: matrix.symfony_constraint == '3.4.*' || matrix.composer_option == '--prefer-lowest'
6060
- run: composer update --no-progress --ansi ${{ matrix.composer_option }}
61-
- run: composer suggests sentry/sentry-symfony --list | xargs -i composer require {}
6261
- run: composer require sentry/sentry dev-develop
6362
if: matrix.sentry_constraint == 'dev-develop'
6463
- run: vendor/bin/phpunit --coverage-clover=coverage.xml

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"symfony/security-core": "^3.4.43||^4.4.11||^5.0.11"
3333
},
3434
"require-dev": {
35+
"doctrine/dbal": "^2.0||^3.0",
3536
"friendsofphp/php-cs-fixer": "^2.17",
3637
"jangregor/phpstan-prophecy": "^0.8",
3738
"monolog/monolog": "^1.3||^2.0",
@@ -52,7 +53,7 @@
5253
},
5354
"suggest": {
5455
"monolog/monolog": "Allow sending log messages to Sentry by using the included Monolog handler.",
55-
"doctrine/dbal": "Trace DBAL queries with Sentry Transactions by using the included DbalListener"
56+
"doctrine/dbal": "Allow distributed tracing of SQL queries using Sentry."
5657
},
5758
"autoload": {
5859
"files": [

src/DependencyInjection/Compiler/ConnectDbalQueryListenerPass.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,31 @@
44

55
namespace Sentry\SentryBundle\DependencyInjection\Compiler;
66

7-
use Sentry\SentryBundle\EventListener\Tracing\DbalListener;
7+
use Sentry\SentryBundle\Tracing\DbalSqlTracingLogger;
88
use Sentry\State\HubInterface;
99
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1010
use Symfony\Component\DependencyInjection\ContainerBuilder;
1111
use Symfony\Component\DependencyInjection\Definition;
1212

13-
class ConnectDbalQueryListenerPass implements CompilerPassInterface
13+
final class ConnectDbalQueryListenerPass implements CompilerPassInterface
1414
{
1515
/**
16+
* {@inheritdoc}
17+
*
1618
* @return void
1719
*/
1820
public function process(ContainerBuilder $container)
1921
{
2022
$config = $container->getExtensionConfig('sentry');
2123

22-
$registerDbalListener = isset($config[0]['register_dbal_listener'])
23-
? $config[0]['register_dbal_listener']
24+
$dbalTracingEnabled = isset($config[0]['tracing']['dbal_tracing'])
25+
? $config[0]['tracing']['dbal_tracing']
2426
: false;
2527

26-
if ($registerDbalListener && $container->hasDefinition('doctrine.dbal.logger')) {
28+
if ($dbalTracingEnabled && $container->hasDefinition('doctrine.dbal.logger')) {
2729
$container->setDefinition(
2830
'doctrine.dbal.logger',
29-
new Definition(DbalListener::class, [$container->getDefinition(HubInterface::class)])
31+
new Definition(DbalSqlTracingLogger::class, [$container->getDefinition(HubInterface::class)])
3032
);
3133
}
3234
}

src/DependencyInjection/Configuration.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ public function getConfigTreeBuilder(): TreeBuilder
3737
->end()
3838
->end()
3939
->booleanNode('register_error_listener')->defaultTrue()->end()
40-
->booleanNode('register_dbal_listener')->defaultFalse()->end()
40+
->arrayNode('tracing')
41+
->addDefaultsIfNotSet()
42+
->children()
43+
->booleanNode('dbal_tracing')->defaultFalse()->end()
44+
->end()
45+
->end()
4146
->arrayNode('options')
4247
->addDefaultsIfNotSet()
4348
->fixXmlConfig('integration')

src/EventListener/Tracing/DbalListener.php renamed to src/Tracing/DbalSqlTracingLogger.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,25 @@
22

33
declare(strict_types=1);
44

5-
namespace Sentry\SentryBundle\EventListener\Tracing;
5+
namespace Sentry\SentryBundle\Tracing;
66

77
use Doctrine\DBAL\Logging\SQLLogger;
88
use Sentry\State\HubInterface;
99
use Sentry\Tracing\Span;
1010
use Sentry\Tracing\SpanContext;
1111
use Sentry\Tracing\Transaction;
1212

13-
/**
14-
* Getting the logger, tied into dbal seems extremely hard. Cheating the system a bit by putting it in between the
15-
* debug stack logger.
16-
*/
17-
final class DbalListener implements SQLLogger
13+
final class DbalSqlTracingLogger implements SQLLogger
1814
{
1915
/**
2016
* @var HubInterface The current hub
2117
*/
2218
private $hub;
2319

2420
/**
25-
* @var Span
21+
* @var Span The span tracing the execution of a query
2622
*/
27-
private $querySpan;
23+
private $span;
2824

2925
/**
3026
* @param HubInterface $hub The current hub
@@ -35,7 +31,7 @@ public function __construct(HubInterface $hub)
3531
}
3632

3733
/**
38-
* @param string $sql
34+
* {@inheritdoc}
3935
*/
4036
public function startQuery($sql, ?array $params = null, ?array $types = null)
4137
{
@@ -46,18 +42,24 @@ public function startQuery($sql, ?array $params = null, ?array $types = null)
4642
}
4743

4844
$spanContext = new SpanContext();
49-
$spanContext->setOp('doctrine.query');
45+
$spanContext->setOp('db.query');
5046
$spanContext->setDescription($sql);
47+
$spanContext->setData([
48+
'db.system' => 'doctrine',
49+
]);
5150

52-
$this->querySpan = $transaction->startChild($spanContext);
51+
$this->span = $transaction->startChild($spanContext);
5352
}
5453

54+
/**
55+
* {@inheritdoc}
56+
*/
5557
public function stopQuery()
5658
{
57-
if (!$this->querySpan instanceof Span) {
59+
if (null === $this->span) {
5860
return;
5961
}
6062

61-
$this->querySpan->finish();
63+
$this->span->finish();
6264
}
6365
}

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public function testProcessConfigurationWithDefaultConfiguration(): void
1717
{
1818
$expectedBundleDefaultConfig = [
1919
'register_error_listener' => true,
20-
'register_dbal_listener' => false,
20+
'tracing' => [
21+
'dbal_tracing' => false,
22+
],
2123
'options' => [
2224
'integrations' => [],
2325
'prefixes' => [],

tests/EventListener/Tracing/DbalListenerTest.php renamed to tests/Tracing/DbalSqlTracingLoggerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22

33
declare(strict_types=1);
44

5-
namespace Sentry\SentryBundle\Tests\EventListener\Tracing;
5+
namespace Sentry\SentryBundle\Tests\Tracing;
66

77
use PHPUnit\Framework\MockObject\MockObject;
88
use PHPUnit\Framework\TestCase;
9-
use Sentry\SentryBundle\EventListener\Tracing\DbalListener;
9+
use Sentry\SentryBundle\Tracing\DbalSqlTracingLogger;
1010
use Sentry\State\HubInterface;
1111
use Sentry\Tracing\Transaction;
1212
use Sentry\Tracing\TransactionContext;
1313

14-
final class DbalListenerTest extends TestCase
14+
final class DbalSqlTracingLoggerTest extends TestCase
1515
{
1616
/**
1717
* @var MockObject&HubInterface
1818
*/
1919
private $hub;
2020

2121
/**
22-
* @var DbalListener
22+
* @var \Sentry\SentryBundle\Tracing\DbalSqlTracingLogger
2323
*/
2424
private $listener;
2525

2626
protected function setUp(): void
2727
{
2828
$this->hub = $this->createMock(HubInterface::class);
29-
$this->listener = new DbalListener($this->hub);
29+
$this->listener = new DbalSqlTracingLogger($this->hub);
3030
}
3131

3232
public function testThatDbalStartQueryIgnoresTracingWhenTransactionIsNotStarted(): void

0 commit comments

Comments
 (0)