16
16
17
17
import * as sinon from 'sinon' ;
18
18
import * as assert from 'assert' ;
19
- import { Attributes , AttributeValue , diag } from '@opentelemetry/api' ;
19
+ import {
20
+ Attributes ,
21
+ AttributeValue ,
22
+ diag ,
23
+ ROOT_CONTEXT ,
24
+ trace ,
25
+ TraceFlags ,
26
+ } from '@opentelemetry/api' ;
20
27
import * as logsAPI from '@opentelemetry/api-logs' ;
21
28
import type { HrTime } from '@opentelemetry/api' ;
22
29
import { hrTimeToMilliseconds , timeInputToHrTime } from '@opentelemetry/core' ;
@@ -61,14 +68,21 @@ describe('LogRecord', () => {
61
68
62
69
it ( 'should have a default timestamp' , ( ) => {
63
70
const { logRecord } = setup ( ) ;
64
- assert . ok ( logRecord . time !== undefined ) ;
71
+ assert . ok ( logRecord . hrTime !== undefined ) ;
65
72
assert . ok (
66
- hrTimeToMilliseconds ( logRecord . time ) >
73
+ hrTimeToMilliseconds ( logRecord . hrTime ) >
67
74
hrTimeToMilliseconds ( performanceTimeOrigin )
68
75
) ;
69
76
} ) ;
70
77
71
78
it ( 'should return LogRecord' , ( ) => {
79
+ const spanContext = {
80
+ traceId : 'd4cda95b652f4a1592b449d5929fda1b' ,
81
+ spanId : '6e0c63257de34c92' ,
82
+ traceFlags : TraceFlags . SAMPLED ,
83
+ } ;
84
+ const activeContext = trace . setSpanContext ( ROOT_CONTEXT , spanContext ) ;
85
+
72
86
const logRecordData : logsAPI . LogRecord = {
73
87
timestamp : new Date ( ) . getTime ( ) ,
74
88
severityNumber : logsAPI . SeverityNumber . DEBUG ,
@@ -77,16 +91,14 @@ describe('LogRecord', () => {
77
91
attributes : {
78
92
name : 'test name' ,
79
93
} ,
80
- traceId : 'trance id' ,
81
- spanId : 'span id' ,
82
- traceFlags : 1 ,
94
+ context : activeContext ,
83
95
} ;
84
96
const { logRecord, resource, instrumentationScope } = setup (
85
97
undefined ,
86
98
logRecordData
87
99
) ;
88
100
assert . deepStrictEqual (
89
- logRecord . time ,
101
+ logRecord . hrTime ,
90
102
timeInputToHrTime ( logRecordData . timestamp ! )
91
103
) ;
92
104
assert . strictEqual (
@@ -96,9 +108,12 @@ describe('LogRecord', () => {
96
108
assert . strictEqual ( logRecord . severityText , logRecordData . severityText ) ;
97
109
assert . strictEqual ( logRecord . body , logRecordData . body ) ;
98
110
assert . deepStrictEqual ( logRecord . attributes , logRecordData . attributes ) ;
99
- assert . deepStrictEqual ( logRecord . traceId , logRecordData . traceId ) ;
100
- assert . deepStrictEqual ( logRecord . spanId , logRecordData . spanId ) ;
101
- assert . deepStrictEqual ( logRecord . traceFlags , logRecordData . traceFlags ) ;
111
+ assert . strictEqual ( logRecord . spanContext ?. traceId , spanContext . traceId ) ;
112
+ assert . strictEqual ( logRecord . spanContext ?. spanId , spanContext . spanId ) ;
113
+ assert . strictEqual (
114
+ logRecord . spanContext ?. traceFlags ,
115
+ spanContext . traceFlags
116
+ ) ;
102
117
assert . deepStrictEqual ( logRecord . resource , resource ) ;
103
118
assert . deepStrictEqual (
104
119
logRecord . instrumentationScope ,
@@ -115,9 +130,6 @@ describe('LogRecord', () => {
115
130
attributes : {
116
131
name : 'test name' ,
117
132
} ,
118
- traceId : 'trance id' ,
119
- spanId : 'span id' ,
120
- traceFlags : 1 ,
121
133
} ;
122
134
const { logRecord } = setup ( undefined , logRecordData ) ;
123
135
@@ -258,9 +270,6 @@ describe('LogRecord', () => {
258
270
attributes : {
259
271
name : 'test name' ,
260
272
} ,
261
- traceId : 'trance id' ,
262
- spanId : 'span id' ,
263
- traceFlags : 1 ,
264
273
} ;
265
274
266
275
const newBody = 'this is a new body' ;
@@ -302,9 +311,6 @@ describe('LogRecord', () => {
302
311
attributes : {
303
312
name : 'test name' ,
304
313
} ,
305
- traceId : 'trance id' ,
306
- spanId : 'span id' ,
307
- traceFlags : 1 ,
308
314
} ;
309
315
310
316
const newBody = 'this is a new body' ;
0 commit comments