-
Notifications
You must be signed in to change notification settings - Fork 149
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
Add php-amqplib integration #1996
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great, thanks. A quick review from my phone. I'll have another look on Monday
$integration->setOptionalMessageTags($span, $message); | ||
|
||
// Try to extract propagated context values from headers | ||
$integration->extract($message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extractContext
may be a better name
'prehook' => function (SpanData $span, $args) use ($integration) { | ||
/** @var AMQPMessage $message */ | ||
$message = $args[0]; | ||
$integration->inject($message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
injectContext
/** @var string $routing_key */ | ||
$routingKey = $args[2] ?? ''; | ||
|
||
$exchangeDisplayName = empty($exchange) ? '<default>' : $exchange; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we factorize duplicated code?
Note: I passed it locally, and I want to see if it will run fine on the CI as well
Ok, applied these changes. What's more, I also unmarked as 'skipped' the distributed tracing test so it can run on the CI (where it passes). |
// If present, set the traceid of the current span to x-datadog-trace-id | ||
if (isset($headers['x-datadog-trace-id'])) { | ||
$traceId = $headers['x-datadog-trace-id']; | ||
} else { | ||
return; | ||
} | ||
|
||
// If present, set the spanid of the current span to x-datadog-parent-id | ||
if (isset($headers['x-datadog-parent-id'])) { | ||
$parentId = $headers['x-datadog-parent-id']; | ||
} else { | ||
return; | ||
} | ||
|
||
// If present, set the sampling priority of the current span to x-datadog-sampling-priority | ||
$priority = $headers['x-datadog-sampling-priority'] ?? null; | ||
\DDTrace\set_priority_sampling($priority); | ||
|
||
// If present, set the origin of the current span to x-datadog-origin | ||
$origin = $headers['x-datadog-origin'] ?? null; | ||
|
||
\DDTrace\set_distributed_tracing_context($traceId, $parentId, $origin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// If present, set the traceid of the current span to x-datadog-trace-id | |
if (isset($headers['x-datadog-trace-id'])) { | |
$traceId = $headers['x-datadog-trace-id']; | |
} else { | |
return; | |
} | |
// If present, set the spanid of the current span to x-datadog-parent-id | |
if (isset($headers['x-datadog-parent-id'])) { | |
$parentId = $headers['x-datadog-parent-id']; | |
} else { | |
return; | |
} | |
// If present, set the sampling priority of the current span to x-datadog-sampling-priority | |
$priority = $headers['x-datadog-sampling-priority'] ?? null; | |
\DDTrace\set_priority_sampling($priority); | |
// If present, set the origin of the current span to x-datadog-origin | |
$origin = $headers['x-datadog-origin'] ?? null; | |
\DDTrace\set_distributed_tracing_context($traceId, $parentId, $origin); | |
\DDTrace\consume_distributed_tracing_headers($headers); |
(Merge master into this first.)
} | ||
} | ||
|
||
public function injectContext(AMQPMessage $message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a check for DD_DISTRIBUTED_TRACING
config first.
public function setGenericTags(SpanData $span, string $name, string $spanKind, $exception = null) | ||
{ | ||
$span->name = $name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function setGenericTags(SpanData $span, string $name, string $spanKind, $exception = null) | |
{ | |
$span->name = $name; | |
public function setGenericTags(SpanData $span, string $name, string $spanKind, string $resourceDetail = null, $exception = null) | |
{ | |
$span->name = "amqp.$name"; | |
$span->resource = "$name" . ($resourceDetail === null ? "" : " $resourceDetail"); |
Wouldn't that reduce redundancy? Given that name and resource always share that part.
$exchangeDisplayName = empty($exchange) ? '<default>' : $exchange; | ||
$routingKeyDisplayName = empty($routingKey) | ||
? '<all>' | ||
: (str_starts_with($routingKey, 'amq.gen-') | ||
? '<generated>' | ||
: $routingKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$exchangeDisplayName = empty($exchange) ? '<default>' : $exchange; | |
$routingKeyDisplayName = empty($routingKey) | |
? '<all>' | |
: (str_starts_with($routingKey, 'amq.gen-') | |
? '<generated>' | |
: $routingKey); | |
$exchangeDisplayName = $this->formatExchangeName($exchange); | |
$routingKeyDisplayName = $this->formatRoutingKey($routingKey); |
: (str_starts_with($routingKey, 'amq.gen-') | ||
? '<generated>' | ||
: $routingKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: (str_starts_with($routingKey, 'amq.gen-') | |
? '<generated>' | |
: $routingKey); | |
: $this->formatQueueName($routingKey); |
# Conflicts: # ext/ddtrace.stub.php
public function testDistributedTracing() | ||
{ | ||
// Note: This test is extremely flaky, locally at least. It will eventually pass with some tries... | ||
// Reason: We may parse the traces from dumped data BEFORE the traces are flushed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate? Also \DDTrace\Tests\Common\TracerTestTrait::resetRequestDumper()
is a thing, if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me it was never flaky, so, let's ship it.
Description
Add a php-amqplib integration (#1840).
Methods Traced
AMQPChannel
PhpAmqpLib\Channel\AMQPChannel::basic_get
PhpAmqpLib\Channel\AMQPChannel::basic_deliver
PhpAmqpLib\Channel\AMQPChannel::basic_publish
PhpAmqpLib\Channel\AMQPChannel::basic_cancel
PhpAmqpLib\Channel\AMQPChannel::basic_cancel_ok
PhpAmqpLib\Channel\AMQPChannel::basic_consume
PhpAmqpLib\Channel\AMQPChannel::basic_consume_ok
PhpAmqpLib\Channel\AMQPChannel::basic_ack
PhpAmqpLib\Channel\AMQPChannel::basic_nack
PhpAmqpLib\Channel\AMQPChannel::exchange_declare
PhpAmqpLib\Channel\AMQPChannel::queue_declare
PhpAmqpLib\Channel\AMQPChannel::queue_bind
AbstractConnection
PhpAmqpLib\Connection\AbstractConnection::connect
PhpAmqpLib\Connection\AbstractConnection::reconnect
Readiness checklist
Reviewer checklist