@@ -11,45 +11,45 @@ const LOG_SEVERITY_ATTRIBUTE = 'log.severity'
1111const LOG_MESSAGE_ATTRIBUTE = 'log.message'
1212
1313interface SpanTestScenario {
14- description : string ;
15- samplingConfig : SamplingConfig ;
14+ description : string
15+ samplingConfig : SamplingConfig
1616 inputSpan : {
17- name : string ;
18- attributes ?: Record < string , any > ;
17+ name : string
18+ attributes ?: Record < string , any >
1919 events ?: Array < {
20- name : string ;
21- attributes ?: Record < string , any > ;
22- } > ;
23- } ;
20+ name : string
21+ attributes ?: Record < string , any >
22+ } >
23+ }
2424 inputLog ?: {
25- message ?: string ;
26- attributes ?: Record < string , any > ;
27- severityText ?: string ;
28- } ;
25+ message ?: string
26+ attributes ?: Record < string , any >
27+ severityText ?: string
28+ }
2929 samplerFunctionCases : Array < {
30- type : 'always' | 'never' ;
30+ type : 'always' | 'never'
3131 expected_result : {
32- sample : boolean ;
33- attributes : Record < string , any > | null ;
34- } ;
35- } > ;
32+ sample : boolean
33+ attributes : Record < string , any > | null
34+ }
35+ } >
3636}
3737
3838interface LogTestScenario {
39- description : string ;
40- samplingConfig : SamplingConfig ;
39+ description : string
40+ samplingConfig : SamplingConfig
4141 inputLog : {
42- message ?: string ;
43- attributes ?: Record < string , any > ;
44- severityText ?: string ;
45- } ;
42+ message ?: string
43+ attributes ?: Record < string , any >
44+ severityText ?: string
45+ }
4646 samplerFunctionCases : Array < {
47- type : 'always' | 'never' ;
47+ type : 'always' | 'never'
4848 expected_result : {
49- sample : boolean ;
50- attributes : Record < string , any > | null ;
51- } ;
52- } > ;
49+ sample : boolean
50+ attributes : Record < string , any > | null
51+ }
52+ } >
5353}
5454
5555// Test helper function that always returns true for sampling
@@ -97,7 +97,7 @@ const createMockSpan = ({
9797 endTime : [ 0 , 0 ] ,
9898 status : { code : 0 } ,
9999 links : [ ] ,
100- events : events . map ( e => ( {
100+ events : events . map ( ( e ) => ( {
101101 name : e . name ,
102102 attributes : e . attributes || { } ,
103103 time : e . time || [ 0 , 0 ] ,
@@ -121,8 +121,8 @@ beforeEach(() => {
121121} )
122122
123123const runTestSpanScenarios = ( scenarios : SpanTestScenario [ ] ) => {
124- scenarios . forEach ( scenario => {
125- scenario . samplerFunctionCases . forEach ( samplerCase => {
124+ scenarios . forEach ( ( scenario ) => {
125+ scenario . samplerFunctionCases . forEach ( ( samplerCase ) => {
126126 const samplerFn = samplerFunctions [ samplerCase . type ]
127127
128128 it ( `${ scenario . description } - ${ samplerCase . type } ` , ( ) => {
@@ -132,15 +132,17 @@ const runTestSpanScenarios = (scenarios: SpanTestScenario[]) => {
132132 const mockSpan = createMockSpan ( {
133133 name : scenario . inputSpan . name ,
134134 attributes : scenario . inputSpan . attributes || { } ,
135- events : scenario . inputSpan . events || [ ]
135+ events : scenario . inputSpan . events || [ ] ,
136136 } )
137137
138138 const result = sampler . shouldSample ( mockSpan )
139139
140140 expect ( result . sample ) . toBe ( samplerCase . expected_result . sample )
141141
142142 if ( samplerCase . expected_result . attributes ) {
143- expect ( result . attributes ) . toEqual ( samplerCase . expected_result . attributes )
143+ expect ( result . attributes ) . toEqual (
144+ samplerCase . expected_result . attributes ,
145+ )
144146 } else {
145147 expect ( result . attributes ) . toBeUndefined ( )
146148 }
@@ -150,28 +152,34 @@ const runTestSpanScenarios = (scenarios: SpanTestScenario[]) => {
150152}
151153
152154const runTestLogScenarios = ( scenarios : LogTestScenario [ ] ) => {
153- scenarios . forEach ( scenario => {
154- scenario . samplerFunctionCases . forEach ( samplerCase => {
155+ scenarios . forEach ( ( scenario ) => {
156+ scenario . samplerFunctionCases . forEach ( ( samplerCase ) => {
155157 const samplerFn = samplerFunctions [ samplerCase . type ]
156158
157159 it ( `${ scenario . description } - ${ samplerCase . type } ` , ( ) => {
158160 const config = scenario . samplingConfig as SamplingConfig
159161 const sampler = new CustomSampler ( config , samplerFn )
160162
161- const baseAttributes = scenario . inputLog . attributes || { } ;
162- const mergedAttributes = { ...baseAttributes , [ LOG_MESSAGE_ATTRIBUTE ] : scenario . inputLog . message , [ LOG_SEVERITY_ATTRIBUTE ] : scenario . inputLog . severityText }
163+ const baseAttributes = scenario . inputLog . attributes || { }
164+ const mergedAttributes = {
165+ ...baseAttributes ,
166+ [ LOG_MESSAGE_ATTRIBUTE ] : scenario . inputLog . message ,
167+ [ LOG_SEVERITY_ATTRIBUTE ] : scenario . inputLog . severityText ,
168+ }
163169
164170 const mockSpan = createMockSpan ( {
165171 name : LOG_SPAN_NAME ,
166- attributes : mergedAttributes
172+ attributes : mergedAttributes ,
167173 } )
168174
169175 const result = sampler . shouldSample ( mockSpan )
170176
171177 expect ( result . sample ) . toBe ( samplerCase . expected_result . sample )
172178
173179 if ( samplerCase . expected_result . attributes ) {
174- expect ( result . attributes ) . toEqual ( samplerCase . expected_result . attributes )
180+ expect ( result . attributes ) . toEqual (
181+ samplerCase . expected_result . attributes ,
182+ )
175183 } else {
176184 expect ( result . attributes ) . toBeUndefined ( )
177185 }
0 commit comments