Skip to content

Commit 6232409

Browse files
committed
Improve documentation for X-Ray and Symfony Messenger
1 parent 4272eeb commit 6232409

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

website/src/pages/xray/docs.mdx

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,6 @@ If you are using Symfony, the package automatically integrates with the Symfony
138138
To trace Symfony Messenger jobs across multiple services, you need to trace the AWS SDK client used by Symfony Messenger:
139139

140140
```yaml
141-
bref.messenger.sqs_client:
142-
class: AsyncAws\Sqs\SqsClient
143-
public: true
144-
arguments:
145-
$httpClient: '@Bref\Apm\XRay\AsyncAws\TracedAsyncAwsHttpClient'
146-
147141
bref.messenger.sns_client:
148142
class: AsyncAws\Sns\SnsClient
149143
public: true
@@ -164,6 +158,42 @@ async_aws:
164158
http_client: 'Bref\Apm\XRay\AsyncAws\TracedAsyncAwsHttpClient'
165159
```
166160

161+
While the configuration above works for SNS and EventBridge, it is unfortunately not as simple for SQS. The SQS client is created inside a Symfony Messenger class (`AmazonSqsTransportFactory`) in a non-extensible way. To work around that, you can create a custom transport factory that overrides the native one from Symfony Messenger and make it use the `TracedAsyncAwsHttpClient` from Bref. Here is an example of class you can create in your Symfony application:
162+
163+
```php
164+
<?php declare(strict_types=1);
165+
166+
namespace App;
167+
168+
use Bref\Apm\XRay\AsyncAws\TracedAsyncAwsHttpClient;
169+
use Psr\Log\LoggerInterface;
170+
use Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\AmazonSqsTransport;
171+
use Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\Connection;
172+
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
173+
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
174+
use Symfony\Component\Messenger\Transport\TransportInterface;
175+
176+
class AmazonSqsTransportFactory implements TransportFactoryInterface
177+
{
178+
public function __construct(
179+
private ?LoggerInterface $logger = null,
180+
) {
181+
}
182+
183+
public function createTransport(#[\SensitiveParameter] string $dsn, array $options, SerializerInterface $serializer): TransportInterface
184+
{
185+
unset($options['transport_name']);
186+
187+
return new AmazonSqsTransport(Connection::fromDsn($dsn, $options, new TracedAsyncAwsHttpClient, $this->logger), $serializer);
188+
}
189+
190+
public function supports(#[\SensitiveParameter] string $dsn, array $options): bool
191+
{
192+
return str_starts_with($dsn, 'sqs://') || preg_match('#^https://sqs\.[\w\-]+\.amazonaws\.com/.+#', $dsn);
193+
}
194+
}
195+
```
196+
167197
### Cold starts tracing
168198

169199
Cold starts are automatically traced when using Laravel or Symfony. There is nothing additional to set up.

0 commit comments

Comments
 (0)