TraceScope

org.llm4s.trace.TraceScope
@Experimental
object 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
class Object
trait Matchable
class Any
Self type
TraceScope.type

Members list

Value members

Concrete methods

The span calls on this thread run under, if any.

The span calls on this thread run under, if any.

Attributes

Source
TraceScope.scala

The span a call on this thread that fails is placed under, if any: current unless the scope names another.

The span a call on this thread that fails is placed under, if any: current unless the scope names another.

Attributes

Source
TraceScope.scala
def under[A](span: TraceContext)(body: => A): A

Runs body with span as the span calls on this thread run under, restoring the previous one after.

Runs body with span as the span calls on this thread run under, restoring the previous one after.

Attributes

Source
TraceScope.scala
def under[A](span: TraceContext, onFailure: TraceContext, usageAccountedElsewhere: Boolean)(body: => A): A

Runs body with span as the span calls on this thread run under and onFailure as the one a call that fails is placed under; usageAccountedElsewhere when another observation reports the calls' usage. The previous scope is restored after.

Runs body with span as the span calls on this thread run under and onFailure as the one a call that fails is placed under; usageAccountedElsewhere when another observation reports the calls' usage. The previous scope is restored after.

Attributes

Source
TraceScope.scala

Whether another observation reports the usage of a call on this thread: an agent's model step says so.

Whether another observation reports the usage of a call on this thread: an agent's model step says so.

Attributes

Source
TraceScope.scala