TraceScope
The span a call on this thread runs under (#2950), so a traced client can place its event in the caller's trace without a change to its signature: an agent runs each model call under the run's chat span, and a TracingLLMClient called inside places its TraceEvent.CompletionReceived - the call's content, which a backend records only when it captures content - as a child of that span.
TraceScope.under(callSpan) {
tracedClient.complete(conversation) // its event is a child of callSpan
}
A scope may name a separate parent for a call that fails (failureParent): the span the caller places a successful call under may only be emitted when the call succeeds - an agent's chat span comes from the call's completion - so a failed call's error goes under a span that exists either way, the agent run's own.
A scope may also say that another observation accounts for the call's usage (usageAccountedElsewhere): an agent's chat span reports each model call's tokens, so a traced client called inside the agent's model step leaves its usage out, and the call is billed once. A scope of your own leaves the usage on the call.
The scope is the calling thread's, for the duration of body: work body hands to another thread does not see it, and it is restored when body returns or throws. Scopes nest.
Attributes
- Source
- TraceScope.scala
- Graph
-
- Supertypes
- Self type
-
TraceScope.type
