@@ -88,7 +88,7 @@ describe('instrumentation_info', () => {
88
88
) ;
89
89
} ) ;
90
90
91
- it ( 'should add instrumentation info to existing list' , ( ) => {
91
+ it ( 'should add instrumentation info to existing list in right order ' , ( ) => {
92
92
const dummyEntry = createEntry ( NODEJS_TEST , VERSION_TEST ) ;
93
93
const entries = instrumentation . populateInstrumentationInfo ( dummyEntry ) ;
94
94
assert . equal ( entries [ 0 ] . length , 1 ) ;
@@ -102,19 +102,19 @@ describe('instrumentation_info', () => {
102
102
assert . equal (
103
103
entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
104
104
instrumentation . INSTRUMENTATION_SOURCE_KEY
105
- ] ?. [ 0 ] ?. [ NAME ] ,
105
+ ] ?. [ 1 ] ?. [ NAME ] ,
106
106
instrumentation . NODEJS_LIBRARY_NAME_PREFIX
107
107
) ;
108
108
assert . equal (
109
109
entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
110
110
instrumentation . INSTRUMENTATION_SOURCE_KEY
111
- ] ?. [ 1 ] ?. [ NAME ] ,
111
+ ] ?. [ 0 ] ?. [ NAME ] ,
112
112
NODEJS_TEST
113
113
) ;
114
114
assert . equal (
115
115
entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
116
116
instrumentation . INSTRUMENTATION_SOURCE_KEY
117
- ] ?. [ 1 ] ?. [ VERSION ] ,
117
+ ] ?. [ 0 ] ?. [ VERSION ] ,
118
118
VERSION_TEST
119
119
) ;
120
120
} ) ;
@@ -147,13 +147,13 @@ describe('instrumentation_info', () => {
147
147
assert . equal (
148
148
entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
149
149
instrumentation . INSTRUMENTATION_SOURCE_KEY
150
- ] ?. [ 1 ] ?. [ NAME ] ,
150
+ ] ?. [ 0 ] ?. [ NAME ] ,
151
151
NODEJS_TEST + '-oo*'
152
152
) ;
153
153
assert . equal (
154
154
entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
155
155
instrumentation . INSTRUMENTATION_SOURCE_KEY
156
- ] ?. [ 1 ] ?. [ VERSION ] ,
156
+ ] ?. [ 0 ] ?. [ VERSION ] ,
157
157
VERSION_TEST + '.0.0.0.0.*'
158
158
) ;
159
159
} ) ;
@@ -174,6 +174,60 @@ describe('instrumentation_info', () => {
174
174
assert . equal ( entries [ 0 ] . length , 1 ) ;
175
175
assert . deepEqual ( dummyEntry , entries [ 0 ] [ 0 ] ) ;
176
176
} ) ;
177
+
178
+ it ( 'should discard extra instrumentation records' , ( ) => {
179
+ // Add 4 library versions and make sure that last 2 are discarded and the "nodejs" base
180
+ // library version is always added as a third one
181
+ const dummy = createEntry (
182
+ instrumentation . NODEJS_LIBRARY_NAME_PREFIX + '-one' ,
183
+ 'v1'
184
+ ) ;
185
+ dummy . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] [
186
+ instrumentation . INSTRUMENTATION_SOURCE_KEY
187
+ ] . push ( {
188
+ name : instrumentation . NODEJS_LIBRARY_NAME_PREFIX + '-two' ,
189
+ version : 'v2' ,
190
+ } ) ;
191
+ dummy . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] [
192
+ instrumentation . INSTRUMENTATION_SOURCE_KEY
193
+ ] . push ( {
194
+ name : NODEJS_TEST ,
195
+ version : VERSION_TEST ,
196
+ } ) ;
197
+ dummy . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] [
198
+ instrumentation . INSTRUMENTATION_SOURCE_KEY
199
+ ] . push ( {
200
+ name : LONG_NODEJS_TEST ,
201
+ version : LONG_VERSION_TEST ,
202
+ } ) ;
203
+ const entries = instrumentation . populateInstrumentationInfo ( dummy ) ;
204
+ assert . equal ( entries [ 0 ] . length , 1 ) ;
205
+ assert . equal (
206
+ entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
207
+ instrumentation . INSTRUMENTATION_SOURCE_KEY
208
+ ] ?. length ,
209
+ 3
210
+ ) ;
211
+ assert . equal ( true , entries [ 1 ] ) ;
212
+ assert . equal (
213
+ entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
214
+ instrumentation . INSTRUMENTATION_SOURCE_KEY
215
+ ] ?. [ 0 ] ?. [ NAME ] ,
216
+ instrumentation . NODEJS_LIBRARY_NAME_PREFIX + '-one'
217
+ ) ;
218
+ assert . equal (
219
+ entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
220
+ instrumentation . INSTRUMENTATION_SOURCE_KEY
221
+ ] ?. [ 1 ] ?. [ NAME ] ,
222
+ instrumentation . NODEJS_LIBRARY_NAME_PREFIX + '-two'
223
+ ) ;
224
+ assert . equal (
225
+ entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
226
+ instrumentation . INSTRUMENTATION_SOURCE_KEY
227
+ ] ?. [ 2 ] ?. [ NAME ] ,
228
+ instrumentation . NODEJS_LIBRARY_NAME_PREFIX
229
+ ) ;
230
+ } ) ;
177
231
} ) ;
178
232
179
233
function createEntry ( name : string | undefined , version : string | undefined ) {
0 commit comments