Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Add tracing.http_client_requests option #641

Merged
merged 2 commits into from Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opted for enabled by default, to not break for people that already use it without updating their config.


$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