@@ -7,7 +7,7 @@ const { Client } = require('./client')
7
7
const processStartTime = BigInt ( Date . now ( ) * 1e6 )
8
8
const processStartTicks = process . hrtime . bigint ( )
9
9
const now = ( ) => Number ( processStartTime + process . hrtime . bigint ( ) - processStartTicks )
10
- const service = process . env . DD_SERVICE || 'unnamed-node-app'
10
+ // const service = process.env.DD_SERVICE || 'unnamed-node-app'
11
11
const ARRAY_OF_TWO = 0x92
12
12
const SOFT_LIMIT = 8 * 1024 * 1024 // 8MB
13
13
const flushInterval = 2000
@@ -52,8 +52,9 @@ class Encoder {
52
52
// resource comes from mixing http method and route
53
53
// error will be its own event
54
54
55
- this . _encodeFixArray ( bytes , 7 )
55
+ this . _encodeFixArray ( bytes , 2 )
56
56
this . _encodeShort ( bytes , eventTypes . KOA_REQUEST_START ) // implied: name
57
+ this . _encodeFixArray ( bytes , 6 )
57
58
this . _encodeLong ( bytes , now ( ) )
58
59
this . _encodeId ( bytes , store . traceContext . traceId )
59
60
this . _encodeId ( bytes , store . traceContext . spanId )
@@ -70,8 +71,9 @@ class Encoder {
70
71
71
72
if ( ! store || ! store . traceContext ) return
72
73
73
- this . _encodeFixArray ( bytes , 5 )
74
+ this . _encodeFixArray ( bytes , 2 )
74
75
this . _encodeShort ( bytes , eventTypes . KOA_REQUEST_FINISH ) // implied: name
76
+ this . _encodeFixArray ( bytes , 4 )
75
77
this . _encodeLong ( bytes , now ( ) )
76
78
this . _encodeId ( bytes , store . traceContext . traceId )
77
79
this . _encodeId ( bytes , store . traceContext . spanId )
@@ -86,8 +88,9 @@ class Encoder {
86
88
87
89
if ( ! store || ! store . traceContext ) return // TODO: support errors without tracing
88
90
89
- this . _encodeFixArray ( bytes , 7 )
91
+ this . _encodeFixArray ( bytes , 2 )
90
92
this . _encodeShort ( bytes , eventTypes . ERROR ) // implied: name
93
+ this . _encodeFixArray ( bytes , 6 )
91
94
this . _encodeLong ( bytes , now ( ) )
92
95
this . _encodeId ( bytes , store . traceContext . traceId )
93
96
this . _encodeId ( bytes , store . traceContext . spanId )
@@ -98,8 +101,7 @@ class Encoder {
98
101
this . _afterEncode ( )
99
102
}
100
103
101
- // TODO: support new payload format
102
- makePayload05 ( ) {
104
+ makePayload ( ) {
103
105
const prefixSize = 1
104
106
const stringSize = this . _stringBytes . length + 5
105
107
const eventSize = this . _eventBytes . length + 5
@@ -110,31 +112,7 @@ class Encoder {
110
112
buffer [ offset ++ ] = ARRAY_OF_TWO
111
113
112
114
offset = this . _writeStrings ( buffer , offset )
113
- offset = this . _writeEvents ( buffer , offset )
114
-
115
- this . _reset ( )
116
-
117
- return buffer
118
- }
119
-
120
- makePayload ( ) {
121
- this . _encodeMap ( this . _metadataBytes , { service } ) // HACK
122
-
123
- const metadataBytes = this . _metadataBytes
124
- const metadataSize = metadataBytes . length + 9
125
- const eventSize = this . _eventBytes . length + 5 + 7
126
- const buffer = Buffer . allocUnsafe ( 1 + metadataSize + eventSize )
127
-
128
- let offset = 0
129
-
130
- buffer [ offset ++ ] = 0x82 // fixmap(2)
131
-
132
- buffer [ offset ++ ] = 0xa8 // fixstr(8)
133
- offset += buffer . write ( 'metadata' , offset )
134
- offset += metadataBytes . buffer . copy ( buffer , offset , 0 , metadataBytes . length )
135
-
136
- buffer [ offset ++ ] = 0xa6 // fixstr(6)
137
- offset += buffer . write ( 'events' , offset )
115
+ // TODO: add metadata
138
116
offset = this . _writeEvents ( buffer , offset )
139
117
140
118
this . _reset ( )
@@ -308,17 +286,9 @@ class Encoder {
308
286
}
309
287
}
310
288
311
- _encodeString05 ( bytes , value = '' ) {
312
- this . _cacheString ( value )
313
- this . _encodeInteger ( bytes , this . _stringMap [ value ] )
314
- }
315
-
316
289
_encodeString ( bytes , value = '' ) {
317
290
this . _cacheString ( value )
318
-
319
- const { start, end } = this . _stringMap [ value ]
320
-
321
- this . _stringBytes . copy ( bytes , start , end )
291
+ this . _encodeInteger ( bytes , this . _stringMap [ value ] )
322
292
}
323
293
324
294
_encodeFloat ( bytes , value ) {
@@ -341,23 +311,13 @@ class Encoder {
341
311
}
342
312
}
343
313
344
- _cacheString05 ( value ) {
314
+ _cacheString ( value ) {
345
315
if ( ! ( value in this . _stringMap ) ) {
346
316
this . _stringMap [ value ] = this . _stringCount ++
347
317
this . _stringBytes . write ( value )
348
318
}
349
319
}
350
320
351
- _cacheString ( value ) {
352
- if ( ! ( value in this . _stringMap ) ) {
353
- this . _stringCount ++
354
- this . _stringMap [ value ] = {
355
- start : this . _stringBytes . length ,
356
- end : this . _stringBytes . length + this . _stringBytes . write ( value )
357
- }
358
- }
359
- }
360
-
361
321
_writeArrayPrefix ( buffer , offset , count ) {
362
322
buffer [ offset ++ ] = 0xdd
363
323
buffer . writeUInt32BE ( count , offset )
0 commit comments