Skip to content

Commit

Permalink
Merge pull request #2069 from DataDog/alex/fix/amqp-parameters-order
Browse files Browse the repository at this point in the history
Fix error stack in span's resource when a AMQP connection error occurs
  • Loading branch information
PROFeNoM committed Jun 8, 2023
2 parents cd678ea + 4bcf098 commit 2c0e51e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Integrations/Integrations/AMQP/AMQPIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ public function init()
$this->protocolVersion = "";

hook_method(
'PhpAmqpLib\Channel\AbstractChannel',
'PhpAmqpLib\Connection\AbstractConnection',
'__construct',
null,
function ($This) use ($integration) {
$integration->protocolVersion = $This::getProtocolVersion();
}
Expand Down Expand Up @@ -243,23 +242,23 @@ function (SpanData $span, $args, $retval, $exception) use ($integration) {
'PhpAmqpLib\Channel\AMQPChannel',
'basic_cancel_ok',
function (SpanData $span, $args, $retval, $exception) use ($integration) {
$integration->setGenericTags($span, 'basic.cancel_ok', 'server', $exception);
$integration->setGenericTags($span, 'basic.cancel_ok', 'server', null, $exception);
}
);

trace_method(
'PhpAmqpLib\Connection\AbstractConnection',
'connect',
function (SpanData $span, $args, $retval, $exception) use ($integration) {
$integration->setGenericTags($span, 'connect', 'client', $exception);
$integration->setGenericTags($span, 'connect', 'client', null, $exception);
}
);

trace_method(
'PhpAmqpLib\Connection\AbstractConnection',
'reconnect',
function (SpanData $span, $args, $retval, $exception) use ($integration) {
$integration->setGenericTags($span, 'reconnect', 'client', $exception);
$integration->setGenericTags($span, 'reconnect', 'client', null, $exception);
}
);

Expand Down
32 changes: 32 additions & 0 deletions tests/Integrations/AMQP/AMQPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,38 @@ protected function connectionToServer()
return new AMQPStreamConnection('rabbitmq_integration', 5672, 'guest', 'guest');
}

public function testConnectError()
{
$traces = $this->isolateTracer(function () {
try {
$connection = new AMQPStreamConnection('rabbitmq_integration', 5673, 'guest', 'guest'); // wrong port
$connection->close();
} catch (\Exception $e) {
// Ignore exception
}
});

$this->assertSpans($traces, [
SpanAssertion::build(
'amqp.connect',
'amqp',
'queue',
'connect'
)->setError(
'PhpAmqpLib\Exception\AMQPIOException',
'Connection refused',
true
)->withExactTags([
Tag::SPAN_KIND => 'client',
Tag::COMPONENT => 'amqp',
Tag::MQ_SYSTEM => 'rabbitmq',
Tag::MQ_DESTINATION_KIND => 'queue',
Tag::MQ_PROTOCOL => 'AMQP',
Tag::MQ_PROTOCOL_VERSION => AMQPChannel::getProtocolVersion(),
])
]);
}

public function testHelloWorld()
{
$receivedMessage = false;
Expand Down

0 comments on commit 2c0e51e

Please sign in to comment.