类 OtelTracingMiddleware

java.lang.Object
io.agentscope.core.tracing.OtelTracingMiddleware
所有已实现的接口:
MiddlewareBase

public class OtelTracingMiddleware extends Object implements MiddlewareBase
Middleware that adds OpenTelemetry tracing to the agent lifecycle.

Produces spans for:

  • invoke_agent <name> — wraps the entire reply
  • chat <model> — wraps each model API call
  • execute_tool <name> — wraps each tool execution

When no OTel SDK is configured (only the default no-op provider is active), every hook short-circuits to next.apply(input) with near-zero overhead.

Usage:


 ReActAgent agent = ReActAgent.builder()
     .name("assistant")
     .model(model)
     .middleware(new OtelTracingMiddleware())
     .build();
 
  • 构造器详细资料

    • OtelTracingMiddleware

      public OtelTracingMiddleware()
  • 方法详细资料

    • onAgent

      public reactor.core.publisher.Flux<AgentEvent> onAgent(Agent agent, RuntimeContext ctx, AgentInput input, Function<AgentInput,reactor.core.publisher.Flux<AgentEvent>> next)
      从接口复制的说明: MiddlewareBase
      Intercept the entire agent invocation.
      指定者:
      onAgent 在接口中 MiddlewareBase
      参数:
      agent - the agent instance
      ctx - per-call runtime context (session, user, attributes)
      input - agent input (messages)
      next - calls the next middleware or the core agent logic
      返回:
      event stream from the agent invocation
    • onModelCall

      public reactor.core.publisher.Flux<AgentEvent> onModelCall(Agent agent, RuntimeContext ctx, ModelCallInput input, Function<ModelCallInput,reactor.core.publisher.Flux<AgentEvent>> next)
      从接口复制的说明: MiddlewareBase
      Intercept the raw model API call.
      指定者:
      onModelCall 在接口中 MiddlewareBase
      参数:
      agent - the agent instance
      ctx - per-call runtime context (session, user, attributes)
      input - model-call input (messages, tools, options, model)
      next - calls the next middleware or the actual model invocation
      返回:
      event stream from the model call
    • onActing

      public reactor.core.publisher.Flux<AgentEvent> onActing(Agent agent, RuntimeContext ctx, ActingInput input, Function<ActingInput,reactor.core.publisher.Flux<AgentEvent>> next)
      从接口复制的说明: MiddlewareBase
      Intercept the tool-call execution phase.
      指定者:
      onActing 在接口中 MiddlewareBase
      参数:
      agent - the agent instance
      ctx - per-call runtime context (session, user, attributes)
      input - acting input (the tool calls)
      next - calls the next middleware or the core acting logic
      返回:
      event stream from acting