opentelemetry-go/exporters/prometheus/testdata
David Ashpole 8e6e28f962
Migrate prometheus exporter to otlptranslator (#7044)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/7039
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/6704

This uses the common prometheus/otlptranslator library to handle name
conversion. It was a little tricky to work around the fact that the
library only lets us configure whether all suffixes are added or not.
But we want to keep supporting WithoutUnit and WithoutCounterSuffixes
for a while longer. Those will eventually be deprecated and replaced
after
https://github.com/open-telemetry/opentelemetry-specification/pull/4533
is released.

We decided to go ahead with the changes despite it being a small
behavioral change when UTF8 is enabled. See:
https://github.com/prometheus/otlptranslator/issues/44 for the
rationale.

This adds a unit test to verify that it properly handles bracketed
units. The test fails on main with:

```
--- FAIL: TestPrometheusExporter (0.01s)
    --- FAIL: TestPrometheusExporter/counter_with_bracketed_unit (0.00s)
        exporter_test.go:646:
            	Error Trace:	/usr/local/google/home/dashpole/go/src/go.opentelemetry.io/opentelemetry-go/exporters/prometheus/exporter_test.go:646
            	Error:      	Received unexpected error:
            	            	-# HELP "foo_{spans}_total" a simple counter
            	            	-# TYPE "foo_{spans}_total" counter
            	            	-{"foo_{spans}_total",A="B",C="D",E="true",F="42",otel_scope_fizz="buzz",otel_scope_name="testmeter",otel_scope_schema_url="",otel_scope_version="v0.1.0"} 24.3
            	            	-{"foo_{spans}_total",A="D",C="B",E="true",F="42",otel_scope_fizz="buzz",otel_scope_name="testmeter",otel_scope_schema_url="",otel_scope_version="v0.1.0"} 5
            	            	+# HELP foo_total a simple counter
            	            	+# TYPE foo_total counter
            	            	+foo_total{A="B",C="D",E="true",F="42",otel_scope_fizz="buzz",otel_scope_name="testmeter",otel_scope_schema_url="",otel_scope_version="v0.1.0"} 24.3
            	            	+foo_total{A="D",C="B",E="true",F="42",otel_scope_fizz="buzz",otel_scope_name="testmeter",otel_scope_schema_url="",otel_scope_version="v0.1.0"} 5
            	            	 # HELP target_info Target metadata
            	            	 # TYPE target_info gauge
            	            	 target_info{"service.name"="prometheus_test","telemetry.sdk.language"="go","telemetry.sdk.name"="opentelemetry","telemetry.sdk.version"="latest"} 1

            	Test:       	TestPrometheusExporter/counter_with_bracketed_unit
2025/07/18 15:07:47 internal_logging.go:50: "msg"="Using existing type definition." "error"="instrument type conflict" "instrument"="foo_total" "existing"="COUNTER" "dropped"="GAUGE"
2025/07/18 15:07:47 internal_logging.go:50: "msg"="Using existing type definition." "error"="instrument type conflict" "instrument"="foo_bytes" "existing"="GAUGE" "dropped"="HISTOGRAM"
FAIL
FAIL	go.opentelemetry.io/otel/exporters/prometheus	0.054s
FAIL
```

cc @TylerHelmuth @ywwg @ArthurSens

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
2025-07-21 11:58:28 -04:00
..
conflict_help_two_counters_1.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
conflict_help_two_counters_2.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
conflict_help_two_histograms_1.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
conflict_help_two_histograms_2.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
conflict_help_two_updowncounters_1.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
conflict_help_two_updowncounters_2.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
conflict_type_counter_and_updowncounter_1.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
conflict_type_counter_and_updowncounter_2.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
conflict_type_histogram_and_updowncounter_1.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
conflict_type_histogram_and_updowncounter_2.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
conflict_unit_two_counters.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
conflict_unit_two_histograms.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
conflict_unit_two_updowncounters.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
counter.txt Migrate prometheus exporter to otlptranslator (#7044) 2025-07-21 11:58:28 -04:00
counter_disabled_suffix.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
counter_no_unit.txt Migrate prometheus exporter to otlptranslator (#7044) 2025-07-21 11:58:28 -04:00
counter_noutf8_with_unit_suffix.txt Migrate prometheus exporter to otlptranslator (#7044) 2025-07-21 11:58:28 -04:00
counter_utf8.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
counter_with_custom_unit_suffix.txt Handle custom metric suffix in `exporter/prometheus` to match otel-contrib (#6839) 2025-06-02 08:45:05 -04:00
counter_with_unit_suffix.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
custom_resource.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
empty_resource.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
exponential_histogram.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
gauge.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
histogram.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
multi_scopes.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
no_conflict_two_counters.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
no_conflict_two_histograms.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
no_conflict_two_updowncounters.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
non_monotonic_sum_does_not_add_exemplars.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
sanitized_labels.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
sanitized_names.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
with_allow_resource_attributes_filter.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
with_namespace.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
with_resource_attributes_filter.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00
without_scope_and_target_info.txt prometheus exporter convert instrumentation scope to otel_scope_info metric (#3357) 2022-11-02 07:50:37 -07:00
without_scope_info.txt chore(deps): update github.com/prometheus/client_golang to v1.21.1 (#6433) 2025-03-18 10:22:12 +01:00
without_target_info.txt prometheus: remove otel_scope_info (#6770) 2025-05-28 07:09:36 +02:00