Skip to content

fix(langfuse): fix latency display showing incorrect huge hours value#688

Open
favbox wants to merge 2 commits intocloudwego:mainfrom
favbox:fix/langfuse-duration-field
Open

fix(langfuse): fix latency display showing incorrect huge hours value#688
favbox wants to merge 2 commits intocloudwego:mainfrom
favbox:fix/langfuse-duration-field

Conversation

@favbox
Copy link
Copy Markdown

@favbox favbox commented Feb 10, 2026

Problem

Langfuse UI was displaying incorrect latency values like "17751749h 37m 57s"
instead of the actual duration in milliseconds (e.g., "854ms").

Root Cause

The callback handler was not preserving the original startTime when
updating spans/generations in OnEnd. This caused the startTime to be
reset to zero value ("0001-01-01T00:00:00Z"), which Langfuse backend
uses to calculate latency as endTime - startTime, resulting in a
massive time difference.

Solution

  1. Add Duration field (milliseconds) to SpanEventBody and
    GenerationEventBody in event data model
  2. Store startTime in callback state during OnStart
  3. Preserve original startTime and calculate duration in OnEnd

Changes

  • libs/acl/langfuse/event.go: Add Duration *int64 field (milliseconds)
  • callbacks/langfuse/langfuse.go: Track startTime and compute duration

Testing

Before fix: Latency: 17751749h 37m 57s
After fix: Latency: 854ms


Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

## Problem
Langfuse UI was displaying incorrect latency values like "17751749h"
instead of the actual duration in milliseconds (e.g., "854ms").

## Root Cause
The callback handler was not preserving the original `startTime` when
updating spans/generations in `OnEnd`. This caused the `startTime` to be
reset to zero value ("0001-01-01T00:00:00Z"), which Langfuse backend
uses to calculate latency as `endTime - startTime`, resulting in a
massive time difference.

## Solution
1. Add `Duration` field (milliseconds) to `SpanEventBody` and
   `GenerationEventBody` in event data model
2. Store `startTime` in callback state during `OnStart`
3. Preserve original `startTime` and calculate `duration` in `OnEnd`

## Changes
- `libs/acl/langfuse/event.go`: Add `Duration *int64` field
- `callbacks/langfuse/langfuse.go`: Track startTime and compute duration
- `callbacks/langfuse/go.mod`: Add local replace for development

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 10, 2026

CLA assistant check
All committers have signed the CLA.

@shentongmartin shentongmartin added C-enhancement This is a PR that adds a new feature or fixes a bug. D-tracing Domain: this issue relates to tracing capability based on callback mechanism labels Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-enhancement This is a PR that adds a new feature or fixes a bug. D-tracing Domain: this issue relates to tracing capability based on callback mechanism

Development

Successfully merging this pull request may close these issues.

3 participants