use std::time::Duration; use crank_metrics::{ ExemplarTraceId, HttpMethod, HttpRoute, HttpStatusClass, exemplar_snapshot, record_http_request_with_exemplar, reset_exemplars_for_test, }; use metrics_util::debugging::DebuggingRecorder; #[test] fn trace_id_is_validated_and_never_becomes_an_ordinary_label() { assert!(ExemplarTraceId::parse("0123456789abcdef0123456789abcdef").is_some()); assert!(ExemplarTraceId::parse("0123456789ABCDEF0123456789ABCDEF").is_none()); assert!(ExemplarTraceId::parse("short").is_none()); reset_exemplars_for_test(); let recorder = DebuggingRecorder::new(); let snapshotter = recorder.snapshotter(); metrics::with_local_recorder(&recorder, || { record_http_request_with_exemplar( HttpRoute::from_matched_path("/health"), HttpMethod::Get, HttpStatusClass::Success, Duration::from_millis(10), ExemplarTraceId::parse("0123456789abcdef0123456789abcdef"), ); }); let aggregate = snapshotter.snapshot().into_vec(); assert!( aggregate .iter() .all(|(key, _, _, _)| { key.key().labels().all(|label| label.key() != "trace_id") }) ); let exemplars = exemplar_snapshot(); assert_eq!(exemplars.len(), 1); assert_eq!( exemplars[0].trace_id.as_str(), "0123456789abcdef0123456789abcdef" ); }