NAME

Langertha::Runtime::Metrics::OTLP - Convert parsed Prometheus records to an OTLP/HTTP (JSON) metrics payload

VERSION

version 0.503

SYNOPSIS

use Langertha::Runtime::Metrics;
use Langertha::Runtime::Metrics::OTLP;

my $records = Langertha::Runtime::Metrics->new->parse($prometheus_body);

my $otlp = Langertha::Runtime::Metrics::OTLP->new;

my $payload = $otlp->build_payload($records,
    service_name        => 'vllm',
    resource_attributes => { trace_id => 'trace-123' },
);

my $json = $otlp->to_json($records, service_name => 'vllm');

DESCRIPTION

Serializes the record shape produced by Langertha::Runtime::Metrics ({ name, type, value, labels }) into an OpenTelemetry OTLP/HTTP JSON metrics payload: resourceMetrics / scopeMetrics / metric. The payload is a plain HashRef (or JSON string via "to_json") ready to POST to any OTLP/HTTP metrics receiver — an OpenTelemetry Collector, a Prometheus OTLP receiver, Grafana, or any other backend that speaks OTLP/HTTP.

Type mapping:

  • gauge / untyped — OTLP gauge data point (asDouble)

  • counter — OTLP sum with isMonotonic => true and aggregationTemporality => AGGREGATION_TEMPORALITY_CUMULATIVE (Prometheus counters are cumulative monotonic sums)

  • histogram — the _bucket / _sum / _count series are re-grouped into a single OTLP histogram metric. Buckets are sorted by their le bound (+Inf last), explicitBounds excludes +Inf, and bucketCounts keeps the cumulative counts including the +Inf bucket.

  • summary — the _sum / _count series plus any {quantile="..."} series are re-grouped into a single OTLP summary metric with quantileValues.

Langfuse note: Langfuse does not ingest OTLP metrics. Its /api/public/otel endpoint accepts traces only; a POST to /api/public/otel/v1/metrics is accepted and silently discarded (dummy route since langfuse/langfuse#6408). The /api/public/metrics REST endpoint is a read-only query API over Langfuse's own trace data, not an ingestion endpoint. Point this serializer at a real OTLP metrics backend (Collector, Prometheus, Grafana) — see "export_otlp_f" in Langertha::Role::Runtime::MetricsPoll for the exporter and the sources.

build_payload

my $payload = $otlp->build_payload($records, %opts);

Builds the OTLP/HTTP JSON metrics payload HashRef for the given records. Optional %opts:

  • service_name — convenience for the service.name resource attribute

  • resource_attributes — HashRef of extra resource attributes (e.g. { trace_id => 'trace-123' } to attach a trace context)

  • scope_name — instrumentation scope name (default 'langertha')

  • timestamp — epoch seconds (default: now); rendered as timeUnixNano on every data point

to_json

my $json = $otlp->to_json($records, %opts);

Same as "build_payload" but returns the JSON-encoded string, ready to POST as the request body.

SEE ALSO

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/Getty/langertha/issues.

IRC

Join #langertha on irc.perl.org or message Getty directly.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <getty@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus https://raudssus.de/.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.