File tree Expand file tree Collapse file tree 2 files changed +58
-4
lines changed Expand file tree Collapse file tree 2 files changed +58
-4
lines changed Original file line number Diff line number Diff line change @@ -249,43 +249,43 @@ module.exports = class PrometheusMetricsConsumer extends Writable {
249249 this . histogram ( metric ) ;
250250 } catch ( err ) {
251251 this . logger . error (
252+ err ,
252253 `failed to generate prometheus histogram for metric "${ JSON . stringify (
253254 metric ,
254255 ) } "`,
255- err ,
256256 ) ;
257257 }
258258 } else if ( this . typeFor ( metric ) === metricTypes . GAUGE ) {
259259 try {
260260 this . gauge ( metric ) ;
261261 } catch ( err ) {
262262 this . logger . error (
263+ err ,
263264 `failed to generate prometheus gauge for metric "${ JSON . stringify (
264265 metric ,
265266 ) } "`,
266- err ,
267267 ) ;
268268 }
269269 } else if ( this . typeFor ( metric ) === metricTypes . SUMMARY ) {
270270 try {
271271 this . summary ( metric ) ;
272272 } catch ( err ) {
273273 this . logger . error (
274+ err ,
274275 `failed to generate prometheus summary metric for "${ JSON . stringify (
275276 metric ,
276277 ) } "`,
277- err ,
278278 ) ;
279279 }
280280 } else {
281281 try {
282282 this . counter ( metric ) ;
283283 } catch ( err ) {
284284 this . logger . error (
285+ err ,
285286 `failed to generate prometheus counter for metric "${ JSON . stringify (
286287 metric ,
287288 ) } "`,
288- err ,
289289 ) ;
290290 }
291291 }
Original file line number Diff line number Diff line change @@ -545,3 +545,57 @@ test('should have correct bucket count', (t) => {
545545
546546 source . pipe ( consumer ) ;
547547} ) ;
548+
549+ test ( 'should log errors according to abslog contract' , ( t ) => {
550+ let errObject ;
551+ let errMsg = '' ;
552+ const log = ( ) => { } ;
553+ const err = ( obj , msg ) => {
554+ errObject = obj ;
555+ errMsg = msg ;
556+ } ;
557+
558+ const mockLogger = {
559+ trace : log ,
560+ debug : log ,
561+ info : log ,
562+ warn : log ,
563+ error : err ,
564+ fatal : log ,
565+ } ;
566+ const consumer = new PrometheusMetricsConsumer ( {
567+ logger : mockLogger ,
568+ client : promClient ,
569+ } ) ;
570+
571+ const source = src ( [
572+ { } ,
573+ '' ,
574+ { name : 'test' } ,
575+ new Metric ( {
576+ name : 'test3' ,
577+ description : '.' ,
578+ labels : [ { name : 'label3' , value : 'one' } ] ,
579+ value : 1 ,
580+ type : 2 ,
581+ } ) ,
582+ new Metric ( {
583+ name : 'test3' ,
584+ description : '.' ,
585+ labels : [
586+ { name : 'label3' , value : 'one' } ,
587+ { name : 'label4' , value : 'two' } ,
588+ ] ,
589+ value : 1 ,
590+ type : 2 ,
591+ } ) ,
592+ ] ) ;
593+
594+ consumer . on ( 'finish' , ( ) => {
595+ t . match ( errObject , / E r r o r / ) ;
596+ t . match ( errMsg , 'failed to generate prometheus counter for metric' ) ;
597+ t . end ( ) ;
598+ } ) ;
599+
600+ source . pipe ( consumer ) ;
601+ } ) ;
You can’t perform that action at this time.
0 commit comments