Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create example showing how to expose metrics in the OpenMetrics format
  • Loading branch information
emschwartz committed May 25, 2023
commit fa9203efc2577077b9ec622377abbe40af1747ef
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:

# Run the tests with each of the different metrics libraries
- run: cargo test --features=prometheus-exporter,metrics
- run: cargo test --features=prometheus-exporter,prometheus --tests
- run: cargo test --features=prometheus-exporter,prometheus-client,exemplars-tracing --tests
- run: cargo test --features=prometheus-exporter,prometheus
- run: cargo test --features=prometheus-exporter,prometheus-client,exemplars-tracing
# The tests using opentelemetry are currently failing because of this issue:
# https://github.com/open-telemetry/opentelemetry-rust/issues/1070
# We should remove the continue-on-error once that is fixed
Expand Down
21 changes: 21 additions & 0 deletions autometrics/src/exemplars/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@
//! ```http
//! Content-Type: application/openmetrics-text; version=1.0.0; charset=utf-8
//! ```
//!
//! ```rust
//! use http::{header::CONTENT_TYPE, Response};
//!
//! /// Expose the metrics to Prometheus in the OpenMetrics format
//! async fn get_metrics() -> Response<String> {
//! match autometrics::encode_global_metrics() {
//! Ok(metrics) => Response::builder()
//! .header(
//! CONTENT_TYPE,
//! "application/openmetrics-text; version=1.0.0; charset=utf-8",
//! )
//! .body(metrics)
//! .unwrap(),
//! Err(err) => Response::builder()
//! .status(500)
//! .body(err.to_string())
//! .unwrap(),
//! }
//! }
//! ```

#[cfg(feature = "exemplars-tracing")]
pub mod tracing;
3 changes: 2 additions & 1 deletion autometrics/src/exemplars/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ pub(crate) fn get_exemplar() -> Option<TraceLabels> {
///
/// # Example
/// ```rust
/// use autometrics::integrations::tracing::AutometricsExemplarExtractor;
/// use autometrics::exemplars::tracing::AutometricsExemplarExtractor;
/// use tracing_subscriber::prelude::*;
///
/// fn main() {
/// tracing_subscriber::fmt::fmt()
Expand Down