fix(otel): emit trace_output as span attribute instead of event#9255
Merged
Conversation
trace_output was emitted via tracing::info!() which becomes an OTEL event (log line on the span), not a span attribute. Observability backends like MLflow and Langfuse (via OTEL ingestion) look for span attributes, so the output was invisible to them. Declare trace_output as a field on reply_stream_span and use Span::record() so it becomes a proper OTEL span attribute. The Langfuse custom layer handles both paths identically (on_record and on_event both call handle_record), so this is a no-op for that path. Fixes #8586 Signed-off-by: Douwe Osinga <douwe@squareup.com>
alexhancock
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
trace_outputwas emitted viatracing::info!()which becomes an OTEL event (a log line attached to the span), not a span attribute. Observability backends like MLflow and Langfuse (via OTEL ingestion) look for span attributes to populate input/output fields, so the assistant output was invisible to them.Changes
trace_outputas a field onreply_stream_spanso it can accept a recorded valuetracing::info!(trace_output = ...)withtracing::Span::current().record("trace_output", ...)to set it as a proper span attributeThe Langfuse custom layer's
on_recordandon_eventboth callhandle_recordwith the same metadata, so this change is transparent to the Langfuse-specific path.Fixes #8586