Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit dcf4b30

Browse files
authored
Move HTTP_REDIRECTED_URL header handling to StackdriverExporter (#113)
1 parent f91ffdb commit dcf4b30

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/Trace/Exporter/StackdriverExporter.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@ private function addCommonAttributes(&$tracer, $headers = null)
259259
$tracer->addAttribute($attributeKey, $val, ['span' => $rootSpan]);
260260
}
261261
}
262+
263+
$responseCode = http_response_code();
264+
if ($responseCode == 301 || $responseCode == 302) {
265+
foreach (headers_list() as $header) {
266+
if (substr($header, 0, 9) == 'Location:') {
267+
$this->rootSpan->addAttribute(self::HTTP_REDIRECTED_URL, substr($header, 10));
268+
break;
269+
}
270+
}
271+
}
262272
$tracer->addAttribute(self::PID, '' . getmypid(), ['span' => $rootSpan]);
263273
$tracer->addAttribute(self::AGENT, 'opencensus-php [' . self::VERSION . ']', ['span' => $rootSpan]);
264274
}

src/Trace/RequestHandler.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,6 @@ public function __construct(
121121
public function onExit()
122122
{
123123
$responseCode = http_response_code();
124-
if ($responseCode == 301 || $responseCode == 302) {
125-
foreach (headers_list() as $header) {
126-
if (substr($header, 0, 9) == 'Location:') {
127-
$this->rootSpan->addAttribute(self::HTTP_REDIRECTED_URL, substr($header, 10));
128-
break;
129-
}
130-
}
131-
}
132124
$this->rootSpan->setStatus($responseCode, "HTTP status code: $responseCode");
133125

134126
$this->scope->close();

0 commit comments

Comments
 (0)