diff --git a/CHANGELOG.md b/CHANGELOG.md index 15732868dd6..68310bc765a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ The next release will require at least [Go 1.25]. - Change the `rpc.server.call.duration` metric value from milliseconds to seconds in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#8509) - Enforce that `client_certificate_file` and `client_key_file` are provided together in `go.opentelemetry.io/contrib/otelconf`. (#8450) - Fixed broken CSS and JavaScript CDN URLs in `go.opentelemetry.io/contrib/zpages` by replacing the inaccessible code.getmdl.io CDN with cdnjs.cloudflare.com. (#8502) +- Use Prometheus translation strategy instead of deprecated funcs in `go.opentelemetry.io/contrib/otelconf`. (#8595) ### Removed diff --git a/otelconf/v0.2.0/metric.go b/otelconf/v0.2.0/metric.go index 41423931213..05a0e505d5f 100644 --- a/otelconf/v0.2.0/metric.go +++ b/otelconf/v0.2.0/metric.go @@ -18,6 +18,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/prometheus/otlptranslator" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" @@ -272,12 +273,13 @@ func prometheusReader(ctx context.Context, prometheusConfig *Prometheus) (sdkmet if prometheusConfig.WithoutScopeInfo != nil && *prometheusConfig.WithoutScopeInfo { opts = append(opts, otelprom.WithoutScopeInfo()) } - if prometheusConfig.WithoutTypeSuffix != nil && *prometheusConfig.WithoutTypeSuffix { - opts = append(opts, otelprom.WithoutCounterSuffixes()) //nolint:staticcheck // WithoutCounterSuffixes is deprecated, but we still need it for backwards compatibility. - } - if prometheusConfig.WithoutUnits != nil && *prometheusConfig.WithoutUnits { - opts = append(opts, otelprom.WithoutUnits()) //nolint:staticcheck // WithouTypeSuffix is deprecated, but we still need it for backwards compatibility. + + if prometheusConfig.WithoutTypeSuffix != nil && *prometheusConfig.WithoutTypeSuffix && prometheusConfig.WithoutUnits != nil && *prometheusConfig.WithoutUnits { + opts = append(opts, otelprom.WithTranslationStrategy(otlptranslator.UnderscoreEscapingWithoutSuffixes)) + } else { + opts = append(opts, otelprom.WithTranslationStrategy(otlptranslator.NoUTF8EscapingWithSuffixes)) } + if prometheusConfig.WithResourceConstantLabels != nil { if prometheusConfig.WithResourceConstantLabels.Included != nil { var keys []attribute.Key diff --git a/otelconf/v0.3.0/metric.go b/otelconf/v0.3.0/metric.go index 03169295137..03f69f0d72f 100644 --- a/otelconf/v0.3.0/metric.go +++ b/otelconf/v0.3.0/metric.go @@ -18,6 +18,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/prometheus/otlptranslator" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" @@ -384,12 +385,13 @@ func prometheusReaderOpts(prometheusConfig *Prometheus) ([]otelprom.Option, erro if prometheusConfig.WithoutScopeInfo != nil && *prometheusConfig.WithoutScopeInfo { opts = append(opts, otelprom.WithoutScopeInfo()) } - if prometheusConfig.WithoutTypeSuffix != nil && *prometheusConfig.WithoutTypeSuffix { - opts = append(opts, otelprom.WithoutCounterSuffixes()) //nolint:staticcheck // WithouTypeSuffix is deprecated, but we still need it for backwards compatibility. - } - if prometheusConfig.WithoutUnits != nil && *prometheusConfig.WithoutUnits { - opts = append(opts, otelprom.WithoutUnits()) //nolint:staticcheck // WithouTypeSuffix is deprecated, but we still need it for backwards compatibility. + + if prometheusConfig.WithoutTypeSuffix != nil && *prometheusConfig.WithoutTypeSuffix && prometheusConfig.WithoutUnits != nil && *prometheusConfig.WithoutUnits { + opts = append(opts, otelprom.WithTranslationStrategy(otlptranslator.UnderscoreEscapingWithoutSuffixes)) + } else { + opts = append(opts, otelprom.WithTranslationStrategy(otlptranslator.NoUTF8EscapingWithSuffixes)) } + if prometheusConfig.WithResourceConstantLabels != nil { f, err := newIncludeExcludeFilter(prometheusConfig.WithResourceConstantLabels) if err != nil { diff --git a/otelconf/v0.3.0/metric_test.go b/otelconf/v0.3.0/metric_test.go index 6b9f9534b85..e0c8712700e 100644 --- a/otelconf/v0.3.0/metric_test.go +++ b/otelconf/v0.3.0/metric_test.go @@ -1374,7 +1374,7 @@ func TestPrometheusReaderOpts(t *testing.T) { { name: "no options", cfg: Prometheus{}, - wantOptions: 0, + wantOptions: 1, }, { name: "all set", @@ -1384,7 +1384,7 @@ func TestPrometheusReaderOpts(t *testing.T) { WithoutUnits: ptr(true), WithResourceConstantLabels: &IncludeExclude{}, }, - wantOptions: 4, + wantOptions: 3, }, { name: "all set false", @@ -1394,7 +1394,7 @@ func TestPrometheusReaderOpts(t *testing.T) { WithoutUnits: ptr(false), WithResourceConstantLabels: &IncludeExclude{}, }, - wantOptions: 1, + wantOptions: 2, }, } for _, tt := range testCases {