Operations

Structured Logging


All Orcher services use tracing's structured fields for machine-parseable context:

1
use tracing::{info, warn, error, instrument};
2
3
#[instrument(
4
skip(ctx),
5
fields(execution_id = %execution_id, workflow = %workflow_name)
6
)]
7
pub 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 workflow
13
info!("Starting workflow execution");
14
15
info!(
16
version = %ctx.workflow_version,
17
namespace = %ctx.namespace,
18
"Workflow configuration loaded"
19
);
20
21
warn!(
22
queue_depth = ctx.queue_depth,
23
threshold = 1000,
24
"Queue depth is high"
25
);
26
27
error!(
28
error = ?err,
29
retry_count = ctx.retry_count,
30
"Workflow execution failed"
31
);
32
33
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:

1
use tracing::info_span;
2
3
let span = info_span!(
4
"process_request",
5
correlation_id = %correlation_id,
6
request_id = %request_id
7
);
8
9
let _enter = span.enter();
10
11
// All logs within this scope include correlation_id and request_id
12
info!("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