Skip to main content

MetricsEntry

Struct MetricsEntry 

Source
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: MetricsSource

Implementations§

Source§

impl MetricsEntry

Source

pub fn new( name: impl Into<String>, value: f64, metric_type: BasicMetricType, ) -> Self

Create a new metrics entry

Source

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}
Source

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}
Source

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

Source§

fn clone(&self) -> MetricsEntry

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MetricsEntry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more