Merged
Conversation
langsmith-java-core/src/main/kotlin/com/langchain/smith/wrappers/openai/ChatStreamAggregator.kt
Outdated
Show resolved
Hide resolved
langsmith-java-core/src/main/kotlin/com/langchain/smith/wrappers/openai/OpenTelemetryConfig.kt
Show resolved
Hide resolved
langsmith-java-core/src/main/kotlin/com/langchain/smith/wrappers/openai/WrappedChatService.kt
Show resolved
Hide resolved
langsmith-java-core/src/main/kotlin/com/langchain/smith/wrappers/openai/WrappedChatService.kt
Outdated
Show resolved
Hide resolved
langsmith-java-core/src/main/kotlin/com/langchain/smith/wrappers/openai/ChatStreamAggregator.kt
Outdated
Show resolved
Hide resolved
langsmith-java-core/src/main/kotlin/com/langchain/smith/wrappers/openai/ChatStreamAggregator.kt
Outdated
Show resolved
Hide resolved
langsmith-java-core/src/main/kotlin/com/langchain/smith/wrappers/openai/ChatStreamAggregator.kt
Outdated
Show resolved
Hide resolved
Angus Jelinek (angus-langchain)
approved these changes
Mar 9, 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.
Issues
Chat streaming: The span ends when
createStreaming()returned, so the trace was closed before the stream finished. Completion text, tool calls, and token usage were not on the span, andgen_ai.input.messagescould be wrong or empty.Completion format: Non-streaming set
gen_ai.completionto raw assistant text aligned this with streaming.Responses API streaming: Span ended on
createStreamingreturn instead of stream close.OTel integration: No way to attach LangSmith to an existing SdkTracerProvider.
Fix
Chat streaming: End the span in
TracedChatStreamResponse.close()so it closes when the stream is closed. UseChatStreamAggregatorto aggregate content, tool calls, and usage from chunks and apply them inclose(). Always setgen_ai.input.messagesfromformatInputMessages(params), setgen_ai.promptonly when user text is found. Requeststream_options.include_usage=trueso the final chunk includes usage.Completion format: For both streaming and non-streaming, set
gen_ai.completionto a JSON string{"messages":[...]}, with streaming building the assistant message from the aggregator.Responses API streaming: Wrap the stream in
TracedResponseStreamResponseinclose(), useResponseAccumulator.response()to read usage and status and set them on the span, then end the span.OTel config: Add
buildSpanProcessor()that returns aSpanProcessorso callers can add it to an existingSdkTracerProvider. Share setup withbuild()via a privatecreateSpanProcessor()helper.Also added a streaming example:
StreamingLangSmithExample; run with:./gradlew :langsmith-java-example:run -Pexample=StreamingLangSmith