Skip to content

Improve Doc to Make the Tracing Context Example #575 #583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
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
22 changes: 14 additions & 8 deletions metrics-tracing-context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@
//! First, set up `tracing` and `metrics` crates:
//!
//! ```rust
//! # use metrics_util::debugging::DebuggingRecorder;
//! # use tracing_subscriber::Registry;
//! use metrics_tracing_context::{MetricsLayer, TracingContextLayer};
//! use metrics_exporter_prometheus::PrometheusBuilder;
//! use metrics_tracing_context::MetricsLayer;
//! use metrics_tracing_context::TracingContextLayer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! use metrics_tracing_context::MetricsLayer;
//! use metrics_tracing_context::TracingContextLayer;
//! use metrics_tracing_context::{MetricsLayer, TracingContextLayer};

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @tobz.

I will fix the ci, if other changes are ok.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added dependencies, but I still got the following error:

---- metrics-tracing-context/src/lib.rs - (line 11) stdout ----
error[E0277]: the trait bound `PrometheusRecorder: Recorder` is not satisfied
   --> metrics-tracing-context/src/lib.rs:32:30
    |
24  | metrics::set_global_recorder(recorder).unwrap();
    | ---------------------------- ^^^^^^^^ the trait `Recorder` is not implemented for `PrometheusRecorder`
  

I've failed to understand why as Recorder as implemented for PrometheusRecorder and all dependencies seems up to date.

//! use metrics_util::layers::Layer;
//! use tracing_subscriber::layer::SubscriberExt;
//! use tracing_subscriber::{self, Registry};
//!
//! // Prepare tracing.
//! # let my_subscriber = Registry::default();
//! let subscriber = my_subscriber.with(MetricsLayer::new());
//! let (recorder, metric_server) = PrometheusBuilder::new()
//! .with_http_listener(([0, 0, 0, 0], 1111))
//! .build()
//! .unwrap();
//! let server_handle = tokio::spawn(metric_server);
//! let subscriber = Registry::default()
//! .with(tracing_subscriber::fmt::layer())
//! .with(MetricsLayer::new());
//! tracing::subscriber::set_global_default(subscriber).unwrap();
//!
//! // Prepare metrics.
//! # let my_recorder = DebuggingRecorder::new();
//! let recorder = TracingContextLayer::all().layer(my_recorder);
//! // Prepare recorder.
//! let recorder = TracingContextLayer::all().layer(recorder);
//! metrics::set_global_recorder(recorder).unwrap();
//! ```
//!
Expand Down
Loading