File tree Expand file tree Collapse file tree 4 files changed +25
-2
lines changed
exporter/opentelemetry-exporter-prometheus
src/opentelemetry/exporter/prometheus Expand file tree Collapse file tree 4 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 10
10
# Otherwise, set variable to the commit of your branch on
11
11
# opentelemetry-python-contrib which is compatible with these Core repo
12
12
# changes.
13
- CONTRIB_REPO_SHA : 3c2788469834aa4f5976e1644d757f43d60bc219
13
+ CONTRIB_REPO_SHA : 9ce1c26d2732dfbdadbb492fc38c562dcd08ed2e
14
14
# This is needed because we do not clone the core repo in contrib builds anymore.
15
15
# When running contrib builds as part of core builds, we use actions/checkout@v2 which
16
16
# does not set an environment variable (simply just runs tox), which is different when
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
19
([ #3785 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/3785 ) )
20
20
- Add capture the fully qualified type name for raised exceptions in spans
21
21
([ #3837 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/3837 ) )
22
+ - Prometheus exporter sort label keys to prevent duplicate metrics when user input changes order
23
+ ([ #3698 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/3698 ) )
22
24
23
25
## Version 1.24.0/0.45b0 (2024-03-28)
24
26
Original file line number Diff line number Diff line change @@ -237,7 +237,7 @@ def _translate_to_prometheus(
237
237
label_keys = []
238
238
label_values = []
239
239
240
- for key , value in number_data_point .attributes .items ():
240
+ for key , value in sorted ( number_data_point .attributes .items () ):
241
241
label_keys .append (self ._sanitize (key ))
242
242
label_values .append (self ._check_value (value ))
243
243
Original file line number Diff line number Diff line change @@ -436,3 +436,24 @@ def test_target_info_sanitize(self):
436
436
prometheus_metric .samples [0 ].labels ["ratio" ],
437
437
"0.1" ,
438
438
)
439
+
440
+ def test_label_order_does_not_matter (self ):
441
+ metric_reader = PrometheusMetricReader ()
442
+ provider = MeterProvider (metric_readers = [metric_reader ])
443
+ meter = provider .get_meter ("getting-started" , "0.1.2" )
444
+ counter = meter .create_counter ("counter" )
445
+
446
+ counter .add (1 , {"cause" : "cause1" , "reason" : "reason1" })
447
+ counter .add (1 , {"reason" : "reason2" , "cause" : "cause2" })
448
+
449
+ prometheus_output = generate_latest ().decode ()
450
+
451
+ # All labels are mapped correctly
452
+ self .assertIn ('cause="cause1"' , prometheus_output )
453
+ self .assertIn ('cause="cause2"' , prometheus_output )
454
+ self .assertIn ('reason="reason1"' , prometheus_output )
455
+ self .assertIn ('reason="reason2"' , prometheus_output )
456
+
457
+ # Only one metric is generated
458
+ metric_count = prometheus_output .count ("# HELP counter_total" )
459
+ self .assertEqual (metric_count , 1 )
You can’t perform that action at this time.
0 commit comments