Skip to content

Commit

Permalink
Merge f18d174 into 05888a7
Browse files Browse the repository at this point in the history
  • Loading branch information
jcchavezs committed Sep 13, 2021
2 parents 05888a7 + f18d174 commit 7350690
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
6 changes: 4 additions & 2 deletions src/Zipkin/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

final class Endpoint
{
public const DEFAULT_SERVICE_NAME = 'unknown';

/**
* Service name in lowercase, such as "memcache" or "zipkin-web"
* Conventionally, when the service name isn't known, service_name = "unknown".
*/
private string $serviceName;
private string $serviceName = self::DEFAULT_SERVICE_NAME;

/**
* Host address packed into 4 bytes.
Expand Down Expand Up @@ -72,7 +74,7 @@ public static function createFromGlobals(): self

public static function createAsEmpty(): self
{
return new self('', null, null, null);
return new self(self::DEFAULT_SERVICE_NAME, null, null, null);
}

public function getServiceName(): string
Expand Down
28 changes: 14 additions & 14 deletions src/Zipkin/Reporters/Log/LogSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,37 @@ public function serialize(array $spans): string
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());
$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('StartTime: %s', $parentID);
}
$serialized[] = sprintf("Timestamp: %s", $span->getTimestamp());
$serialized[] = sprintf("Duration: %s", $span->getDuration());
$serialized[] = sprintf("Kind: %s", $span->getKind());
$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());
$serialized[] = sprintf('LocalEndpoint: %s', $span->getLocalEndpoint()->getServiceName());

if (\count($tags = $span->getTags()) > 0) {
$serialized[] = "Tags:";
$serialized[] = 'Tags:';

foreach ($tags as $key => $value) {
$serialized[] = sprintf(" %s: %s", $key, $value);
$serialized[] = sprintf(' %s: %s', $key, $value);
}
}

if (\count($annotations = $span->getAnnotations()) > 0) {
$serialized[] = "Annotations:";
$serialized[] = 'Annotations:';

foreach ($annotations as $annotation) {
$serialized[] = sprintf(" - timestamp: %s", $annotation["timestamp"]);
$serialized[] = sprintf(" value: %s", $annotation["value"]);
$serialized[] = sprintf(' - timestamp: %s', $annotation['timestamp']);
$serialized[] = sprintf(' value: %s', $annotation['value']);
}
}

if (!is_null($remoteEndpoint = $span->getRemoteEndpoint())) {
$serialized[] = sprintf("RemoteEndpoint: %s", $remoteEndpoint->getServiceName());
$serialized[] = sprintf('RemoteEndpoint: %s', $remoteEndpoint->getServiceName());
}

return implode(PHP_EOL, $serialized);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Reporters/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ final class HttpTest extends TestCase
{
use ProphecyTrait;

const PAYLOAD = '[{"id":"%s","traceId":"%s",'
. '"timestamp":%d,"name":"test","localEndpoint":{"serviceName":""}}]';
private const PAYLOAD = '[{"id":"%s","traceId":"%s",'
. '"timestamp":%d,"name":"test","localEndpoint":{"serviceName":"unknown"}}]';

public function testHttpReporterSuccess()
{
Expand Down

0 comments on commit 7350690

Please sign in to comment.