OpenTelemetryObserver
Sends the runs of a graph to OpenTelemetry as traces. Give it to a run with GraphConfig.observers:
val tracing = OpenTelemetryObserver(openTelemetry)
graph.invoke(order, GraphConfig(observers = listOf(tracing)))A run is a span named telar.run, and each node a span named telar.node <name> inside it. A subgraph is a telar.run inside the span of the node that runs it. A run started inside a span, such as the span of a request to a server, is a child of that span.
The run has the attributes
telar.thread_idandtelar.outcome(completed,interrupted,failedorcancelled), andtelar.next_nodeswhen it paused. It has an eventtelar.stepfor each step, with the nodes that ran and those that the edges chose next, and an eventtelar.checkpointfor each saved checkpoint.A node has the attributes
telar.node,telar.stepandtelar.outcome, and an eventtelar.retryfor each try that failed and was followed by another.An edge with a condition is a span
telar.edge <from>inside the run, withtelar.edge.from,telar.step(the step whose results it routes, 0 for an edge fromSTART),telar.outcome, andtelar.next_nodes, what the condition chose. A plain edge has no span.A failure is recorded on the span of the node and of the run, with the status
ERROR. A cancelled node or run is not an error.
The span of a node is current while the node runs, and that of an edge while its condition runs, so the spans of what they call, such as an HTTP client with OpenTelemetry instrumentation, are inside them.
Calls to models and tools. It is also an AgentObserver, so the calls that a node of toolLoop or toolAgent, ask, chatWithProgress or a ChatDecisionModel makes are spans inside the span of the node, or of the edge for the condition of a decisionEdge, named as the semantic conventions for generative AI name them:
A call to a model is a span
chat <model>of kindCLIENT, withgen_ai.operation.name,gen_ai.request.model(the name of the model),gen_ai.response.model(the model that answered, when the provider says), and the tokens its provider reported:gen_ai.usage.input_tokens(the tokens read from a cache included) andgen_ai.usage.output_tokens, andgen_ai.usage.cache_read.input_tokensandgen_ai.usage.cache_write.input_tokenswhen they are not 0. A backend prices the call with the model and the tokens. A model whose name is not known, such as one of your own that does not override it, gives a spanchatwithoutgen_ai.request.model. A call that failed has the statusERROR, anerror.typeand the exception.A tool call is a span
execute_tool <name>, withgen_ai.tool.nameandgen_ai.tool.call.id. A tool that returned an error to the model has the statusERRORanderror.typetool_error, although the run goes on. A call that ended without a result, because the run was cancelled or paused, has no status: the span of the node says what happened.
Observer functions are not suspend, so the span of a call is not current while it runs: the span of the HTTP request of a model is inside the span of the node, next to the span chat.
The state of the run is never recorded, nor what a node reports with reportProgress: both can hold personal data.
The conversation, with recordContent: the span of a model call gets what it sent (gen_ai.system_instructions and gen_ai.input.messages) and the answer (gen_ai.output.messages), and the span of a tool call its input (gen_ai.tool.call.arguments) and result (gen_ai.tool.call.result), as JSON in strings, as the conventions write them. A backend such as Langfuse shows them as the input and output of the call. Each text is cut at maxContentLength characters, with a note of how long it was. An image or a PDF becomes a note of its type and size, such as [image/png, 47 KB]: its bytes are never recorded. Nor is the providerContent of a message, such as the thinking of Claude, nor the tools the model was offered. The conversation can hold personal data, such as what the users of the app wrote, so it is off by default: turn it on only when you know who can read the traces.
Parameters
where the spans go. The default is the instance that the OpenTelemetry Java agent or GlobalOpenTelemetry.set registered, which records nothing when there is none.
records the messages of each model call and the input and result of each tool call. Off by default, because they can hold personal data.
the most characters of each text that recordContent records.
Throws
if maxContentLength is less than 1.