Skip to content

Make opentelemetry_metrics_exporter entrypoint support pull exporters #3411

@aabmass

Description

@aabmass

The opentelemetry_metrics_exporter is currently the option for configuring metric exporters for auto-instrumentation. Unfortunately, this doesn't work for pull exporters (e.g. prometheus) which are implemented as MetricReader subclasses, nor does it allow the entrypoint impl to set configure the MetricReader. Solution was discussed in #2843 (comment)

If I could make a suggestion, the entrypoints for OTEL_METRIC_EXPORTERS should provide a MetricReader factory function. For example, for otlp that could be something like

def provide_reader() -> MetricReader:
  preferred_temporality=environ.get(
                    OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE,
                    "CUMULATIVE",
                )
                .upper()
                .strip()

  return PeriodicExportingMetricReader(
    exporter=OTLPExporter(),
    preferred_temporality=preferred_temporality,
    ...,
  )

then update

otlp_proto_grpc = opentelemetry.exporter.otlp.proto.grpc.metric_exporter:OTLPMetricExporter

to

 otlp_proto_grpc = opentelemetry.exporter.otlp.proto.grpc.metric_exporter:provide_reader

one downside of this approach is some code duplication across implementations of provide_reader() for other exporters if we have common environment variables to check. However it would simplify things for using MetricReaders like Prometheus which act as a "pull exporter", as they can easily implement this method as well. Right now im not sure how we would implement OTEL_METRICS_EXPORTER=prometheus

and I think we are all on board with this approach (see #2864 (comment)).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions