Replies: 1 comment 1 reply
-
Not Opentelemetry, but gives you a starting point. Just export all the data yourself, it's quite easy. prometheus-client = "0.22" async fn main() -> ... {
let mut registry = <Registry>::default();
registry.register(...);
use poem::{Route, Server};
let app = Route::new().nest("/metrics", PrometheusExporter::new(registry));
Server::new(poem::listener::TcpListener::bind("0.0.0.0:63012"))
.run(app)
.await
} use poem::http::StatusCode;
use poem::{Endpoint, Request, Response, Result};
use prometheus_client::encoding::text::encode;
use prometheus_client::registry::Registry;
pub struct PrometheusExporter {
registry: Registry,
}
impl PrometheusExporter {
pub fn new(registry: Registry) -> Self {
Self { registry }
}
}
#[async_trait::async_trait]
impl Endpoint for PrometheusExporter {
type Output = Response;
async fn call(&self, _req: Request) -> Result<Self::Output> {
let mut buffer = String::new();
encode(&mut buffer, &self.registry)
.map(|()| {
Response::builder()
.content_type("application/openmetrics-text; version=1.0.0; charset=utf-8")
.body(buffer)
})
.map_err(|_err| StatusCode::INTERNAL_SERVER_ERROR.into())
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
i found this example in the issues: #448
but its really outdated, does anyone know how to setup the PrometheusExporter with opentelemetry like this?
A up-to-date example would be really helpful, can't find anything in the docs for this, i mean there is something with jaeger, but i'd like to use prometheus
Beta Was this translation helpful? Give feedback.
All reactions