Skip to content

Commit d64cf29

Browse files
authored
ref: Add tracing.http_client_requests option (#641)
1 parent eb6eec1 commit d64cf29

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

config/sentry.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
// Capture views as spans
4545
'views' => true,
4646

47+
// Capture HTTP client requests as spans
48+
'http_client_requests' => true,
49+
4750
// Indicates if the tracing integrations supplied by Sentry should be loaded
4851
'default_integrations' => true,
4952

src/Sentry/Laravel/Tracing/EventHandler.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ class EventHandler
7979
*/
8080
private $traceQueueJobsAsTransactions;
8181

82+
/**
83+
* Indicates if we should trace HTTP client requests.
84+
*
85+
* @var bool
86+
*/
87+
private $traceHttpClientRequests;
88+
8289
/**
8390
* Hold the stack of parent spans that need to be put back on the scope.
8491
*
@@ -108,6 +115,8 @@ public function __construct(array $config, BacktraceHelper $backtraceHelper)
108115
$this->traceSqlQueries = ($config['sql_queries'] ?? true) === true;
109116
$this->traceSqlQueryOrigins = ($config['sql_origin'] ?? true) === true;
110117

118+
$this->traceHttpClientRequests = ($config['http_client_requests'] ?? true) === true;
119+
111120
$this->traceQueueJobs = ($config['queue_jobs'] ?? false) === true;
112121
$this->traceQueueJobsAsTransactions = ($config['queue_job_transactions'] ?? false) === true;
113122

@@ -283,6 +292,10 @@ protected function transactionRolledBackHandler(DatabaseEvents\TransactionRolled
283292

284293
protected function httpClientRequestSendingHandler(HttpClientEvents\RequestSending $event): void
285294
{
295+
if (!$this->traceHttpClientRequests) {
296+
return;
297+
}
298+
286299
$parentSpan = SentrySdk::getCurrentHub()->getSpan();
287300

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

301314
protected function httpClientResponseReceivedHandler(HttpClientEvents\ResponseReceived $event): void
302315
{
316+
if (!$this->traceHttpClientRequests) {
317+
return;
318+
}
319+
303320
$span = $this->popSpan();
304321

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

311328
protected function httpClientConnectionFailedHandler(HttpClientEvents\ConnectionFailed $event): void
312329
{
330+
if (!$this->traceHttpClientRequests) {
331+
return;
332+
}
333+
313334
$span = $this->popSpan();
314335

315336
if ($span !== null) {

0 commit comments

Comments
 (0)