Override span fields

Force the input, output, name, or other fields on the current span when the auto-captured values aren’t what you want.

By default, Respan captures span input and output from the function arguments and return value. When that isn’t what you want displayed in the trace UI — for example, you want to redact sensitive args, condense a large payload, or surface a different field — override the span at runtime via update_current_span().

Override input & output

Python
1import json
2from opentelemetry.semconv_ai import SpanAttributes
3from respan import Respan
4from respan.decorators import workflow
5
6respan = Respan()
7client = respan.getClient()
8
9@workflow(name="update_attributes_test")
10def update_attributes_test(input: str):
11 force_set_attributes = {
12 SpanAttributes.TRACELOOP_ENTITY_INPUT: json.dumps({
13 "args": [],
14 "kwargs": {"text": "custom input"}
15 }),
16 }
17
18 client.update_current_span(
19 attributes=force_set_attributes,
20 name="update_attributes_test",
21 respan_params={"metadata": {"test": "test"}},
22 )
23
24 return "Some desired output"
25
26if __name__ == "__main__":
27 update_attributes_test("Some input")

Use update_current_span(attributes=...) for overriding displayed input/output. Values must be JSON-serializable strings via json.dumps(...).

You can also update spans after they’ve been logged via the Update Span API.