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

Commit fc0254d

Browse files
authored
Ensure we use the correct timestamp for timeEvents (#3)
1 parent b37a9c2 commit fc0254d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/Stackdriver/SpanConverter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ private static function convertTimeEvents(array $events)
120120
private static function convertAnnotation(OCAnnotation $annotation)
121121
{
122122
return new Annotation($annotation->description(), [
123-
'attributes' => $annotation->attributes()
123+
'attributes' => $annotation->attributes(),
124+
'time' => $annotation->time()
124125
]);
125126
}
126127

@@ -129,7 +130,8 @@ private static function convertMessageEvent(OCMessageEvent $messageEvent)
129130
return new MessageEvent($messageEvent->id(), [
130131
'type' => self::MESSAGE_TYPE_MAP[$messageEvent->type()],
131132
'uncompressedSizeBytes' => $messageEvent->uncompressedSize(),
132-
'compressedSizeBytes' => $messageEvent->compressedSize()
133+
'compressedSizeBytes' => $messageEvent->compressedSize(),
134+
'time' => $messageEvent->time()
133135
]);
134136
}
135137

tests/unit/Stackdriver/SpanConverterTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,18 @@ public function testLinks()
157157

158158
public function testTimeEvents()
159159
{
160+
$time = 1490737450.484299;
160161
$span = new OCSpan([
161162
'traceId' => 'aaa',
162163
'timeEvents' => [
163164
new OCAnnotation('some-description', [
164-
'attributes' => ['foo' => 'bar']
165+
'attributes' => ['foo' => 'bar'],
166+
'time' => $time
165167
]),
166168
new OCMessageEvent(OCMessageEvent::TYPE_SENT, 'message-id', [
167169
'uncompressedSize' => 234,
168-
'compressedSize' => 123
170+
'compressedSize' => 123,
171+
'time' => $time
169172
])
170173
],
171174
'startTime' => new \DateTime(),
@@ -179,13 +182,15 @@ public function testTimeEvents()
179182
$event1 = $timeEvents[0];
180183
$this->assertEquals('some-description', $event1['annotation']['description']['value']);
181184
$this->assertRegExp(self::TIMESTAMP_FORMAT_REGEXP, $event1['time']);
185+
$this->assertEquals('2017-03-28T21:44:10.484299000Z', $event1['time']);
182186

183187
$event2 = $timeEvents[1];
184188
$this->assertEquals('SENT', $event2['messageEvent']['type']);
185189
$this->assertEquals('message-id', $event2['messageEvent']['id']);
186190
$this->assertEquals(234, $event2['messageEvent']['uncompressedSizeBytes']);
187191
$this->assertEquals(123, $event2['messageEvent']['compressedSizeBytes']);
188192
$this->assertRegExp(self::TIMESTAMP_FORMAT_REGEXP, $event2['time']);
193+
$this->assertEquals('2017-03-28T21:44:10.484299000Z', $event2['time']);
189194
}
190195

191196
public function testStatus()

0 commit comments

Comments
 (0)