trace_id and parent call ID from the upstream service can be passed over the wire to downstream services, and then set as context before the downstream op executes. This links all calls into a single unified trace visible in the Weave UI.
How it works
The approach has two parts:-
Upstream service: Inside a running op, call
get_current_call()to retrieve the current call object. Extract itstrace_idandidfields, then pass them to the downstream service alongside your normal request payload. The transport mechanism (HTTP headers, gRPC metadata, a message queue payload, or any other channel) is up to your implementation. -
Downstream service: Before calling the downstream op, use the
parent_callcontext manager (described below) to set a sentinel call on the call stack. Weave uses this sentinel as the parent for any ops that execute inside the context manager, connecting them to the upstream trace.
Prerequisites
- Python with Weave installed (
pip install weave) - A W&B account and project initialized with
weave.init()
Step 1: Add the parent_call helper
Add this context manager to each downstream service. It accepts the trace_id and parent_call_id passed from upstream, and temporarily sets them as the current call stack:
_op_name, project_id, parent_id, and inputs fields are required by the Call constructor but are not used in this context. Pass empty values for each.
Step 2: Extract trace context in the upstream service
Inside an op in the upstream service, callget_current_call() to retrieve the active call. Pass curr_call.trace_id and curr_call.id to the downstream service:
Step 3: Use parent_call in the downstream service
In the downstream service, wrap the op call in the parent_call context manager using the trace_id and parent_call_id received from upstream:
parent_call context manager are recorded as children of the upstream call, regardless of process or service boundaries.
Complete example
The following example simulates three services running as separate processes. A top-level service accepts a number, fans out two calls to a middle service, and each middle service call fans out to a bottom service.View complete example
View complete example