Skip to content

Commit 87d0678

Browse files
authored
Set the current span on the hub in Guzzle middleware (#1801)
1 parent 3519924 commit 87d0678

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Tracing/GuzzleTracingMiddleware.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public static function trace(?HubInterface $hub = null): \Closure
5959
$spanContext->setDescription($request->getMethod() . ' ' . $partialUri);
6060

6161
$childSpan = $parentSpan->startChild($spanContext);
62+
63+
$hub->setSpan($childSpan);
6264
}
6365

6466
if (self::shouldAttachTracingHeaders($client, $request)) {
@@ -68,11 +70,13 @@ public static function trace(?HubInterface $hub = null): \Closure
6870
->withHeader('baggage', getBaggage());
6971
}
7072

71-
$handlerPromiseCallback = static function ($responseOrException) use ($hub, $spanAndBreadcrumbData, $childSpan, $partialUri) {
73+
$handlerPromiseCallback = static function ($responseOrException) use ($hub, $spanAndBreadcrumbData, $childSpan, $parentSpan, $partialUri) {
7274
if ($childSpan !== null) {
7375
// We finish the span (which means setting the span end timestamp) first to ensure the measured time
7476
// the span spans is as close to only the HTTP request time and do the data collection afterwards
7577
$childSpan->finish();
78+
79+
$hub->setSpan($parentSpan);
7680
}
7781

7882
$response = null;

0 commit comments

Comments
 (0)