Structured Logging
All Orcher services use tracing's structured fields for machine-parseable context:
1use tracing::{info, warn, error, instrument};23#[instrument(4 skip(ctx),5 fields(execution_id = %execution_id, workflow = %workflow_name)6)]7pub async fn execute_workflow(8 ctx: &Context,9 execution_id: String,10 workflow_name: String,11) -> Result<()> {12 // All logs in this function include execution_id and workflow13 info!("Starting workflow execution");1415 info!(16 version = %ctx.workflow_version,17 namespace = %ctx.namespace,18 "Workflow configuration loaded"19 );2021 warn!(22 queue_depth = ctx.queue_depth,23 threshold = 1000,24 "Queue depth is high"25 );2627 error!(28 error = ?err,29 retry_count = ctx.retry_count,30 "Workflow execution failed"31 );3233 Ok(())34}The #[instrument] macro automatically creates a tracing span. All logs within the function inherit the span's fields, so you don't need to repeat execution_id in every log call.
Span Context
Spans propagate through async calls, giving you correlated logs across the entire execution path:
1use tracing::info_span;23let span = info_span!(4 "process_request",5 correlation_id = %correlation_id,6 request_id = %request_id7);89let _enter = span.enter();1011// All logs within this scope include correlation_id and request_id12info!("Processing workflow request");In JSON format, this produces:
1{2 "timestamp": "2024-01-15T10:30:45Z",3 "level": "INFO",4 "message": "Processing workflow request",5 "fields": {6 "correlation_id": "req_xyz789",7 "request_id": "abc123"8 }9}Next Steps
- Viewing Logs — CLI commands, Docker, and database queries
- Log Aggregation — Kubernetes, Grafana Loki, Elasticsearch, and performance
- Logging Overview — Configuration, formats, and log levels