@@ -30,6 +30,7 @@ import {
3030 INVALID_SPAN_CONTEXT ,
3131 propagation ,
3232 ROOT_CONTEXT ,
33+ SpanStatusCode ,
3334 trace ,
3435} from '@opentelemetry/api' ;
3536import { performance } from 'perf_hooks' ;
@@ -291,13 +292,67 @@ describe('OpenTracing Shim', () => {
291292 otSpan = ( span as SpanShim ) . getSpan ( ) as Span ;
292293 } ) ;
293294
294- it ( 'sets tags' , ( ) => {
295- span . setTag ( 'hello' , 'world' ) ;
296- assert . strictEqual ( otSpan . attributes . hello , 'world' ) ;
295+ describe ( 'tags' , ( ) => {
296+ it ( 'sets tags' , ( ) => {
297+ span . setTag ( 'hello' , 'world' ) ;
298+ assert . strictEqual ( otSpan . attributes . hello , 'world' ) ;
297299
298- span . addTags ( { hello : 'stars' , from : 'earth' } ) ;
299- assert . strictEqual ( otSpan . attributes . hello , 'stars' ) ;
300- assert . strictEqual ( otSpan . attributes . from , 'earth' ) ;
300+ span . addTags ( { hello : 'stars' , from : 'earth' } ) ;
301+ assert . strictEqual ( otSpan . attributes . hello , 'stars' ) ;
302+ assert . strictEqual ( otSpan . attributes . from , 'earth' ) ;
303+ } ) ;
304+
305+ it ( 'ignores undefined tags' , ( ) => {
306+ span . addTags ( { hello : 'stars' , from : undefined } ) ;
307+ assert . deepStrictEqual ( otSpan . attributes , { hello : 'stars' } ) ;
308+ } ) ;
309+
310+ it ( 'maps error tag to status code' , ( ) => {
311+ span . setTag ( 'error' , '' ) ;
312+ assert . strictEqual ( otSpan . status . code , SpanStatusCode . UNSET ) ;
313+
314+ span . setTag ( 'error' , true ) ;
315+ assert . strictEqual ( otSpan . status . code , SpanStatusCode . ERROR ) ;
316+
317+ span . setTag ( 'error' , false ) ;
318+ assert . strictEqual ( otSpan . status . code , SpanStatusCode . OK ) ;
319+
320+ span . setTag ( 'error' , 'true' ) ;
321+ assert . strictEqual ( otSpan . status . code , SpanStatusCode . ERROR ) ;
322+
323+ span . setTag ( 'error' , 'false' ) ;
324+ assert . strictEqual ( otSpan . status . code , SpanStatusCode . OK ) ;
325+ } ) ;
326+
327+ it ( 'sets unknown error tag as attribute' , ( ) => {
328+ span . setTag ( 'error' , 'whoopsie' ) ;
329+ assert . strictEqual ( otSpan . status . code , SpanStatusCode . UNSET ) ;
330+ assert . strictEqual ( otSpan . attributes . error , 'whoopsie' ) ;
331+ } ) ;
332+
333+ it ( 'maps error tag to status code when adding multiple tags' , ( ) => {
334+ span . addTags ( { hello : 'stars' , error : '' } ) ;
335+ assert . strictEqual ( otSpan . status . code , SpanStatusCode . UNSET ) ;
336+
337+ span . addTags ( { hello : 'stars' , error : true } ) ;
338+ assert . strictEqual ( otSpan . status . code , SpanStatusCode . ERROR ) ;
339+
340+ span . addTags ( { hello : 'stars' , error : false } ) ;
341+ assert . strictEqual ( otSpan . status . code , SpanStatusCode . OK ) ;
342+
343+ span . addTags ( { hello : 'stars' , error : 'true' } ) ;
344+ assert . strictEqual ( otSpan . status . code , SpanStatusCode . ERROR ) ;
345+
346+ span . addTags ( { hello : 'stars' , error : 'false' } ) ;
347+ assert . strictEqual ( otSpan . status . code , SpanStatusCode . OK ) ;
348+ } ) ;
349+
350+ it ( 'sets unknown error tag as attribute when adding multiple tags' , ( ) => {
351+ span . addTags ( { hello : 'stars' , error : 'whoopsie' } ) ;
352+ assert . strictEqual ( otSpan . status . code , SpanStatusCode . UNSET ) ;
353+ assert . strictEqual ( otSpan . attributes . hello , 'stars' ) ;
354+ assert . strictEqual ( otSpan . attributes . error , 'whoopsie' ) ;
355+ } ) ;
301356 } ) ;
302357
303358 it ( 'logs KV pairs' , ( ) => {
0 commit comments