@@ -62,6 +62,66 @@ describe('JaegerPropagation', () => {
6262 ) ;
6363 assert . deepStrictEqual ( jaegerFormat . extract ( getter ) , spanContext ) ;
6464 } ) ;
65+
66+ it ( 'should format traceId for 64Bit Hex id without leading zeros' , ( ) => {
67+ const spanContext = jaegerFormat . generate ( ) ;
68+ spanContext . traceId = '70c2f20bd65603bd' ;
69+ const getter = helperGetter (
70+ `${ spanContext . traceId } :${ spanContext . spanId } ::${ spanContext . options } `
71+ ) ;
72+ assert . deepStrictEqual ( jaegerFormat . extract ( getter ) , spanContext ) ;
73+ } ) ;
74+
75+ it ( 'should format traceId for 64Bit Hex id with leading zeros when needed' , ( ) => {
76+ const spanContext = jaegerFormat . generate ( ) ;
77+ spanContext . traceId = 'c2f20bd65603bd' ;
78+ const compareSpanContext = { ...spanContext } ;
79+ compareSpanContext . traceId = '00c2f20bd65603bd' ;
80+ const getter = helperGetter (
81+ `${ spanContext . traceId } :${ spanContext . spanId } ::${ spanContext . options } `
82+ ) ;
83+ assert . deepStrictEqual ( jaegerFormat . extract ( getter ) , compareSpanContext ) ;
84+ } ) ;
85+
86+ it ( 'should format traceId for 128Bit Hex id without leading zeros' , ( ) => {
87+ const spanContext = jaegerFormat . generate ( ) ;
88+ spanContext . traceId = '929985345ae64c35acddd590f13ffc82' ;
89+ const getter = helperGetter (
90+ `${ spanContext . traceId } :${ spanContext . spanId } ::${ spanContext . options } `
91+ ) ;
92+ assert . deepStrictEqual ( jaegerFormat . extract ( getter ) , spanContext ) ;
93+ } ) ;
94+
95+ it ( 'should format traceId for 128Bit Hex id with leading zeros when needed' , ( ) => {
96+ const spanContext = jaegerFormat . generate ( ) ;
97+ spanContext . traceId = '9985345ae64c35acddd590f13ffc82' ;
98+ const compareSpanContext = { ...spanContext } ;
99+ compareSpanContext . traceId = '009985345ae64c35acddd590f13ffc82' ;
100+ const getter = helperGetter (
101+ `${ spanContext . traceId } :${ spanContext . spanId } ::${ spanContext . options } `
102+ ) ;
103+ assert . deepStrictEqual ( jaegerFormat . extract ( getter ) , compareSpanContext ) ;
104+ } ) ;
105+ } ) ;
106+
107+ it ( 'should format spanId without leading zeros' , ( ) => {
108+ const spanContext = jaegerFormat . generate ( ) ;
109+ spanContext . spanId = '70c2f20bd65603bd' ;
110+ const getter = helperGetter (
111+ `${ spanContext . traceId } :${ spanContext . spanId } ::${ spanContext . options } `
112+ ) ;
113+ assert . deepStrictEqual ( jaegerFormat . extract ( getter ) , spanContext ) ;
114+ } ) ;
115+
116+ it ( 'should format spanId with leading zeros when needed' , ( ) => {
117+ const spanContext = jaegerFormat . generate ( ) ;
118+ spanContext . spanId = 'c2f20bd65603bd' ;
119+ const compareSpanContext = { ...spanContext } ;
120+ compareSpanContext . spanId = '00c2f20bd65603bd' ;
121+ const getter = helperGetter (
122+ `${ spanContext . traceId } :${ spanContext . spanId } ::${ spanContext . options } `
123+ ) ;
124+ assert . deepStrictEqual ( jaegerFormat . extract ( getter ) , compareSpanContext ) ;
65125 } ) ;
66126
67127 describe ( 'inject' , ( ) => {
@@ -104,6 +164,50 @@ describe('JaegerPropagation', () => {
104164 jaegerFormat . inject ( setter , emptySpanContext ) ;
105165 assert . deepStrictEqual ( jaegerFormat . extract ( getter ) , null ) ;
106166 } ) ;
167+
168+ it ( 'should inject spancontext with 64Bit traceID' , ( ) => {
169+ const spanContext = {
170+ traceId : '70c2f20bd65603bd' ,
171+ spanId : '5ba4ceca5d0edd4c' ,
172+ options : SAMPLED_VALUE ,
173+ } ;
174+ const headers : { [ key : string ] : string | string [ ] | undefined } = { } ;
175+ const setter : HeaderSetter = {
176+ setHeader ( name : string , value : string ) {
177+ headers [ name ] = value ;
178+ } ,
179+ } ;
180+ const getter : HeaderGetter = {
181+ getHeader ( name : string ) {
182+ return headers [ name ] ;
183+ } ,
184+ } ;
185+
186+ jaegerFormat . inject ( setter , spanContext ) ;
187+ assert . deepStrictEqual ( jaegerFormat . extract ( getter ) , spanContext ) ;
188+ } ) ;
189+
190+ it ( 'should inject spancontext with 128Bit traceID' , ( ) => {
191+ const spanContext = {
192+ traceId : '929985345ae64c35acddd590f13ffc82' ,
193+ spanId : '5ba4ceca5d0edd4c' ,
194+ options : SAMPLED_VALUE ,
195+ } ;
196+ const headers : { [ key : string ] : string | string [ ] | undefined } = { } ;
197+ const setter : HeaderSetter = {
198+ setHeader ( name : string , value : string ) {
199+ headers [ name ] = value ;
200+ } ,
201+ } ;
202+ const getter : HeaderGetter = {
203+ getHeader ( name : string ) {
204+ return headers [ name ] ;
205+ } ,
206+ } ;
207+
208+ jaegerFormat . inject ( setter , spanContext ) ;
209+ assert . deepStrictEqual ( jaegerFormat . extract ( getter ) , spanContext ) ;
210+ } ) ;
107211 } ) ;
108212
109213 // Same test as propagation-stackdriver.
0 commit comments