@@ -175,7 +175,7 @@ describe('OpenCensus Agent Exporter', () => {
175175 tracing = nodeTracing . start ( {
176176 exporter : ocAgentExporter ,
177177 samplingRate : INITIAL_SAMPLER_PROBABILITY ,
178- traceParams : { numberOfAttributesPerSpan : 4 }
178+ traceParams : { numberOfAttributesPerSpan : 4 , numberOfLinksPerSpan : 3 }
179179 } ) ;
180180 } ) ;
181181
@@ -345,7 +345,7 @@ describe('OpenCensus Agent Exporter', () => {
345345 rootSpan . addAnnotation (
346346 'my_annotation' , { myString : 'bar' , myNumber : 123 , myBoolean : true } ) ;
347347
348- // Metric Event
348+ // Message Event
349349 const timeStamp = 123456789 ;
350350 rootSpan . addMessageEvent ( 'MessageEventTypeSent' , 'ffff' , timeStamp ) ;
351351 rootSpan . addMessageEvent ( 'MessageEventTypeRecv' , 'ffff' , timeStamp ) ;
@@ -354,6 +354,8 @@ describe('OpenCensus Agent Exporter', () => {
354354 rootSpan . addMessageEvent ( null as any , 'ffff' , timeStamp ) ;
355355
356356 // Links
357+ rootSpan . addLink ( 'aaaaa' , 'aaa' , 'CHILD_LINKED_SPAN' ) ;
358+ rootSpan . addLink ( 'bbbbb' , 'bbbbb' , 'CHILD_LINKED_SPAN' ) ;
357359 rootSpan . addLink ( 'ffff' , 'ffff' , 'CHILD_LINKED_SPAN' , {
358360 'child_link_attribute_string' : 'foo1' ,
359361 'child_link_attribute_number' : 123 ,
@@ -476,7 +478,7 @@ describe('OpenCensus Agent Exporter', () => {
476478 // Links
477479 const buff = Buffer . from ( [ 255 , 255 ] ) ;
478480 assert . deepEqual ( span . links , {
479- droppedLinksCount : 0 ,
481+ droppedLinksCount : 2 ,
480482 link : [
481483 {
482484 type : 'CHILD_LINKED_SPAN' ,
@@ -517,4 +519,175 @@ describe('OpenCensus Agent Exporter', () => {
517519 rootSpan . end ( ) ;
518520 } ) ;
519521 } ) ;
522+
523+ it ( 'should adapt a span correctly without overflowing trace param limits' ,
524+ ( done ) => {
525+ const rootSpanOptions : TraceOptions = {
526+ name : 'root' ,
527+ kind : 'SERVER' ,
528+ spanContext : {
529+ traceId : hexId ( ) ,
530+ spanId : hexId ( ) ,
531+ traceState : 'foo=bar,baz=buzz' ,
532+ options : 0x1
533+ }
534+ } ;
535+
536+ tracing . tracer . startRootSpan ( rootSpanOptions , ( rootSpan : RootSpan ) => {
537+ // Status
538+ rootSpan . setStatus ( CanonicalCode . OK ) ;
539+
540+ // Attribute
541+ rootSpan . addAttribute ( 'my_first_attribute' , 'foo' ) ;
542+ rootSpan . addAttribute ( 'my_second_attribute' , 'foo2' ) ;
543+
544+ // Annotation
545+ rootSpan . addAnnotation (
546+ 'my_annotation' ,
547+ { myString : 'bar' , myNumber : 123 , myBoolean : true } ) ;
548+
549+ // Message Event
550+ const timeStamp = 123456789 ;
551+ rootSpan . addMessageEvent ( 'MessageEventTypeSent' , 'ffff' , timeStamp ) ;
552+ rootSpan . addMessageEvent ( 'MessageEventTypeRecv' , 'ffff' , timeStamp ) ;
553+
554+ // Links
555+ rootSpan . addLink ( 'ffff' , 'ffff' , 'CHILD_LINKED_SPAN' , {
556+ 'child_link_attribute_string' : 'foo1' ,
557+ 'child_link_attribute_number' : 123 ,
558+ 'child_link_attribute_boolean' : true ,
559+ } ) ;
560+ rootSpan . addLink ( 'ffff' , 'ffff' , 'PARENT_LINKED_SPAN' ) ;
561+
562+ server . on (
563+ MockAgentEvent . ExportStreamMessageReceived ,
564+ ( message : opencensus . proto . agent . trace . v1
565+ . ExportTraceServiceRequest ) => {
566+ assert . equal ( message . spans . length , 1 ) ;
567+ const span = message . spans [ 0 ] ;
568+ // Name / Context
569+ if ( ! span . name ) {
570+ assert . fail ( 'span.name is null or undefined' ) ;
571+ return ;
572+ }
573+ assert . equal ( span . name . value , 'root' ) ;
574+ assert . equal ( span . kind , 'SERVER' ) ;
575+
576+ if ( ! span . tracestate ) {
577+ assert . fail ( 'span.tracestate is null or undefined' ) ;
578+ return ;
579+ }
580+ assert . deepEqual (
581+ span . tracestate . entries ,
582+ [ { key : 'foo' , value : 'bar' } , { key : 'baz' , value : 'buzz' } ] ) ;
583+
584+ if ( ! span . status ) {
585+ assert . fail ( 'span.status is null or undefined' ) ;
586+ } else {
587+ assert . deepEqual ( span . status , { code : 0 , message : '' } ) ;
588+ }
589+
590+ // Attributes
591+ if ( ! span . attributes ) {
592+ assert . fail ( 'span.attributes is null or undefined' ) ;
593+ return ;
594+ }
595+ assert . deepEqual ( span . attributes . attributeMap , {
596+ my_first_attribute : {
597+ value : 'stringValue' ,
598+ stringValue : { value : 'foo' , truncatedByteCount : 0 }
599+ } ,
600+ my_second_attribute : {
601+ value : 'stringValue' ,
602+ stringValue : { value : 'foo2' , truncatedByteCount : 0 }
603+ }
604+ } ) ;
605+ assert . equal ( span . attributes . droppedAttributesCount , 0 ) ;
606+
607+ // Time Events
608+ assert . deepEqual ( span . timeEvents , {
609+ droppedAnnotationsCount : 0 ,
610+ droppedMessageEventsCount : 0 ,
611+ timeEvent : [
612+ {
613+ value : 'annotation' ,
614+ time : null ,
615+ annotation : {
616+ description :
617+ { value : 'my_annotation' , truncatedByteCount : 0 } ,
618+ attributes : {
619+ attributeMap : {
620+ myString : {
621+ value : 'stringValue' ,
622+ stringValue :
623+ { value : 'bar' , truncatedByteCount : 0 }
624+ } ,
625+ myNumber : { value : 'intValue' , intValue : '123' } ,
626+ myBoolean : { value : 'boolValue' , boolValue : true }
627+ } ,
628+ droppedAttributesCount : 0
629+ }
630+ }
631+ } ,
632+ {
633+ messageEvent : {
634+ compressedSize : '0' ,
635+ id : '65535' ,
636+ type : 'SENT' ,
637+ uncompressedSize : '0'
638+ } ,
639+ time : { seconds : '123456' , nanos : 789000000 } ,
640+ value : 'messageEvent'
641+ } ,
642+ {
643+ value : 'messageEvent' ,
644+ messageEvent : {
645+ compressedSize : '0' ,
646+ id : '65535' ,
647+ type : 'RECEIVED' ,
648+ uncompressedSize : '0'
649+ } ,
650+ time : { seconds : '123456' , nanos : 789000000 } ,
651+ }
652+ ]
653+ } ) ;
654+
655+ // Links
656+ const buff = Buffer . from ( [ 255 , 255 ] ) ;
657+ assert . deepEqual ( span . links , {
658+ droppedLinksCount : 0 ,
659+ link : [
660+ {
661+ type : 'CHILD_LINKED_SPAN' ,
662+ traceId : buff ,
663+ spanId : buff ,
664+ attributes : {
665+ droppedAttributesCount : 0 ,
666+ attributeMap : {
667+ child_link_attribute_string : {
668+ value : 'stringValue' ,
669+ stringValue : { value : 'foo1' , truncatedByteCount : 0 }
670+ } ,
671+ child_link_attribute_number :
672+ { value : 'intValue' , intValue : '123' } ,
673+ child_link_attribute_boolean :
674+ { value : 'boolValue' , boolValue : true }
675+ }
676+ }
677+ } ,
678+ {
679+ type : 'PARENT_LINKED_SPAN' ,
680+ traceId : buff ,
681+ spanId : buff ,
682+ attributes : null
683+ }
684+ ]
685+ } ) ;
686+
687+ done ( ) ;
688+ } ) ;
689+
690+ rootSpan . end ( ) ;
691+ } ) ;
692+ } ) ;
520693} ) ;
0 commit comments