-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove global span creation when Tracer is initialized and fix batch exporter not exporting in batches but one by one * use the monotonic clock instead of realtime clock to compute time elapsed - realtime clocks can move backwards * add the NoopSpan. It will be used as the root Span * Use NoopSpan for new traces * Generate a new context if the root span is noop * Remove comments * Inline variable * Must set parent as active span so that span ID is propagated * Revert "Must set parent as active span so that span ID is propagated" as context can't be used as span This reverts commit 985fa5e. * Load NoopSpan when required * Fixed regression: creating a Tracer with an existing context is now supported again. * Add variable to improve readability * Rename variable for clarity. * fix failing psalm checks and add test for root NoopSpan Co-authored-by: Ben Magee <[email protected]>
- Loading branch information
Showing
12 changed files
with
357 additions
and
51 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,150 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Sdk\Trace; | ||
|
||
use OpenTelemetry\Trace as API; | ||
|
||
class NoopSpan implements \OpenTelemetry\Trace\Span | ||
{ | ||
/** @var SpanContext */ | ||
private $context; | ||
|
||
/** @var API\Attributes */ | ||
private $attributes; | ||
|
||
/** @var API\Links */ | ||
private $links; | ||
// @todo when links will be implemented, this attribute should be initialized properly | ||
|
||
/** @var API\Events */ | ||
private $events; | ||
|
||
/** @var API\SpanStatus */ | ||
private $status; | ||
|
||
public function __construct() | ||
{ | ||
$this->context = new SpanContext( | ||
SpanContext::INVALID_TRACE, | ||
SpanContext::INVALID_SPAN, | ||
0, | ||
[] | ||
); | ||
|
||
$this->attributes = new Attributes(); | ||
$this->events = new Events(); | ||
$this->status = SpanStatus::ok(); | ||
} | ||
|
||
public function getSpanName(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function getContext(): API\SpanContext | ||
{ | ||
return $this->context; | ||
} | ||
|
||
public function getParent(): ?API\SpanContext | ||
{ | ||
return null; | ||
} | ||
|
||
public function getStartEpochTimestamp(): int | ||
{ | ||
return 0; | ||
} | ||
|
||
public function getStart(): int | ||
{ | ||
return 0; | ||
} | ||
|
||
public function getEnd(): ?int | ||
{ | ||
return 0; | ||
} | ||
|
||
public function getAttributes(): API\Attributes | ||
{ | ||
return $this->attributes; | ||
} | ||
|
||
public function getLinks(): API\Links | ||
{ | ||
return $this->links; | ||
} | ||
|
||
public function getEvents(): API\Events | ||
{ | ||
return $this->events; | ||
} | ||
|
||
public function getStatus(): API\SpanStatus | ||
{ | ||
return $this->status; | ||
} | ||
|
||
public function setAttribute(string $key, $value): API\Span | ||
{ | ||
return $this; | ||
} | ||
|
||
public function addEvent(string $name, int $timestamp, ?API\Attributes $attributes = null): API\Span | ||
{ | ||
return $this; | ||
} | ||
|
||
public function addLink(API\SpanContext $context, ?API\Attributes $attributes = null): API\Span | ||
{ | ||
return $this; | ||
} | ||
|
||
public function updateName(string $name): API\Span | ||
{ | ||
return $this; | ||
} | ||
|
||
public function setSpanStatus(string $code, ?string $description = null): API\Span | ||
{ | ||
return $this; | ||
} | ||
|
||
public function end(int $timestamp = null): API\Span | ||
{ | ||
return $this; | ||
} | ||
|
||
public function isRecording(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function isSampled(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function getSpanKind(): int | ||
{ | ||
return API\SpanKind::KIND_INTERNAL; | ||
} | ||
|
||
public function getCanonicalStatusCode(): string | ||
{ | ||
return $this->status->getCanonicalStatusCode(); | ||
} | ||
|
||
public function getStatusDescription(): string | ||
{ | ||
return $this->status->getStatusDescription(); | ||
} | ||
|
||
public function isStatusOk(): bool | ||
{ | ||
return $this->status->isStatusOK(); | ||
} | ||
} |
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.