Skip to content

Commit d650f84

Browse files
committed
.
1 parent dde4896 commit d650f84

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

packages/core/src/tracing/openai/streaming.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { SPAN_STATUS_ERROR } from '../../tracing';
33
import type { Span } from '../../types-hoist/span';
44
import { endStreamSpan } from '../ai/utils';
55
import { RESPONSE_EVENT_TYPES } from './constants';
6+
import { setCommonResponseAttributes, setTokenUsageAttributes } from './utils';
67
import type {
78
ChatCompletionChunk,
89
ChatCompletionToolCall,
@@ -235,6 +236,8 @@ export async function* instrumentStream<T>(
235236
yield event;
236237
}
237238
} finally {
239+
setCommonResponseAttributes(span, state.responseId, state.responseModel, state.responseTimestamp);
240+
setTokenUsageAttributes(span, state.promptTokens, state.completionTokens, state.totalTokens);
238241
const allToolCalls = [...Object.values(state.chatCompletionToolCalls), ...state.responsesApiToolCalls];
239242
endStreamSpan(span, { ...state, toolCalls: allToolCalls }, recordOutputs);
240243
}

0 commit comments

Comments
 (0)