Skip to content

Commit

Permalink
allowed to custom span time
Browse files Browse the repository at this point in the history
  • Loading branch information
moolex committed Jul 30, 2019
1 parent fba0404 commit 4413fc3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Utils/SpansCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function traced() : bool
* @param mixed $exaCarrier
* @param SpanContext $exaContext
* @param Platform $platform
* @param int $timestamp
*/
protected function newSpan(
Context $context,
Expand All @@ -62,7 +63,8 @@ protected function newSpan(
string $exaFormat = null,
$exaCarrier = null,
SpanContext $exaContext = null,
Platform $platform = null
Platform $platform = null,
int $timestamp = null
) : void {
if (is_null($platform)) {
if (DI::has(Platform::class)) {
Expand All @@ -87,7 +89,7 @@ protected function newSpan(

// options
$options = [
'start_time' => $this->microseconds(),
'start_time' => $timestamp ?? $this->microseconds(),
'tags' => array_merge($platform->env()->tags(), $tags),
];

Expand Down Expand Up @@ -143,16 +145,17 @@ protected function finishSpan(Promised $finished, Context $traced = null) : Prom
/**
* @param Context $context
* @param array $tags
* @param int $time
*/
protected function closeSpan(Context $context, array $tags = []) : void
protected function closeSpan(Context $context, array $tags = [], int $time = null) : void
{
if ($context->has(CTX::G_SPAN)) {
/**
* @var Span $span
*/
$span = $context->get(CTX::G_SPAN);
$span->setTags($tags);
$span->finish();
$span->finish($time);
$this->endingSpan($context);
}
}
Expand All @@ -161,8 +164,9 @@ protected function closeSpan(Context $context, array $tags = []) : void
* @param Context $context
* @param Throwable $err
* @param array $tags
* @param int $time
*/
protected function errorSpan(Context $context, Throwable $err = null, array $tags = []) : void
protected function errorSpan(Context $context, Throwable $err = null, array $tags = [], int $time = null) : void
{
if ($context->has(CTX::G_SPAN)) {
/**
Expand All @@ -177,7 +181,7 @@ protected function errorSpan(Context $context, Throwable $err = null, array $tag
LOG::MESSAGE => $err->getMessage(),
LOG::STACK => $err->getTraceAsString(),
]);
$span->finish();
$span->finish($time);
$this->endingSpan($context);
}
}
Expand Down

0 comments on commit 4413fc3

Please sign in to comment.