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
sumdata points with cumulative aggregation temporality andisMonotonic: true. - Prometheus gauges become OTLP
gaugedata points. - Prometheus histograms become OTLP
histogramdata points. Prometheus cumulative_bucketsamples are converted to OTLP non-cumulativebucketCounts, and the+Infbound is dropped fromexplicitBoundsper the OTLP data model. - Summaries and untyped families fall back to
gaugedata 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
Properties
Methods
-
buildMetricsPayload(
Iterable< MetricFamilySamples> families, {DateTime? timestamp, DateTime? startTimestamp}) → Map<String, dynamic> -
Builds the OTLP
ExportMetricsServiceRequestJSON document forfamilies. -
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
familiesto the configured endpoint as a single OTLPExportMetricsServiceRequest. -
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