Skip to content

[Bug]: OtelTracingMiddleware does not record message content — input/output always empty in OTLP backends #1939

Description

@Buktal

Describe the bug

OtelTracingMiddleware.onModelCall only records message count and token usage. It does not serialize the actual content of input messages or the model response text into span attributes or events. As a result, OTLP-compatible backends (e.g. Langfuse) show empty input/output for every trace.

To Reproduce

ReActAgent agent = ReActAgent.builder()
    .name("assistant")
    .model(model)
    .middleware(new OtelTracingMiddleware())
    .build();

Invoke the agent with any user message. Observe in Langfuse (or any OTLP backend):

  • The chat <model> span shows gen_ai.request.messages.count and token counts.
  • Input messages and response content are empty.

Expected behavior

The span should include the full content of input messages and the model response, following the OpenTelemetry GenAI semantic conventions (gen_ai.prompt.* / gen_ai.completion.*, or equivalent span events).

Error messages

No exception. Input/output fields are silently empty.

Root cause

Current onModelCall implementation:

.setAttribute("gen_ai.request.messages.count", (long) input.messages().size())
// message content never written

// doOnNext only handles token counts:
private void setModelResponseAttributes(Span span, ModelCallEndEvent event) {
    span.setAttribute("gen_ai.usage.input_tokens", (long) usage.getInputTokens());
    span.setAttribute("gen_ai.usage.output_tokens", (long) usage.getOutputTokens());
    // response text never written
}

The deprecated TelemetryTracer used getLLMRequestAttributes and getLLMResponseAttributes helpers (in AttributesExtractors) to serialize full message content. OtelTracingMiddleware has no equivalent implementation.

Environment

  • AgentScope-Java Version: 2.0.0-RC4
  • Java Version: 21
  • OS: Windows 11

Additional context

This is a functional regression compared to the deprecated TelemetryTracer. The fix requires serializing input.messages() content into span attributes or events on onModelCall, and extracting the response text from ModelCallEndEvent to write as the output attribute.

Related to #1938 (orphan span issue) — both need to be fixed together for OtelTracingMiddleware to be a viable replacement for TelemetryTracer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions