diff --git a/exporter/prometheusexporter/README.md b/exporter/prometheusexporter/README.md index 2c580e9f70a..c556d733ce7 100644 --- a/exporter/prometheusexporter/README.md +++ b/exporter/prometheusexporter/README.md @@ -17,8 +17,8 @@ The following settings can be optionally configured: - `send_timestamps` (default = `false`): if true, sends the timestamp of the underlying metric sample in the response. - `metric_expiration` (default = `5m`): defines how long metrics are exposed without updates -- `resource_attributes_as_tag` (default = `false`): if set to true will transform all resource - attributes into labels. +- `resource_to_telemetry_conversion` + - `enabled` (default = false): If `enabled` is `true`, all the resource attributes will be converted to metric labels by default. Example: @@ -32,5 +32,6 @@ exporters: "another label": spaced value send_timestamps: true metric_expiration: 180m - resource_attributes_as_tags: true + resource_to_telemetry_conversion: + enabled: true ``` diff --git a/exporter/prometheusexporter/config.go b/exporter/prometheusexporter/config.go index 6bf4bbf985b..0fd36382f4f 100644 --- a/exporter/prometheusexporter/config.go +++ b/exporter/prometheusexporter/config.go @@ -20,6 +20,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/exporter/exporterhelper" ) // Config defines configuration for Prometheus exporter. @@ -41,7 +42,6 @@ type Config struct { // MetricExpiration defines how long metrics are kept without updates MetricExpiration time.Duration `mapstructure:"metric_expiration"` - // ResourceAttributesAsTags, if sMet to true, will use the exporterhelper feature to - // transform all resource attributes into metric labels. - ResourceAttributesAsTags bool `mapstructure:"resource_attributes_as_tags"` + // ResourceToTelemetrySettings defines configuration for converting resource attributes to metric labels. + exporterhelper.ResourceToTelemetrySettings `mapstructure:"resource_to_telemetry_conversion"` } diff --git a/exporter/prometheusexporter/factory.go b/exporter/prometheusexporter/factory.go index dcef071cac4..9e1f70769ea 100644 --- a/exporter/prometheusexporter/factory.go +++ b/exporter/prometheusexporter/factory.go @@ -63,9 +63,7 @@ func createMetricsExporter( prometheus.ConsumeMetrics, exporterhelper.WithStart(prometheus.Start), exporterhelper.WithShutdown(prometheus.Shutdown), - exporterhelper.WithResourceToTelemetryConversion(exporterhelper.ResourceToTelemetrySettings{ - Enabled: pcfg.ResourceAttributesAsTags, - }), + exporterhelper.WithResourceToTelemetryConversion(pcfg.ResourceToTelemetrySettings), ) if err != nil { return nil, err diff --git a/exporter/prometheusexporter/prometheus_test.go b/exporter/prometheusexporter/prometheus_test.go index 5ba81c5481b..216a25fae4a 100644 --- a/exporter/prometheusexporter/prometheus_test.go +++ b/exporter/prometheusexporter/prometheus_test.go @@ -32,6 +32,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/translator/internaldata" ) @@ -261,10 +262,12 @@ func TestPrometheusExporter_endToEndWithResource(t *testing.T) { "foo2": "bar2", "code2": "one2", }, - Endpoint: ":7777", - SendTimestamps: true, - MetricExpiration: 120 * time.Minute, - ResourceAttributesAsTags: true, + Endpoint: ":7777", + SendTimestamps: true, + MetricExpiration: 120 * time.Minute, + ResourceToTelemetrySettings: exporterhelper.ResourceToTelemetrySettings{ + Enabled: true, + }, } factory := NewFactory()