|
18 | 18 | const EventId = require('eventid'); |
19 | 19 | import * as extend from 'extend'; |
20 | 20 | import {google} from '../protos/protos'; |
21 | | -import {objToStruct, structToObj, zuluToDateObj} from './utils/common'; |
| 21 | +import { |
| 22 | + objToStruct, |
| 23 | + structToObj, |
| 24 | + zuluToDateObj, |
| 25 | + toNanosAndSecondsObj, |
| 26 | +} from './utils/common'; |
22 | 27 | import { |
23 | 28 | makeHttpRequestData, |
24 | 29 | CloudLoggingHttpRequest, |
@@ -75,7 +80,9 @@ export interface StructuredJson { |
75 | 80 | // Universally supported properties |
76 | 81 | message?: string | object; |
77 | 82 | httpRequest?: object; |
78 | | - timestamp?: string; |
| 83 | + // Based on https://cloud.google.com/logging/docs/agent/logging/configuration#timestamp-processing, the |
| 84 | + // timestamp should be in nanos and seconds format. |
| 85 | + timestamp?: Timestamp; |
79 | 86 | [INSERT_ID_KEY]?: string; |
80 | 87 | [OPERATION_KEY]?: object; |
81 | 88 | [SOURCE_LOCATION_KEY]?: object; |
@@ -214,12 +221,7 @@ class Entry { |
214 | 221 | } |
215 | 222 | // Format log timestamp |
216 | 223 | if (entry.timestamp instanceof Date) { |
217 | | - const seconds = entry.timestamp.getTime() / 1000; |
218 | | - const secondsRounded = Math.floor(seconds); |
219 | | - entry.timestamp = { |
220 | | - seconds: secondsRounded, |
221 | | - nanos: Math.floor((seconds - secondsRounded) * 1e9), |
222 | | - }; |
| 224 | + entry.timestamp = toNanosAndSecondsObj(entry.timestamp); |
223 | 225 | } else if (typeof entry.timestamp === 'string') { |
224 | 226 | entry.timestamp = zuluToDateObj(entry.timestamp); |
225 | 227 | } |
@@ -300,7 +302,7 @@ class Entry { |
300 | 302 | } |
301 | 303 | // Format timestamp |
302 | 304 | if (meta.timestamp instanceof Date) { |
303 | | - entry.timestamp = meta.timestamp.toISOString(); |
| 305 | + entry.timestamp = toNanosAndSecondsObj(meta.timestamp); |
304 | 306 | } |
305 | 307 | // Format httprequest |
306 | 308 | const req = meta.httpRequest; |
|
0 commit comments