Skip to content

Commit

Permalink
Trace the Guzzle request on the scope rather than the current transac…
Browse files Browse the repository at this point in the history
…tion (#1099)
  • Loading branch information
HazAT committed Sep 29, 2020
1 parent b77ff37 commit 65030a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- fix: Use Span on Scope instead of Transaction for GuzzleMiddleware (#1099)

## 3.0.0 (2020-09-28)

**Tracing API**
Expand Down
14 changes: 7 additions & 7 deletions src/Tracing/GuzzleTracingMiddleware.php
Expand Up @@ -18,20 +18,20 @@ public static function trace(?HubInterface $hub = null): \Closure
return function (callable $handler) use ($hub): \Closure {
return function (RequestInterface $request, array $options) use ($hub, $handler) {
$hub = $hub ?? SentrySdk::getCurrentHub();
$transaction = $hub->getTransaction();
$span = null;
$span = $hub->getSpan();
$childSpan = null;

if (null !== $transaction) {
if (null !== $span) {
$spanContext = new SpanContext();
$spanContext->setOp('http.guzzle');
$spanContext->setDescription($request->getMethod() . ' ' . $request->getUri());

$span = $transaction->startChild($spanContext);
$childSpan = $span->startChild($spanContext);
}

$handlerPromiseCallback = static function ($responseOrException) use ($span) {
if (null !== $span) {
$span->finish();
$handlerPromiseCallback = static function ($responseOrException) use ($childSpan) {
if (null !== $childSpan) {
$childSpan->finish();
}

if ($responseOrException instanceof \Throwable) {
Expand Down

0 comments on commit 65030a1

Please sign in to comment.