Search code examples
open-telemetryopen-telemetry-collector

Defining multiple exporters of the same type


Is it possible to define the same type of exporter multiple times in OpenTelemetry Collector config?

Given this example:

receivers:
  otlp:
    protocols:
      http:
        endpoint: 0.0.0.0:4318

exporters:
  prometheus-A:
    endpoint: 0.0.0.0:8889

  prometheus-B:
    endpoint: 0.0.0.0:8890

service:
  pipelines:
    metrics-A:
      receivers: [otlp]
      exporters: [prometheus-A]
    metrics-B:
      receivers: [otlp]
      exporters: [prometheus-B]

I'm getting the following error:

error decoding 'exporters': unknown type: "prometheus-B" for id: "prometheus-B" (valid values: [prometheusremotewrite file prometheus otlp otlphttp kafka opencensus zipkin debug logging])

Of course if I change the exporter type to a valid value prometheus, there's no way of distinguishing those two exporters:

receivers:
  otlp:
    protocols:
      http:
        endpoint: 0.0.0.0:4318

exporters:
  prometheus:
    endpoint: 0.0.0.0:8889

  prometheus:
    endpoint: 0.0.0.0:8890

service:
  pipelines:
    metrics-A:
      receivers: [otlp]
      exporters: [prometheus] # How to distinguish the two?
    metrics-B:
      receivers: [otlp]
      exporters: [prometheus] # How to distinguish the two?

I'm then getting the following error:

mapping key "prometheus" already defined


Solution

  • Receivers, Processors and Exporters accept a list of items.

    You need to do it in the following way:

    receivers:
      otlp:
        protocols:
          http:
            endpoint: 0.0.0.0:4318
    
    exporters:
      prometheus/A:
        endpoint: 0.0.0.0:8889
    
      prometheus/B:
        endpoint: 0.0.0.0:8890
    
    service:
      pipelines:
        metrics:
          receivers: [otlp]
          exporters: [prometheus/A, prometheus/B]