Skip to main content
By default, Openlayer captures inputs, outputs, latency, tokens, and other information from your system. Often you will want to attach custom metadata — such as business context, IDs, or debug information — so you can later filter, search, or correlate traces inside the platform. This guide shows you how to do it.
Want to record user or session IDs? See the Track users and sessions guide.

Trace-level metadata

Use update_current_trace() to attach metadata to the entire trace (i.e., the full request lifecycle).
These key-value pairs appear in the trace metadata and can be filtered in the Openlayer UI.

Promote inputs and outputs onto the trace

update_current_trace() expects you to name every value by hand. When the value you want is already a function argument or a field of what the function returns, pass promote to @trace() instead: Openlayer lifts it onto the trace as a top-level column you can filter on and write tests against. Pass a list to keep the original names:
Each name resolves against the function inputs first, and then against the output — which can be a dict, a Pydantic model, or a dataclass. Both names above come from the returned dict, so the trace gains a score and a confidence column while explanation stays where it is. Pass a dict to rename the columns as you promote them:
A nested step promotes onto the trace it belongs to, not onto itself, so a child step’s fields become top-level columns too. Alias them with the dict form when a parent and a child expose the same field name and would otherwise collide.
A name that matches neither an input nor an output field is skipped with a warning, as is an output that is not a dict, Pydantic model, or dataclass. @trace_async() takes promote with the same semantics.

Step-level metadata

Use update_current_step() to attach metadata to individual steps inside a trace. This is useful for logging retrieval parameters, generation settings, or intermediate results.