Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses unknown servicename #215

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('unknown', null, null, null);
jcchavezs marked this conversation as resolved.
Show resolved Hide resolved
}

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
7 changes: 2 additions & 5 deletions src/Zipkin/TracingBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class TracingBuilder
{
private ?string $localServiceName = null;
private string $localServiceName = 'unknown';

private ?Endpoint $localEndpoint = null;

Expand Down Expand Up @@ -175,10 +175,7 @@ public function build(): Tracing
{
$localEndpoint = $this->localEndpoint;
if ($this->localEndpoint === null) {
$localEndpoint = Endpoint::createFromGlobals();
if ($this->localServiceName !== null) {
$localEndpoint = $localEndpoint->withServiceName($this->localServiceName);
}
$localEndpoint = Endpoint::createFromGlobals()->withServiceName($this->localServiceName);
}

$reporter = $this->reporter ?? new Log(new NullLogger());
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":""}}]';
public const PAYLOAD = '[{"id":"%s","traceId":"%s",'
jcchavezs marked this conversation as resolved.
Show resolved Hide resolved
. '"timestamp":%d,"name":"test","localEndpoint":{"serviceName":"unknown"}}]';

public function testHttpReporterSuccess()
{
Expand Down