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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tracing #387

Merged
merged 9 commits into from Sep 29, 2020
Merged
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions src/Sentry/Laravel/Tracing/Middleware.php
Expand Up @@ -18,6 +18,13 @@ class Middleware
*/
protected $transaction;

/**
* The span for the `app.handle` part of the application.
*
* @var \Sentry\Tracing\Span|null
*/
protected $appSpan;

/**
* Handle an incoming request.
*
Expand Down Expand Up @@ -46,6 +53,13 @@ public function handle($request, Closure $next)
public function terminate($request, $response): void
{
if ($this->transaction !== null && app()->bound('sentry')) {
if ($this->appSpan !== null) {
$this->appSpan->finish();
}

// Make sure we set the span in the Sentry SDK to the transaction
stayallive marked this conversation as resolved.
Show resolved Hide resolved
SentrySdk::getCurrentHub()->setSpan($this->transaction);

$this->transaction->finish();
}
}
Expand Down Expand Up @@ -81,6 +95,13 @@ private function startTransaction(Request $request, Hub $sentry): void
$spanContextStart->setStartTimestamp(defined('LARAVEL_START') ? LARAVEL_START : $request->server('REQUEST_TIME_FLOAT', $fallbackTime));
$spanContextStart->setEndTimestamp(microtime(true));
$this->transaction->startChild($spanContextStart);

$appContextStart = new SpanContext();
$appContextStart->setOp('app.handle');
$appContextStart->setStartTimestamp(microtime(true));
$this->appSpan = $this->transaction->startChild($appContextStart);

SentrySdk::getCurrentHub()->setSpan($this->appSpan);
});
}
}
Expand Down