Skip to content

Commit 6f65c30

Browse files
authored
Add log to durable object metrics (#272)
1 parent 16cf1bf commit 6f65c30

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

crates/generic_log_worker/src/obs/metrics.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,25 @@ pub fn registry() -> Registry {
275275
.expect("only panic when prefix is an empty string")
276276
}
277277

278+
/// Like [`registry`], but adds a constant `log` label to every metric
279+
/// registered on the returned [`Registry`]. Use this for Durable Object
280+
/// metrics where the log name is known and fixed for the lifetime of the DO.
281+
#[must_use]
282+
#[allow(clippy::missing_panics_doc)] // can never panic
283+
pub fn registry_with_log(log: &str) -> Registry {
284+
Registry::new_custom(
285+
None,
286+
Some(
287+
[
288+
("env".to_owned(), env!("DEPLOY_ENV").to_owned()),
289+
("log".to_owned(), log.to_owned()),
290+
]
291+
.into(),
292+
),
293+
)
294+
.expect("only panic when prefix is an empty string")
295+
}
296+
278297
impl super::WshimData for &Registry {
279298
fn endpoint() -> &'static str {
280299
"prometheus"

crates/generic_log_worker/src/sequencer_do.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<L: LogEntry, M: SequencerMetadata> GenericSequencer<L, M> {
194194
where
195195
F: AsyncFnOnce(SequencerMetrics) -> R,
196196
{
197-
let registry = obs::metrics::registry();
197+
let registry = obs::metrics::registry_with_log(&self.config.name);
198198
let metrics = SequencerMetrics::new(&registry);
199199
// a bit of a hack but makes the rest of the code simpler.
200200
// We setup metrics here so that the closure f can then use these reset metrics.

0 commit comments

Comments
 (0)