Skip to content

Commit

Permalink
Merge pull request #91 from xJakub/custom_start_times
Browse files Browse the repository at this point in the history
Support custom startTime in spans
  • Loading branch information
jky-yy authored May 4, 2020
2 parents 39b3e83 + 2636018 commit 4142fce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Jaeger/Jaeger.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public function startSpan($operationName, $options = []){
}
}

$span = new Span($operationName, $spanContext, $options->getReferences());
$startTime = $options->getStartTime() ? intval($options->getStartTime() * 1000000) : null;
$span = new Span($operationName, $spanContext, $options->getReferences(), $startTime);
if(!empty($options->getTags())) {
foreach ($options->getTags() as $k => $tag) {
$span->setTag($k, $tag);
Expand Down
4 changes: 2 additions & 2 deletions src/Jaeger/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class Span implements \OpenTracing\Span{

public $references = [];

public function __construct($operationName, \OpenTracing\SpanContext $spanContext, $references){
public function __construct($operationName, \OpenTracing\SpanContext $spanContext, $references, $startTime = null){
$this->operationName = $operationName;
$this->startTime = $this->microtimeToInt();
$this->startTime = $startTime == null ? $this->microtimeToInt() : $startTime;
$this->spanContext = $spanContext;
$this->references = $references;
}
Expand Down
12 changes: 11 additions & 1 deletion tests/JaegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public function testExtractUnSupportFormat(){

public function testStartSpan(){
$Jaeger = $this->getJaeger();
$Jaeger->startSpan('test');
$span = $Jaeger->startSpan('test');
$this->assertNotEmpty($span->startTime);
$this->assertNotEmpty($Jaeger->getSpans());
}

Expand Down Expand Up @@ -158,6 +159,15 @@ public function testStartSpanWithChildOfTypeRef()
}


public function testStartSpanWithCustomStartTime()
{
$jaeger = $this->getJaeger();
$span = $jaeger->startSpan('test', ['start_time' => 1499355363.123456]);

$this->assertSame(1499355363123456, $span->startTime);
}


public function testStartSpanWithAllRefType()
{
$jaeger = $this->getJaeger();
Expand Down

0 comments on commit 4142fce

Please sign in to comment.