OtlpObserver
Sends the runs of a graph as traces to an OpenTelemetry collector, or to any backend that receives OTLP over HTTP, on every platform: Android, iOS, desktop, servers and the browser. Give it to a run with GraphConfig.observers:
val tracing = OtlpObserver(httpClient, appScope, endpoint = "https://collector.example.com/v1/traces")
graph.invoke(order, GraphConfig(observers = listOf(tracing)))The spans are the same as those of OpenTelemetryObserver, which is for the JVM. 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.
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, as an event
exceptionand the statusERROR. A cancelled node or run is not an error.
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, so that a backend that knows them shows them as calls to a model:
telar.run telar.thread_id=ticket-42
├─ telar.node model telar.step=1
│ └─ chat gpt-5 gen_ai.request.model=gpt-5 gen_ai.usage.input_tokens=812
├─ telar.node tools telar.step=2
│ └─ execute_tool order_status gen_ai.tool.call.id=toolu_01...
└─ telar.node model telar.step=3
└─ chat gpt-5 gen_ai.request.model=gpt-5 gen_ai.usage.input_tokens=901A 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 an eventexception.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 cannot be current while it runs: 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.
Sending. A span is sent when it ends, together with the others that end within exportDelay, as OTLP/HTTP with JSON, in a coroutine of scope. The app creates the client, with the engine of its platform, and closes it. Nothing is ever thrown into a run: a request that fails is reported to onExportFailed and its spans are dropped. When more spans wait than can be sent, the oldest are dropped. Call flush before the app ends, so that the last spans are sent.
In the browser, the collector has to allow the origin of the page, for example with cors.allowed_origins in the http protocol of the otlp receiver of the OpenTelemetry Collector. A key in headers can be read by everyone who opens the page.
What a node calls. While a node or the condition of an edge runs, its coroutine context holds a TraceContext with the ids of its span. The Traceparent plugin of Ktor sends them with each request, so that a server of the app records its spans inside the node.
Inside a trace of the app. A run is a trace of its own, unless its coroutine context holds a TraceContext: then the run is inside that span. The app puts one there, for example from the traceparent header of the request that started the run (see TraceContext.parse), and a run started inside a node traced by an OtlpObserver already has the one of that node.
Parameters
sends the spans. Its engine decides the platform: Js in the browser, Darwin on iOS, OkHttp on Android, CIO or Java on the JVM.
the coroutines that send the spans run in it. Cancel it, and nothing more is sent except by flush.
the URL of the traces, /v1/traces of the collector. The default is a collector on the same machine.
the service.name of the spans, the name a backend shows for the app.
more attributes of the app, such as service.version or deployment.environment.
sent with each request, for example the key of a backend that receives OTLP itself.
how long a span that ended waits for others before they are sent together.
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.
told when spans could not be sent. It must not throw.
Throws
if endpoint is blank, exportDelay is negative or maxContentLength is less than 1.
Constructors
Functions
Sends every span that ended and was not sent yet, and returns when the collector answered. Call it before the app ends, or when a page in the browser is hidden. A span that has not ended, of a run that is still going, is sent when it ends. Failures go to onExportFailed.