-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(http-server): decouples client/server tracing from PSR implemen…
…tation.
- Loading branch information
Showing
18 changed files
with
175 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/Zipkin/Instrumentation/Http/Client/Psr18/DefaultParser.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zipkin\Instrumentation\Http\Client\Psr18; | ||
|
||
use Zipkin\Tags; | ||
use Zipkin\SpanCustomizer; | ||
use Zipkin\Propagation\TraceContext; | ||
use Zipkin\Instrumentation\Http\Client\Parser; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
/** | ||
* DefaultParser contains the basic logic for turning request/response information | ||
* into span name and tags. Implementors can use this as a base parser to reduce | ||
* boilerplate. | ||
*/ | ||
class DefaultParser implements Parser | ||
{ | ||
public function spanName($request): string | ||
{ | ||
self::assertRequestType($request); | ||
return $request->getMethod(); | ||
} | ||
|
||
public function request($request, TraceContext $context, SpanCustomizer $span): void | ||
{ | ||
self::assertRequestType($request); | ||
$span->tag(Tags\HTTP_METHOD, $request->getMethod()); | ||
$span->tag(Tags\HTTP_PATH, $request->getUri()->getPath() ?: "/"); | ||
} | ||
|
||
public function response($response, TraceContext $context, SpanCustomizer $span): void | ||
{ | ||
self::assertResponseType($response); | ||
$span->tag(Tags\HTTP_STATUS_CODE, (string) $response->getStatusCode()); | ||
if ($response->getStatusCode() > 399) { | ||
$span->tag(Tags\ERROR, (string) $response->getStatusCode()); | ||
} | ||
} | ||
|
||
// Makes sure the type for request object is correct. | ||
private static function assertRequestType(RequestInterface $request): void | ||
{ | ||
} | ||
|
||
// Makes sure the type for response object is correct. | ||
private static function assertResponseType(ResponseInterface $response): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.