Skip to content

Commit

Permalink
Fix: ignore redirection error (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesChou authored Sep 4, 2024
1 parent 89117db commit 9b97522
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ private function maybeRecordError(SpanInterface $span, Response $response): void
return;
}

// HTTP status code 3xx is not really error
// See https://www.rfc-editor.org/rfc/rfc9110.html#name-redirection-3xx
if ($response->redirect()) {
return;
}

$span->setStatus(
StatusCode::STATUS_ERROR,
HttpResponse::$statusTexts[$response->status()] ?? (string) $response->status()
Expand Down
10 changes: 10 additions & 0 deletions src/Instrumentation/Laravel/tests/Integration/Http/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,29 @@ public function test_it_records_requests(): void
Http::fake([
'ok.opentelemetry.io/*' => Http::response(status: 201),
'missing.opentelemetry.io' => Http::response(status: 404),
'redirect.opentelemetry.io' => Http::response(status: 302),
]);

$response = Http::get('missing.opentelemetry.io');
$span = $this->storage[0];
self::assertEquals(404, $response->status());
self::assertEquals('GET', $span->getName());
self::assertEquals('missing.opentelemetry.io', $span->getAttributes()->get(TraceAttributes::URL_PATH));
self::assertEquals(StatusCode::STATUS_ERROR, $span->getStatus()->getCode());

$response = Http::post('ok.opentelemetry.io/foo?param=bar');
$span = $this->storage[1];
self::assertEquals(201, $response->status());
self::assertEquals('POST', $span->getName());
self::assertEquals('ok.opentelemetry.io/foo', $span->getAttributes()->get(TraceAttributes::URL_PATH));
self::assertEquals(StatusCode::STATUS_UNSET, $span->getStatus()->getCode());

$response = Http::get('redirect.opentelemetry.io');
$span = $this->storage[2];
self::assertEquals(302, $response->status());
self::assertEquals('GET', $span->getName());
self::assertEquals('redirect.opentelemetry.io', $span->getAttributes()->get(TraceAttributes::URL_PATH));
self::assertEquals(StatusCode::STATUS_UNSET, $span->getStatus()->getCode());
}

public function test_it_records_connection_failures(): void
Expand Down

0 comments on commit 9b97522

Please sign in to comment.