pub struct MetricsEntry {
pub name: String,
pub value: f64,
pub metric_type: BasicMetricType,
pub timestamp: DateTime<Utc>,
pub trace_context: Option<TraceContext>,
pub source: MetricsSource,
}Expand description
Basic metric entry for correlation with logs
Fields§
§name: String§value: f64§metric_type: BasicMetricType§timestamp: DateTime<Utc>§trace_context: Option<TraceContext>§source: MetricsSourceImplementations§
Source§impl MetricsEntry
impl MetricsEntry
Sourcepub fn new(
name: impl Into<String>,
value: f64,
metric_type: BasicMetricType,
) -> Self
pub fn new( name: impl Into<String>, value: f64, metric_type: BasicMetricType, ) -> Self
Create a new metrics entry
Sourcepub fn with_trace_context(self, trace_context: TraceContext) -> Self
pub fn with_trace_context(self, trace_context: TraceContext) -> Self
Add trace context for correlation
Examples found in repository?
examples/basic_metrics_demo.rs (line 43)
7fn main() -> ObservabilityResult<()> {
8 println!("🎯 Basic MetricsPort Demo");
9
10 // Create simple metrics adapter
11 let metrics_adapter = WasmStdoutMetricsAdapter::new();
12
13 println!("\n📊 Testing simple metrics emission:");
14
15 // Test counter
16 metrics_adapter.emit_counter_simple("requests_total", 1.0)?;
17
18 // Test histogram
19 metrics_adapter.emit_histogram_simple("request_duration_ms", 150.0)?;
20
21 // Test gauge
22 metrics_adapter.emit_gauge_simple("active_connections", 5.0)?;
23
24 println!("\n🔄 Testing unified adapter (logs + metrics correlation):");
25
26 // Create unified adapter for correlation
27 let unified_adapter = UnifiedWasmStdoutAdapter::new();
28
29 // Test correlated metrics
30 unified_adapter.emit_counter_simple("llm_requests", 1.0)?;
31 unified_adapter.emit_histogram_simple("llm_response_time_ms", 2500.0)?;
32
33 println!("\n📈 Testing MetricsEntry with trace context:");
34
35 // Create metrics with trace context for correlation
36 let trace_context = TraceContext {
37 trace_id: "trace-123456".to_string(),
38 span_id: "span-789".to_string(),
39 parent_span_id: Some("parent-456".to_string()),
40 };
41
42 let counter_metric = create_counter_metric("a2a_messages_sent", 3.0)
43 .with_trace_context(trace_context.clone())
44 .with_source(
45 Some("a2a_jsonrpc_core".to_string()),
46 Some("message_handler".to_string()),
47 Some("send_request".to_string()),
48 );
49
50 println!("Metric with context: {}", counter_metric.to_json());
51
52 let histogram_metric = create_histogram_metric("template_render_duration_us", 1250.0)
53 .with_trace_context(trace_context)
54 .with_source(
55 Some("template_engines".to_string()),
56 Some("sailfish_renderer".to_string()),
57 Some("render_template".to_string()),
58 );
59
60 println!("Metric with context: {}", histogram_metric.to_json());
61
62 println!("\n✅ Basic metrics demo completed!");
63
64 Ok(())
65}Sourcepub fn with_source(
self,
module: Option<String>,
component: Option<String>,
operation: Option<String>,
) -> Self
pub fn with_source( self, module: Option<String>, component: Option<String>, operation: Option<String>, ) -> Self
Add source information
Examples found in repository?
examples/basic_metrics_demo.rs (lines 44-48)
7fn main() -> ObservabilityResult<()> {
8 println!("🎯 Basic MetricsPort Demo");
9
10 // Create simple metrics adapter
11 let metrics_adapter = WasmStdoutMetricsAdapter::new();
12
13 println!("\n📊 Testing simple metrics emission:");
14
15 // Test counter
16 metrics_adapter.emit_counter_simple("requests_total", 1.0)?;
17
18 // Test histogram
19 metrics_adapter.emit_histogram_simple("request_duration_ms", 150.0)?;
20
21 // Test gauge
22 metrics_adapter.emit_gauge_simple("active_connections", 5.0)?;
23
24 println!("\n🔄 Testing unified adapter (logs + metrics correlation):");
25
26 // Create unified adapter for correlation
27 let unified_adapter = UnifiedWasmStdoutAdapter::new();
28
29 // Test correlated metrics
30 unified_adapter.emit_counter_simple("llm_requests", 1.0)?;
31 unified_adapter.emit_histogram_simple("llm_response_time_ms", 2500.0)?;
32
33 println!("\n📈 Testing MetricsEntry with trace context:");
34
35 // Create metrics with trace context for correlation
36 let trace_context = TraceContext {
37 trace_id: "trace-123456".to_string(),
38 span_id: "span-789".to_string(),
39 parent_span_id: Some("parent-456".to_string()),
40 };
41
42 let counter_metric = create_counter_metric("a2a_messages_sent", 3.0)
43 .with_trace_context(trace_context.clone())
44 .with_source(
45 Some("a2a_jsonrpc_core".to_string()),
46 Some("message_handler".to_string()),
47 Some("send_request".to_string()),
48 );
49
50 println!("Metric with context: {}", counter_metric.to_json());
51
52 let histogram_metric = create_histogram_metric("template_render_duration_us", 1250.0)
53 .with_trace_context(trace_context)
54 .with_source(
55 Some("template_engines".to_string()),
56 Some("sailfish_renderer".to_string()),
57 Some("render_template".to_string()),
58 );
59
60 println!("Metric with context: {}", histogram_metric.to_json());
61
62 println!("\n✅ Basic metrics demo completed!");
63
64 Ok(())
65}Sourcepub fn to_json(&self) -> Value
pub fn to_json(&self) -> Value
Convert to JSON for transport
Examples found in repository?
examples/basic_metrics_demo.rs (line 50)
7fn main() -> ObservabilityResult<()> {
8 println!("🎯 Basic MetricsPort Demo");
9
10 // Create simple metrics adapter
11 let metrics_adapter = WasmStdoutMetricsAdapter::new();
12
13 println!("\n📊 Testing simple metrics emission:");
14
15 // Test counter
16 metrics_adapter.emit_counter_simple("requests_total", 1.0)?;
17
18 // Test histogram
19 metrics_adapter.emit_histogram_simple("request_duration_ms", 150.0)?;
20
21 // Test gauge
22 metrics_adapter.emit_gauge_simple("active_connections", 5.0)?;
23
24 println!("\n🔄 Testing unified adapter (logs + metrics correlation):");
25
26 // Create unified adapter for correlation
27 let unified_adapter = UnifiedWasmStdoutAdapter::new();
28
29 // Test correlated metrics
30 unified_adapter.emit_counter_simple("llm_requests", 1.0)?;
31 unified_adapter.emit_histogram_simple("llm_response_time_ms", 2500.0)?;
32
33 println!("\n📈 Testing MetricsEntry with trace context:");
34
35 // Create metrics with trace context for correlation
36 let trace_context = TraceContext {
37 trace_id: "trace-123456".to_string(),
38 span_id: "span-789".to_string(),
39 parent_span_id: Some("parent-456".to_string()),
40 };
41
42 let counter_metric = create_counter_metric("a2a_messages_sent", 3.0)
43 .with_trace_context(trace_context.clone())
44 .with_source(
45 Some("a2a_jsonrpc_core".to_string()),
46 Some("message_handler".to_string()),
47 Some("send_request".to_string()),
48 );
49
50 println!("Metric with context: {}", counter_metric.to_json());
51
52 let histogram_metric = create_histogram_metric("template_render_duration_us", 1250.0)
53 .with_trace_context(trace_context)
54 .with_source(
55 Some("template_engines".to_string()),
56 Some("sailfish_renderer".to_string()),
57 Some("render_template".to_string()),
58 );
59
60 println!("Metric with context: {}", histogram_metric.to_json());
61
62 println!("\n✅ Basic metrics demo completed!");
63
64 Ok(())
65}Trait Implementations§
Source§impl Clone for MetricsEntry
impl Clone for MetricsEntry
Source§fn clone(&self) -> MetricsEntry
fn clone(&self) -> MetricsEntry
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MetricsEntry
impl RefUnwindSafe for MetricsEntry
impl Send for MetricsEntry
impl Sync for MetricsEntry
impl Unpin for MetricsEntry
impl UnsafeUnpin for MetricsEntry
impl UnwindSafe for MetricsEntry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more