Custom Metrics Guide
How to add custom metrics and tracing events to your Klyra application
This guide will show you how to add custom metrics and tracing events to your Klyra application using the tracing crate.
Getting Started
First, add the tracing dependency to your project:
Basic Usage
Add tracing events with fields to your functions to create custom metrics. Here’s a simple example:
This will:
- Send an
infolevel log to stdout - Export the metric to your configured telemetry provider
- Include the custom attribute
counter.hellowith value1
Metric Types
The runtime’s OTel exporter uses tracing-opentelemetry under the hood, which automatically handles three metric types:
-
Monotonic Counters: Values that only increase (e.g., total requests)
-
Counters: Values that can increase or decrease
-
Histograms: For measuring distributions of values
Example Trace Output
Here’s what a tracing event looks like when exported:
Best Practices
-
Use Meaningful Names: Choose clear, descriptive names for your metrics
-
Include Context: Add relevant context to your metrics
-
Use Appropriate Metric Types:
- Use
monotonic_counterfor values that only increase - Use
counterfor values that can go up and down - Use
histogramfor measuring distributions
- Use
