OTelExporter class

Exports metrics to an OpenTelemetry collector over OTLP/HTTP.

OTelExporter converts the MetricFamilySamples produced by the prometheus_client-backed registry into an OTLP ExportMetricsServiceRequest JSON document and POSTs it to a configured endpoint. The implementation is dependency-free beyond package:http (already a dependency of this package); protobuf encoding is not used.

Metric type mapping:

  • Prometheus counters become OTLP sum data points with cumulative aggregation temporality and isMonotonic: true.
  • Prometheus gauges become OTLP gauge data points.
  • Prometheus histograms become OTLP histogram data points. Prometheus cumulative _bucket samples are converted to OTLP non-cumulative bucketCounts, and the +Inf bound is dropped from explicitBounds per the OTLP data model.
  • Summaries and untyped families fall back to gauge data points.

Scope note: this repository has no tracing abstraction, so only metrics are exported. No spans or traces are bridged; if a tracing layer is added later, it should plug in as a peer to this exporter.

The exporter is disabled by default; see MetricsConfig.enableOpenTelemetry.

Example:

final exporter = OTelExporter(
  endpoint: Uri.parse('http://localhost:4318/v1/metrics'),
  headers: {'Authorization': 'Bearer token'},
);
await exporter.export(await registry.collectMetricFamilySamples());
await exporter.close();

Constructors

OTelExporter({required Uri endpoint, Map<String, String> headers = const {}, String serviceName = 'dart_ipfs', Client? httpClient, Logger? logger, Duration requestTimeout = const Duration(seconds: 10)})
Creates an OTLP/HTTP exporter that POSTs to endpoint.

Properties

endpoint → Uri
The endpoint this exporter POSTs to.
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

buildMetricsPayload(Iterable<MetricFamilySamples> families, {DateTime? timestamp, DateTime? startTimestamp}) → Map<String, dynamic>
Builds the OTLP ExportMetricsServiceRequest JSON document for families.
close() → Future<void>
Closes the exporter and releases the underlying HTTP client when it is owned by this exporter.
export(Iterable<MetricFamilySamples> families) → Future<void>
Exports families to the configured endpoint as a single OTLP ExportMetricsServiceRequest.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited