Skip to content

Commit

Permalink
ref: Add tracing.http_client_requests option (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Jan 31, 2023
1 parent eb6eec1 commit d64cf29
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/sentry.php
Expand Up @@ -44,6 +44,9 @@
// Capture views as spans
'views' => true,

// Capture HTTP client requests as spans
'http_client_requests' => true,

// Indicates if the tracing integrations supplied by Sentry should be loaded
'default_integrations' => true,

Expand Down
21 changes: 21 additions & 0 deletions src/Sentry/Laravel/Tracing/EventHandler.php
Expand Up @@ -79,6 +79,13 @@ class EventHandler
*/
private $traceQueueJobsAsTransactions;

/**
* Indicates if we should trace HTTP client requests.
*
* @var bool
*/
private $traceHttpClientRequests;

/**
* Hold the stack of parent spans that need to be put back on the scope.
*
Expand Down Expand Up @@ -108,6 +115,8 @@ public function __construct(array $config, BacktraceHelper $backtraceHelper)
$this->traceSqlQueries = ($config['sql_queries'] ?? true) === true;
$this->traceSqlQueryOrigins = ($config['sql_origin'] ?? true) === true;

$this->traceHttpClientRequests = ($config['http_client_requests'] ?? true) === true;

$this->traceQueueJobs = ($config['queue_jobs'] ?? false) === true;
$this->traceQueueJobsAsTransactions = ($config['queue_job_transactions'] ?? false) === true;

Expand Down Expand Up @@ -283,6 +292,10 @@ protected function transactionRolledBackHandler(DatabaseEvents\TransactionRolled

protected function httpClientRequestSendingHandler(HttpClientEvents\RequestSending $event): void
{
if (!$this->traceHttpClientRequests) {
return;
}

$parentSpan = SentrySdk::getCurrentHub()->getSpan();

// If there is no tracing span active there is no need to handle the event
Expand All @@ -300,6 +313,10 @@ protected function httpClientRequestSendingHandler(HttpClientEvents\RequestSendi

protected function httpClientResponseReceivedHandler(HttpClientEvents\ResponseReceived $event): void
{
if (!$this->traceHttpClientRequests) {
return;
}

$span = $this->popSpan();

if ($span !== null) {
Expand All @@ -310,6 +327,10 @@ protected function httpClientResponseReceivedHandler(HttpClientEvents\ResponseRe

protected function httpClientConnectionFailedHandler(HttpClientEvents\ConnectionFailed $event): void
{
if (!$this->traceHttpClientRequests) {
return;
}

$span = $this->popSpan();

if ($span !== null) {
Expand Down

0 comments on commit d64cf29

Please sign in to comment.