Undefined input/output for Spring AI traces when defining userId & sessionId
#9943
-
|
According to the Spring AI integration docs, public String processUserRequest(String userInput, String userId) {
// Create a new span with user and session attributes
Span span = tracer.spanBuilder("user-interaction")
.setAttribute("langfuse.user.id", userId)
.setAttribute("langfuse.session.id", UUID.randomUUID().toString())
.startSpan();
// Make sure to set the new span as active.
try (Scope ignored = span.makeCurrent()) {
// Your AI processing logic here
// Any spans created within this scope will be children of the parent span
String result = performAiOperation(userInput);
return result;
} finally {
span.end();
}
}
private String performAiOperation(String userInput) {
// Your Spring AI code here
// For example:
List<Message> messages = new ArrayList<>();
messages.add(new SystemMessage("You are a helpful assistant."));
messages.add(new UserMessage(userInput));
Prompt prompt = new Prompt(messages);
ChatResponse response = chatClient.call(prompt);
return response.getResult().getOutput().getContent();
}This works and indeed the traces are received with a However, the fact that we're creating a parent trace and then the traces generated by Spring AI are children of the parent one, the Would there be a way to escalate this I believe this behavior is already happening for traces generated via the AI SDK by Vercel: Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
You're correct that when creating a parent span for According to the OpenTelemetry property mapping documentation, trace input and output are set from the root span's observation input and output (1). When you create a custom parent span without setting input/output on it, the trace-level fields remain empty even though child observations contain the actual LLM inputs and outputs. To populate the trace-level input and output fields, you can explicitly set them using OpenTelemetry attributes on your parent span: public String processUserRequest(String userInput, String userId) {
Span span = tracer.spanBuilder("user-interaction")
.setAttribute("langfuse.user.id", userId)
.setAttribute("langfuse.session.id", UUID.randomUUID().toString())
.startSpan();
try (Scope ignored = span.makeCurrent()) {
// Set trace-level input and output attributes
span.setAttribute("langfuse.trace.input", userInput);
String result = performAiOperation(userInput);
// Set trace-level output
span.setAttribute("langfuse.trace.output", result);
return result;
} finally {
span.end();
}
}The key attributes for trace-level data are:
These 📚 Sources: Have another question? Just tag @inkeep. |
Beta Was this translation helpful? Give feedback.




You're correct that when creating a parent span for
userIdandsessionIdwith Spring AI, the trace-level input and output fields appear empty. This is expected behavior based on how Langfuse handles trace input/output mapping (1).According to the OpenTelemetry property mapping documentation, trace input and output are set from the root span's observation input and output (1). When you create a custom parent span without setting input/output on it, the trace-level fields remain empty even though child observations contain the actual LLM inputs and outputs.
To populate the trace-level input and output fields, you can explicitly set them using OpenTelemetry attributes on your parent span:
p…