Skip to content

Commit

Permalink
Merge branch 'master' into laravel-11
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric authored Mar 8, 2024
2 parents d786d43 + 1b7fc23 commit 9b8d4ee
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
26 changes: 20 additions & 6 deletions src/Sentry/Laravel/Console/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,27 @@ public function handle(): int
return 1;
}

try {
$clientBuilder = ClientBuilder::create([
'dsn' => $dsn,
'release' => $laravelClient === null ? null : $laravelClient->getOptions()->getRelease(),
'environment' => $laravelClient === null ? null : $laravelClient->getOptions()->getEnvironment(),
'traces_sample_rate' => 1.0,
$options = [
'dsn' => $dsn,
'traces_sample_rate' => 1.0,
];

if ($laravelClient !== null) {
$options = array_merge($options, [
'release' => $laravelClient->getOptions()->getRelease(),
'environment' => $laravelClient->getOptions()->getEnvironment(),
'http_client' => $laravelClient->getOptions()->getHttpClient(),
'http_proxy' => $laravelClient->getOptions()->getHttpProxy(),
'http_proxy_authentication' => $laravelClient->getOptions()->getHttpProxyAuthentication(),
'http_connect_timeout' => $laravelClient->getOptions()->getHttpConnectTimeout(),
'http_timeout' => $laravelClient->getOptions()->getHttpTimeout(),
'http_ssl_verify_peer' => $laravelClient->getOptions()->getHttpSslVerifyPeer(),
'http_compression' => $laravelClient->getOptions()->isHttpCompressionEnabled(),
]);
}

try {
$clientBuilder = ClientBuilder::create($options);
} catch (Exception $e) {
$this->error($e->getMessage());

Expand Down
30 changes: 21 additions & 9 deletions src/Sentry/Laravel/Features/QueueIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class QueueIntegration extends Feature
pushScope as private pushScopeTrait;
}

private const QUEUE_SPAN_OP_QUEUE_PUBLISH = 'queue.publish';

private const QUEUE_PAYLOAD_BAGGAGE_DATA = 'sentry_baggage_data';
private const QUEUE_PAYLOAD_TRACE_PARENT_DATA = 'sentry_trace_parent_data';

Expand All @@ -57,7 +59,22 @@ public function onBoot(Dispatcher $events): void
$events->listen(JobExceptionOccurred::class, [$this, 'handleJobExceptionOccurredQueueEvent']);

if ($this->isTracingFeatureEnabled('queue_jobs') || $this->isTracingFeatureEnabled('queue_job_transactions')) {
Queue::createPayloadUsing(static function (?string $connection, ?string $queue, ?array $payload): ?array {
Queue::createPayloadUsing(function (?string $connection, ?string $queue, ?array $payload): ?array {
$parentSpan = SentrySdk::getCurrentHub()->getSpan();

if ($parentSpan !== null) {
$context = (new SpanContext)
->setOp(self::QUEUE_SPAN_OP_QUEUE_PUBLISH)
->setData([
'messaging.system' => 'laravel',
'messaging.destination.name' => $queue,
'messaging.destination.connection' => $connection,
])
->setDescription($queue);

$this->pushSpan($parentSpan->startChild($context));
}

if ($payload !== null) {
$payload[self::QUEUE_PAYLOAD_BAGGAGE_DATA] = getBaggage();
$payload[self::QUEUE_PAYLOAD_TRACE_PARENT_DATA] = getTraceparent();
Expand All @@ -70,10 +87,10 @@ public function onBoot(Dispatcher $events): void

public function handleJobQueueingEvent(JobQueueing $event): void
{
$parentSpan = SentrySdk::getCurrentHub()->getSpan();
$currentSpan = SentrySdk::getCurrentHub()->getSpan();

// If there is no tracing span active there is no need to handle the event
if ($parentSpan === null) {
if ($currentSpan === null || $currentSpan->getOp() !== self::QUEUE_SPAN_OP_QUEUE_PUBLISH) {
return;
}

Expand All @@ -85,16 +102,11 @@ public function handleJobQueueingEvent(JobQueueing $event): void
$jobName = get_class($jobName);
}

$context = (new SpanContext)
->setOp('queue.publish')
$currentSpan
->setData([
'messaging.system' => 'laravel',
'messaging.laravel.job' => $jobName,
'messaging.destination.connection' => $event->connectionName,
])
->setDescription($jobName);

$this->pushSpan($parentSpan->startChild($context));
}

public function handleJobQueuedEvent(JobQueued $event): void
Expand Down

0 comments on commit 9b8d4ee

Please sign in to comment.