@@ -88,7 +88,7 @@ describe('instrumentation_info', () => {
8888 ) ;
8989 } ) ;
9090
91- it ( 'should add instrumentation info to existing list' , ( ) => {
91+ it ( 'should add instrumentation info to existing list in right order ' , ( ) => {
9292 const dummyEntry = createEntry ( NODEJS_TEST , VERSION_TEST ) ;
9393 const entries = instrumentation . populateInstrumentationInfo ( dummyEntry ) ;
9494 assert . equal ( entries [ 0 ] . length , 1 ) ;
@@ -102,19 +102,19 @@ describe('instrumentation_info', () => {
102102 assert . equal (
103103 entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
104104 instrumentation . INSTRUMENTATION_SOURCE_KEY
105- ] ?. [ 0 ] ?. [ NAME ] ,
105+ ] ?. [ 1 ] ?. [ NAME ] ,
106106 instrumentation . NODEJS_LIBRARY_NAME_PREFIX
107107 ) ;
108108 assert . equal (
109109 entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
110110 instrumentation . INSTRUMENTATION_SOURCE_KEY
111- ] ?. [ 1 ] ?. [ NAME ] ,
111+ ] ?. [ 0 ] ?. [ NAME ] ,
112112 NODEJS_TEST
113113 ) ;
114114 assert . equal (
115115 entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
116116 instrumentation . INSTRUMENTATION_SOURCE_KEY
117- ] ?. [ 1 ] ?. [ VERSION ] ,
117+ ] ?. [ 0 ] ?. [ VERSION ] ,
118118 VERSION_TEST
119119 ) ;
120120 } ) ;
@@ -147,13 +147,13 @@ describe('instrumentation_info', () => {
147147 assert . equal (
148148 entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
149149 instrumentation . INSTRUMENTATION_SOURCE_KEY
150- ] ?. [ 1 ] ?. [ NAME ] ,
150+ ] ?. [ 0 ] ?. [ NAME ] ,
151151 NODEJS_TEST + '-oo*'
152152 ) ;
153153 assert . equal (
154154 entries [ 0 ] [ 0 ] . data ?. [ instrumentation . DIAGNOSTIC_INFO_KEY ] ?. [
155155 instrumentation . INSTRUMENTATION_SOURCE_KEY
156- ] ?. [ 1 ] ?. [ VERSION ] ,
156+ ] ?. [ 0 ] ?. [ VERSION ] ,
157157 VERSION_TEST + '.0.0.0.0.*'
158158 ) ;
159159 } ) ;
@@ -174,6 +174,60 @@ describe('instrumentation_info', () => {
174174 assert . equal ( entries [ 0 ] . length , 1 ) ;
175175 assert . deepEqual ( dummyEntry , entries [ 0 ] [ 0 ] ) ;
176176 } ) ;
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+ } ) ;
177231} ) ;
178232
179233function createEntry ( name : string | undefined , version : string | undefined ) {
0 commit comments