best practices : should we reuse the instruments ? #2783
Unanswered
antonmithun-work
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am using the below code to record the time taken for a function. but I am creating histogram instrument for every request.
let meter = global::meter("local_time_meter"); let counter = meter .u64_counter("example_counter") .with_description("Counts occurrences of events") .build(); counter.add(1, &[KeyValue::new("test", "test")]); let processing_time = meter.f64_histogram("processing_time").build(); processing_time.record(start.elapsed().as_secs_f64(), &[]);
I think its better if I encapsulate this histogram in a separete module and internally reuse the histogram created in the consturctor to record the data
so I try to do something like this
But I am getting type mismatch error
Type mismatch [E0308] expected Histogram<f64>, but found opentelemetry::metrics::instruments::histogram::Histogram<f64>
these are my dependencies
opentelemetry = { version = "0.28.0", features = ["trace", "metrics"] } opentelemetry-otlp = { version= "0.28.0", features = ["tonic", "grpc-tonic"] } opentelemetry_sdk = { version = "0.28.0", features = ["rt-tokio", "rt-tokio-current-thread"] } opentelemetry-semantic-conventions = { version= "0.28.0" } opentelemetry-stdout = "0.28.0" tracing = "0.1.41" tracing-opentelemetry = "0.29.0" tracing-subscriber = { version = "0.3.19"}
Qs :
thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions