-
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.
Removes span to array as it is deprecated (#212)
* chore: removes Span::toArray as it's been deprecated in 2.0. * chore: removes unused default span name constant. * chore: fix lint. * tests: adds tests for log reporter. * chore: upgrades phpstan. * chore: removes comma from constructor. * chore: makes the new line OS dependent in the LogSerializer.
- Loading branch information
Showing
10 changed files
with
181 additions
and
146 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 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
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,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zipkin\Reporters\Log; | ||
|
||
use Zipkin\Reporters\SpanSerializer; | ||
use Zipkin\Recording\ReadbackSpan; | ||
|
||
final class LogSerializer implements SpanSerializer | ||
{ | ||
/** | ||
* @param ReadbackSpan[]|array $spans | ||
*/ | ||
public function serialize(array $spans): string | ||
{ | ||
$spansAsArray = array_map([self::class, 'serializeSpan'], $spans); | ||
|
||
return implode(PHP_EOL, $spansAsArray); | ||
} | ||
|
||
private function serializeSpan(ReadbackSpan $span): string | ||
{ | ||
$serialized = []; | ||
$serialized[] = sprintf("Name: %s", $span->getName()); | ||
$serialized[] = sprintf("TraceID: %s", $span->getTraceId()); | ||
$serialized[] = sprintf("SpanID: %s", $span->getSpanId()); | ||
if (!is_null($parentID = $span->getParentId())) { | ||
$serialized[] = sprintf("StartTime: %s", $parentID); | ||
} | ||
$serialized[] = sprintf("Timestamp: %s", $span->getTimestamp()); | ||
$serialized[] = sprintf("Duration: %s", $span->getDuration()); | ||
$serialized[] = sprintf("Kind: %s", $span->getKind()); | ||
|
||
$serialized[] = sprintf("LocalEndpoint: %s", $span->getLocalEndpoint()->getServiceName()); | ||
|
||
if (\count($tags = $span->getTags()) > 0) { | ||
$serialized[] = "Tags:"; | ||
|
||
foreach ($tags as $key => $value) { | ||
$serialized[] = sprintf(" %s: %s", $key, $value); | ||
} | ||
} | ||
|
||
if (\count($annotations = $span->getAnnotations()) > 0) { | ||
$serialized[] = "Annotations:"; | ||
|
||
foreach ($annotations as $annotation) { | ||
$serialized[] = sprintf(" - timestamp: %s", $annotation["timestamp"]); | ||
$serialized[] = sprintf(" value: %s", $annotation["value"]); | ||
} | ||
} | ||
|
||
if (!is_null($remoteEndpoint = $span->getRemoteEndpoint())) { | ||
$serialized[] = sprintf("RemoteEndpoint: %s", $remoteEndpoint->getServiceName()); | ||
} | ||
|
||
return implode(PHP_EOL, $serialized); | ||
} | ||
} |
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
Oops, something went wrong.