Using the observe decorator/wrapper to structure your traces
observe
decorator (Python) or function wrapper (JavaScript/TypeScript) is the primary way to structure your traces in Laminar. It allows you to:
observe()
.
This is especially helpful when you want to trace functions, or group
separate functions into a single trace.my_function
and the OpenAI call, which is nested inside it, in the same trace. Notice that the OpenAI span is a child of my_function
. Parent-child relationships are automatically detected and visualized with tree hierarchy.
ObserveOptions
)name
(string
): name of the span. If not passed, and the function to observe is not an anonymous arrow function, the function name will be used.sessionId
(string
): session ID for the wrapped trace.userId
(string
): user ID for the wrapped trace.metadata
(Record<string, any>
): metadata for the wrapped trace, must be json serializable.traceType
('DEFAULT'|'EVALUATION'
): Type of the trace. Unless it is within evaluation, it must be 'DEFAULT'
.spanType
('DEFAULT'|'LLM'
) - Type of the span. 'DEFAULT'
is used if not specified. If the type is 'LLM'
,
you must manually specify some attributes. This translates to lmnr.span.type
attribute on the span.traceId
(string
): [experimental] trace ID for the current trace. This is useful if you want to continue an existing trace.
IMPORTANT: must be a valid UUID, i.e. has to include 8-4-4-4-12 hex digits.input
: a dictionary of input parameters. Is preferred over function parameters.ignoreInput
(boolean
): if true
, the input will not be recorded.ignoreOutput
(boolean
): if true
, the output will not be recorded.tags
(string[]
): array of tags to add to the span.lmnr.span.input
) will be {"param1": 1, "param2": 2}
lmnr.span.output
) will be 3
observe
is to group multiple LLM calls into a single trace:
Laminar.start_as_current_span
if you want to trace a specific block of code: