langfuse-java icon indicating copy to clipboard operation
langfuse-java copied to clipboard

The update event functions do not update output.

Open paris0120 opened this issue 9 months ago • 9 comments

The only field it updates it end time I think. It would be nice if it could update the output after the execution.

paris0120 avatar Mar 15 '25 15:03 paris0120

@paris0120 This should be possible. Can you share an example of what you have tried?

Steffen911 avatar Mar 16 '25 07:03 Steffen911

public IngestionEvent updateGenerationEvent(LangfuseId id, Object output, ChatCompletionResponseUsage usage, ObservationLevel level) {
    OffsetDateTime currentTime = OffsetDateTime.now();
    String currentTimestamp = currentTime.toString();
    OpenAiUsage openAiUsage = OpenAiUsage.builder()
            .completionTokens(usage.getCompletion_tokens())
            .promptTokens(usage.getPrompt_tokens())
            .totalTokens(usage.getTotal_tokens())
            .build();

    IngestionUsage ingestionUsage = IngestionUsage.of(openAiUsage);
    UpdateGenerationBody._FinalStage body = UpdateGenerationBody.builder()
            .id(id.getEventId())
            .traceId(id.getTraceId())
            .parentObservationId(id.getParentEventId())
            .output(output)
            .endTime(currentTime)
            .usage(ingestionUsage);

    if (level != null) {
        body.level(level);
    }

    UpdateGenerationEvent event = UpdateGenerationEvent
            .builder()
            .id(id.getEventId())
            .timestamp(currentTimestamp)
            .body(body.build())
            .build();

    return IngestionEvent.generationUpdate(event);
}

endtime is updated but not output

paris0120 avatar Mar 16 '25 13:03 paris0120

@paris0120 Are you using this with the langfuse cloud version? If yes, could you share the traceId you use? That would help me check the raw events that are received.

Alternatively, you could check in your S3/Minio bucket what is uploaded in /events/<projectId>/observation/<observationId>/<eventId>.json. There should be two files there one for the initial create and one for the update. Could you share both with redacted data in case it's sensitive?

Steffen911 avatar Mar 17 '25 07:03 Steffen911

No I have only one file there. It doesn't update the end time too.

paris0120 avatar Mar 21 '25 12:03 paris0120

Image

paris0120 avatar Mar 21 '25 13:03 paris0120

Also why there is no way to update trace. It will be nice if we can update the output at least

paris0120 avatar Mar 23 '25 12:03 paris0120

@paris0120 Do you set different eventIds on the update? The id on the surrounding event must be different to avoid overwrites on the cloud storage.

Regarding the trace: You can just use the trace-create event multiple times and it will always perform upsert operations.

Steffen911 avatar Mar 25 '25 08:03 Steffen911

Hi Steffen, If don't use spring AI or langchain4j. Can langfuse monitor normal Springboot project. like I use simple api call to LLM. how the langfuse monitor this model. Do your have more example ? many thanks

Namelesschz avatar Apr 03 '25 02:04 Namelesschz

@Namelesschz We don't have an example for java, but you could use the otel semantic conventions and add attributes on your traces to track LLM calls. You can find all attributes here: https://langfuse.com/docs/opentelemetry/get-started#property-mapping.

EDIT: Lets continue the example conversation in https://github.com/langfuse/langfuse-java/issues/8.

Steffen911 avatar Apr 03 '25 07:04 Steffen911