Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
ExtensionTracer should set traceId on spans (#157)
Browse files Browse the repository at this point in the history
* Failing test for extension not preserving traceId

* ExtensionTracer correctly sets traceId on returned spans
  • Loading branch information
chingor13 authored Apr 3, 2018
1 parent 6255978 commit bbbf7a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Trace/Tracer/ExtensionTracer.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function withSpan(Span $span)
? (float)($spanData->startTime()->format('U.u'))
: microtime(true);
$info = [
'traceId' => $spanData->traceId(),
'spanId' => $spanData->spanId(),
'parentSpanId' => $spanData->parentSpanId(),
'startTime' => $startTime,
Expand All @@ -117,7 +118,10 @@ public function spans()
{
// each span returned from opencensus_trace_list should be a
// OpenCensus\Span object
return array_map([$this, 'mapSpan'], opencensus_trace_list());
$traceId = $this->spanContext()->traceId();
return array_map(function ($span) use ($traceId) {
return $this->mapSpan($span, $traceId);
}, opencensus_trace_list());
}

/**
Expand Down Expand Up @@ -246,9 +250,10 @@ private function generateSpanName()
return uniqid('span');
}

private function mapSpan($span)
private function mapSpan($span, $traceId)
{
return new Span([
'traceId' => $traceId,
'name' => $span->name(),
'spanId' => $span->spanId(),
'parentSpanId' => $span->parentSpanId(),
Expand Down
1 change: 1 addition & 0 deletions tests/unit/Trace/Tracer/AbstractTracerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function testMaintainsContext()
$spans = $tracer->spans();
$this->assertCount(1, $spans);
$spanData = $spans[0]->spanData();
$this->assertEquals('traceid', $spanData->traceId());
$this->assertEquals('test', $spanData->name());
$this->assertEquals($parentSpanId, $spanData->parentSpanId());
}
Expand Down

0 comments on commit bbbf7a7

Please sign in to comment.