Sideways 🦀
Observability from the side - because crabs walk sideways, and so should your telemetry.
A production-ready Rust telemetry library that provides easy-to-use Datadog tracing and StatsD metrics collection for high-performance services.
Features
- 🎯 Datadog Native Tracing - OpenTelemetry-based distributed tracing via dd-trace-rs
- 📊 StatsD Metrics - Production-ready Cadence integration with buffering and queuing
- 🚀 One-Line Initialization - Simple
init_telemetry()call sets up everything - 🔧 Environment-Based Config - Configure via environment variables
- 💪 Graceful Degradation - Continues running even if telemetry services unavailable
- 🏷️ Tag Support - Full Datadog-style tag support for rich dimensional data
- 🔍 Health Check Filtering - Automatically filters out noisy health check spans
Quick Start
Add to your Cargo.toml:
[]
= { = "sideways" } # Or published version
Initialize in your application:
use ;
use *; // Import all metrics macros
use info;
async
Configuration
Environment Variables
Datadog Tracing
# Disable with DD_TRACE_ENABLED=false (default: enabled)
DD_TRACE_ENABLED=true
# Service configuration
DD_SERVICE=my-service
DD_ENV=production
DD_TRACE_AGENT_URL=http://localhost:8126
# Logging level
RUST_LOG=info
StatsD Metrics
# Disable with METRICS_ENABLED=false (default: enabled)
METRICS_ENABLED=true
# StatsD server
STATSD_HOST=localhost
STATSD_PORT=8125
# Metric namespace/prefix
METRICS_PREFIX=my-service
Programmatic Configuration
use TelemetryConfig;
let config = builder
.dd_service
.dd_env
.statsd_host
.statsd_port
.metrics_prefix
.build;
let telemetry = init_telemetry.await;
Available Metrics Macros
All metrics support Datadog-style tags:
use *;
// Counters - increment values
statsd_count!;
// Gauges - arbitrary values (integers or floats)
statsd_gauge!;
statsd_gauge!;
// Timers - durations in milliseconds
statsd_time!;
statsd_time!;
// Histograms - statistical distributions
statsd_histogram!;
statsd_histogram!;
statsd_histogram!;
// Distributions - advanced histograms with percentiles
statsd_distribution!;
statsd_distribution!;
// Meters - rate tracking
statsd_meter!;
// Sets - unique value counting
statsd_set!;
Usage Notes
Importing in Your Code
Simply import the prelude to get all metrics macros:
use *;
// Now use any metric macro!
statsd_count!;
Tracing Usage
Once telemetry is initialized, use the standard tracing crate for distributed tracing.
Basic Logging
use ;
info!;
warn!;
error!;
Instrumentation
Instrumentation is REQUIRED for distributed tracing to work properly. The #[instrument] attribute automatically creates spans for functions, which are essential for:
- Request tracing across service boundaries
- Performance profiling
- Call hierarchy visualization in Datadog APM
use instrument;
// Basic instrumentation - function name becomes span name
async
// Skip certain parameters (e.g., large data structures)
async
// Custom span name
async
// Add custom fields to the span
async
Structured Fields
Always use structured fields for better querying in Datadog:
// ❌ BAD - string interpolation
info!;
// ✅ GOOD - structured fields
info!;
Span Context
Manually create spans for more control:
use ;
async
Health Check Filtering
The library automatically filters out health check-related spans from Datadog to reduce noise:
- Spans from
tonic_health - Spans containing "health", "Health", or "Check"
- gRPC health check services
Architecture
Datadog Tracing
- Uses
datadog-opentelemetry(dd-trace-rs) for native Datadog support - OpenTelemetry layers with custom health check filtering
- Console logging + telemetry layers combined
- Configurable via
RUST_LOGenvironment variable
StatsD Metrics
- UDP-based for low overhead
- Buffered sink for efficient batching
- Queuing sink for asynchronous dispatch
- Global client registration for macro usage
- Automatic reconnection on failures
Examples
Web Service
use ;
use *;
use info;
async
Worker Service
use ;
use *;
use ;
async
async
Publishing
To publish this crate to crates.io:
- Update
Cargo.tomlwith repository URL and proper metadata - Test locally:
cargo test --all-features - Publish:
cargo publish
License
MIT
Credits
Built by iClassPro team, powered by:
- Cadence - Excellent StatsD client
- dd-trace-rs - Datadog native tracing