@@ -36,6 +36,7 @@ import {
3636import { performance } from 'perf_hooks' ;
3737import { B3Propagator } from '@opentelemetry/propagator-b3' ;
3838import { JaegerPropagator } from '@opentelemetry/propagator-jaeger' ;
39+ import { SemanticAttributes } from "@opentelemetry/semantic-conventions" ;
3940
4041describe ( 'OpenTracing Shim' , ( ) => {
4142 const compositePropagator = new CompositePropagator ( {
@@ -355,18 +356,92 @@ describe('OpenTracing Shim', () => {
355356 } ) ;
356357 } ) ;
357358
358- it ( 'logs KV pairs' , ( ) => {
359- const kvLogs = { key : 'value' , error : 'not a valid span' } ;
360- span . log ( kvLogs ) ;
361- assert . strictEqual ( otSpan . events [ 0 ] . name , 'log' ) ;
362- assert . strictEqual ( otSpan . events [ 0 ] . attributes , kvLogs ) ;
363- } ) ;
359+ describe ( 'logging' , ( ) => {
360+ describe ( 'event with payload' , ( ) => {
361+ it ( 'logs an event with a payload' , ( ) => {
362+ const payload = { user : 'payload' , request : 1 } ;
363+ span . logEvent ( 'some log' , payload ) ;
364+ assert . strictEqual ( otSpan . events [ 0 ] . name , 'some log' ) ;
365+ assert . deepStrictEqual ( otSpan . events [ 0 ] . attributes , payload ) ;
366+ } ) ;
367+
368+ it ( 'records an exception' , ( ) => {
369+ const payload = {
370+ 'error.object' : 'boom' , fault : 'meow'
371+ } ;
372+ span . logEvent ( 'error' , payload ) ;
373+ assert . strictEqual ( otSpan . events [ 0 ] . name , 'exception' ) ;
374+ const expectedAttributes = {
375+ [ SemanticAttributes . EXCEPTION_MESSAGE ] : 'boom' ,
376+ } ;
377+ assert . deepStrictEqual ( otSpan . events [ 0 ] . attributes , expectedAttributes ) ;
378+ } ) ;
379+
380+ it ( 'maps to exception semantic conventions' , ( ) => {
381+ const payload = {
382+ fault : 'meow' , 'error.kind' : 'boom' , message : 'oh no!' , stack : 'pancakes'
383+ } ;
384+ span . logEvent ( 'error' , payload ) ;
385+ assert . strictEqual ( otSpan . events [ 0 ] . name , 'exception' ) ;
386+ const expectedAttributes = {
387+ fault : 'meow' ,
388+ [ SemanticAttributes . EXCEPTION_TYPE ] : 'boom' ,
389+ [ SemanticAttributes . EXCEPTION_MESSAGE ] : 'oh no!' ,
390+ [ SemanticAttributes . EXCEPTION_STACKTRACE ] : 'pancakes'
391+ } ;
392+ assert . deepStrictEqual ( otSpan . events [ 0 ] . attributes , expectedAttributes ) ;
393+ } ) ;
394+ } ) ;
395+
396+ describe ( 'key-value pairs' , ( ) => {
397+ const tomorrow = new Date ( ) . setDate ( new Date ( ) . getDate ( ) + 1 ) ;
364398
365- it ( 'logs an event with a payload' , ( ) => {
366- const payload = { user : 'payload' , request : 1 } ;
367- span . logEvent ( 'some log' , payload ) ;
368- assert . strictEqual ( otSpan . events [ 0 ] . name , 'some log' ) ;
369- assert . deepStrictEqual ( otSpan . events [ 0 ] . attributes , payload ) ;
399+ it ( 'names event after event attribute' , ( ) => {
400+ const kvLogs = { event : 'fun-time' , user : 'meow' , value : 123 } ;
401+ span . log ( kvLogs , tomorrow ) ;
402+ assert . strictEqual ( otSpan . events [ 0 ] . name , 'fun-time' ) ;
403+ assert . strictEqual ( otSpan . events [ 0 ] . time [ 0 ] , Math . trunc ( tomorrow / 1000 ) ) ;
404+ assert . strictEqual ( otSpan . events [ 0 ] . attributes , kvLogs ) ;
405+ } ) ;
406+
407+ it ( 'names event log, as a fallback' , ( ) => {
408+ const kvLogs = { user : 'meow' , value : 123 } ;
409+ span . log ( kvLogs , tomorrow ) ;
410+ assert . strictEqual ( otSpan . events [ 0 ] . name , 'log' ) ;
411+ assert . strictEqual ( otSpan . events [ 0 ] . time [ 0 ] , Math . trunc ( tomorrow / 1000 ) ) ;
412+ assert . strictEqual ( otSpan . events [ 0 ] . attributes , kvLogs ) ;
413+ } ) ;
414+
415+ it ( 'records an exception' , ( ) => {
416+ const kvLogs = {
417+ event : 'error' , 'error.object' : 'boom' , fault : 'meow'
418+ } ;
419+ span . log ( kvLogs , tomorrow ) ;
420+ assert . strictEqual ( otSpan . events [ 0 ] . name , 'exception' ) ;
421+ assert . strictEqual ( otSpan . events [ 0 ] . time [ 0 ] , Math . trunc ( tomorrow / 1000 ) ) ;
422+ const expectedAttributes = {
423+ [ SemanticAttributes . EXCEPTION_MESSAGE ] : 'boom' ,
424+ } ;
425+ assert . deepStrictEqual ( otSpan . events [ 0 ] . attributes , expectedAttributes ) ;
426+ } ) ;
427+
428+ it ( 'maps to exception semantic conventions' , ( ) => {
429+ const kvLogs = {
430+ event : 'error' , fault : 'meow' , 'error.kind' : 'boom' , message : 'oh no!' , stack : 'pancakes'
431+ } ;
432+ span . log ( kvLogs , tomorrow ) ;
433+ assert . strictEqual ( otSpan . events [ 0 ] . name , 'exception' ) ;
434+ assert . strictEqual ( otSpan . events [ 0 ] . time [ 0 ] , Math . trunc ( tomorrow / 1000 ) ) ;
435+ const expectedAttributes = {
436+ event : 'error' ,
437+ fault : 'meow' ,
438+ [ SemanticAttributes . EXCEPTION_TYPE ] : 'boom' ,
439+ [ SemanticAttributes . EXCEPTION_MESSAGE ] : 'oh no!' ,
440+ [ SemanticAttributes . EXCEPTION_STACKTRACE ] : 'pancakes'
441+ } ;
442+ assert . deepStrictEqual ( otSpan . events [ 0 ] . attributes , expectedAttributes ) ;
443+ } ) ;
444+ } ) ;
370445 } ) ;
371446
372447 it ( 'updates the name' , ( ) => {
0 commit comments