88 "github.com/prometheus/client_golang/prometheus"
99 "go.uber.org/zap"
1010
11+ "github.com/Suhaibinator/SRouter/pkg/logkeys"
1112 srouter_metrics "github.com/Suhaibinator/SRouter/pkg/metrics"
1213)
1314
@@ -106,7 +107,7 @@ func (b *PrometheusCounterBuilder) Build() srouter_metrics.Counter {
106107 // and Build can be called from the request path, so never panic.
107108 // The metric still works locally; it just won't be exported.
108109 b .registry .logger .Error ("Failed to register Prometheus counter; metric will not be exported" ,
109- zap .String ("metric_name" , b .opts .Name ), zap .Error ( err ))
110+ zap .String (logkeys . MetricName , b .opts .Name ), zap .NamedError ( logkeys . Error , err ))
110111 }
111112 }
112113 tags := make (srouter_metrics.Tags , len (b .opts .ConstLabels ))
@@ -120,7 +121,7 @@ func (b *PrometheusCounterBuilder) Build() srouter_metrics.Counter {
120121 } else {
121122 // Never panic in the request path; keep the unregistered metric.
122123 b .registry .logger .Error ("Failed to register Prometheus counter; metric will not be exported" ,
123- zap .String ("metric_name" , b .opts .Name ), zap .Error ( err ))
124+ zap .String (logkeys . MetricName , b .opts .Name ), zap .NamedError ( logkeys . Error , err ))
124125 }
125126 }
126127 tags := make (srouter_metrics.Tags , len (b .opts .ConstLabels ))
@@ -188,7 +189,7 @@ func (b *PrometheusGaugeBuilder) Build() srouter_metrics.Gauge {
188189 } else {
189190 // Never panic in the request path; keep the unregistered metric.
190191 b .registry .logger .Error ("Failed to register Prometheus gauge; metric will not be exported" ,
191- zap .String ("metric_name" , b .opts .Name ), zap .Error ( err ))
192+ zap .String (logkeys . MetricName , b .opts .Name ), zap .NamedError ( logkeys . Error , err ))
192193 }
193194 }
194195 tags := make (srouter_metrics.Tags , len (b .opts .ConstLabels ))
@@ -202,7 +203,7 @@ func (b *PrometheusGaugeBuilder) Build() srouter_metrics.Gauge {
202203 } else {
203204 // Never panic in the request path; keep the unregistered metric.
204205 b .registry .logger .Error ("Failed to register Prometheus gauge; metric will not be exported" ,
205- zap .String ("metric_name" , b .opts .Name ), zap .Error ( err ))
206+ zap .String (logkeys . MetricName , b .opts .Name ), zap .NamedError ( logkeys . Error , err ))
206207 }
207208 }
208209 tags := make (srouter_metrics.Tags , len (b .opts .ConstLabels ))
@@ -279,7 +280,7 @@ func (b *PrometheusHistogramBuilder) Build() srouter_metrics.Histogram {
279280 } else {
280281 // Never panic in the request path; keep the unregistered metric.
281282 b .registry .logger .Error ("Failed to register Prometheus histogram; metric will not be exported" ,
282- zap .String ("metric_name" , b .opts .Name ), zap .Error ( err ))
283+ zap .String (logkeys . MetricName , b .opts .Name ), zap .NamedError ( logkeys . Error , err ))
283284 }
284285 }
285286 tags := make (srouter_metrics.Tags , len (b .opts .ConstLabels ))
@@ -293,7 +294,7 @@ func (b *PrometheusHistogramBuilder) Build() srouter_metrics.Histogram {
293294 } else {
294295 // Never panic in the request path; keep the unregistered metric.
295296 b .registry .logger .Error ("Failed to register Prometheus histogram; metric will not be exported" ,
296- zap .String ("metric_name" , b .opts .Name ), zap .Error ( err ))
297+ zap .String (logkeys . MetricName , b .opts .Name ), zap .NamedError ( logkeys . Error , err ))
297298 }
298299 }
299300 tags := make (srouter_metrics.Tags , len (b .opts .ConstLabels ))
@@ -357,15 +358,15 @@ func (b *PrometheusSummaryBuilder) MaxAge(age time.Duration) srouter_metrics.Sum
357358func (b * PrometheusSummaryBuilder ) AgeBuckets (buckets int ) srouter_metrics.SummaryBuilder {
358359 if buckets < 0 {
359360 b .registry .logger .Warn ("Invalid negative value provided for AgeBuckets, defaulting to 0" ,
360- zap .Int ("provided_buckets" , buckets ),
361- zap .String ("metric_name" , b .opts .Name ),
361+ zap .Int (logkeys . ProvidedBuckets , buckets ),
362+ zap .String (logkeys . MetricName , b .opts .Name ),
362363 )
363364 b .opts .AgeBuckets = 0
364365 } else if buckets > math .MaxUint32 {
365366 b .registry .logger .Warn ("Value provided for AgeBuckets exceeds MaxUint32, clamping" ,
366- zap .Int ("provided_buckets" , buckets ),
367- zap .Uint32 ("clamped_value" , math .MaxUint32 ),
368- zap .String ("metric_name" , b .opts .Name ),
367+ zap .Int (logkeys . ProvidedBuckets , buckets ),
368+ zap .Uint32 (logkeys . ClampedValue , math .MaxUint32 ),
369+ zap .String (logkeys . MetricName , b .opts .Name ),
369370 )
370371 b .opts .AgeBuckets = math .MaxUint32
371372 } else {
@@ -403,7 +404,7 @@ func (b *PrometheusSummaryBuilder) Build() srouter_metrics.Summary {
403404 } else {
404405 // Never panic in the request path; keep the unregistered metric.
405406 b .registry .logger .Error ("Failed to register Prometheus summary; metric will not be exported" ,
406- zap .String ("metric_name" , b .opts .Name ), zap .Error ( err ))
407+ zap .String (logkeys . MetricName , b .opts .Name ), zap .NamedError ( logkeys . Error , err ))
407408 }
408409 }
409410 tags := make (srouter_metrics.Tags , len (b .opts .ConstLabels ))
@@ -417,7 +418,7 @@ func (b *PrometheusSummaryBuilder) Build() srouter_metrics.Summary {
417418 } else {
418419 // Never panic in the request path; keep the unregistered metric.
419420 b .registry .logger .Error ("Failed to register Prometheus summary; metric will not be exported" ,
420- zap .String ("metric_name" , b .opts .Name ), zap .Error ( err ))
421+ zap .String (logkeys . MetricName , b .opts .Name ), zap .NamedError ( logkeys . Error , err ))
421422 }
422423 }
423424 tags := make (srouter_metrics.Tags , len (b .opts .ConstLabels ))
0 commit comments