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

Commit

Permalink
Ensure we use the correct timestamp for timeEvents (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 committed Apr 9, 2018
1 parent b37a9c2 commit fc0254d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Stackdriver/SpanConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ private static function convertTimeEvents(array $events)
private static function convertAnnotation(OCAnnotation $annotation)
{
return new Annotation($annotation->description(), [
'attributes' => $annotation->attributes()
'attributes' => $annotation->attributes(),
'time' => $annotation->time()
]);
}

Expand All @@ -129,7 +130,8 @@ private static function convertMessageEvent(OCMessageEvent $messageEvent)
return new MessageEvent($messageEvent->id(), [
'type' => self::MESSAGE_TYPE_MAP[$messageEvent->type()],
'uncompressedSizeBytes' => $messageEvent->uncompressedSize(),
'compressedSizeBytes' => $messageEvent->compressedSize()
'compressedSizeBytes' => $messageEvent->compressedSize(),
'time' => $messageEvent->time()
]);
}

Expand Down
9 changes: 7 additions & 2 deletions tests/unit/Stackdriver/SpanConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,18 @@ public function testLinks()

public function testTimeEvents()
{
$time = 1490737450.484299;
$span = new OCSpan([
'traceId' => 'aaa',
'timeEvents' => [
new OCAnnotation('some-description', [
'attributes' => ['foo' => 'bar']
'attributes' => ['foo' => 'bar'],
'time' => $time
]),
new OCMessageEvent(OCMessageEvent::TYPE_SENT, 'message-id', [
'uncompressedSize' => 234,
'compressedSize' => 123
'compressedSize' => 123,
'time' => $time
])
],
'startTime' => new \DateTime(),
Expand All @@ -179,13 +182,15 @@ public function testTimeEvents()
$event1 = $timeEvents[0];
$this->assertEquals('some-description', $event1['annotation']['description']['value']);
$this->assertRegExp(self::TIMESTAMP_FORMAT_REGEXP, $event1['time']);
$this->assertEquals('2017-03-28T21:44:10.484299000Z', $event1['time']);

$event2 = $timeEvents[1];
$this->assertEquals('SENT', $event2['messageEvent']['type']);
$this->assertEquals('message-id', $event2['messageEvent']['id']);
$this->assertEquals(234, $event2['messageEvent']['uncompressedSizeBytes']);
$this->assertEquals(123, $event2['messageEvent']['compressedSizeBytes']);
$this->assertRegExp(self::TIMESTAMP_FORMAT_REGEXP, $event2['time']);
$this->assertEquals('2017-03-28T21:44:10.484299000Z', $event2['time']);
}

public function testStatus()
Expand Down

0 comments on commit fc0254d

Please sign in to comment.