Override span fields
Respan normally captures span input and output from function arguments and return values. Use update_current_span() when the trace should display a sanitized, condensed, or domain-specific representation instead.
Prerequisites
Override input and output
This complete example creates a manual task span, computes an internal result, writes safe display values to the span, checks that the update succeeded, and flushes the exporter.
The application receives the full internal_result, but the exported span displays only these safe values:
Verify in Respan
- Run the script and wait for
respan.flush()to complete. - Open Logs → Spans.
- Search for classify_support_ticket and open the span.
- Confirm that Input contains
ticket_demo_001and[redacted]. - Confirm that Output contains only
categoryandpriority;internal_notesmust not appear. - Confirm that metadata includes
data_policy=redacted.
Do not set a manual output inside a @workflow or @task function and assume it will win. Decorators automatically capture the function return value after the function finishes, which can overwrite an output attribute set earlier. Use a manual start_span() when the exported output must differ from the returned value, or return the same sanitized value you want captured.
Override only the input in a decorated function
When automatic output capture is correct, you can keep the decorator and override only the displayed input:
Troubleshooting
update_current_span()returnsFalse. The call ran outside an active span, or tracing is disabled. Move it insidestart_span(),@workflow, or@taskand confirmRESPAN_API_KEYis set.- The output still shows the function return value. A decorator captured the return after your manual update. Use the manual-span pattern above.
- Input or output is missing. Serialize structured values with
json.dumps(...); OpenTelemetry attributes must be strings or supported scalar/array values. - The span is not visible yet. Call
respan.flush()before a short-lived script exits, then confirm the project and environment associated with the API key.
You can also update an already-ingested span with the Update Span API.