Skip to content

Commit 780d42e

Browse files
committed
Update generation.ts
1 parent 18aae68 commit 780d42e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

agents/src/voice/generation.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import type { AudioFrame } from '@livekit/rtc-node';
55
import { AudioResampler } from '@livekit/rtc-node';
66
import type { Span } from '@opentelemetry/api';
7+
import { context as otelContext } from '@opentelemetry/api';
78
import type { ReadableStream, ReadableStreamDefaultReader } from 'stream/web';
89
import {
910
type ChatContext,
@@ -471,9 +472,13 @@ export function performLLMInference(
471472
}
472473
};
473474

475+
// Capture the current context (agent_turn) to ensure llm_node is properly parented
476+
const currentContext = otelContext.active();
477+
474478
const inferenceTask = async (signal: AbortSignal) =>
475479
tracer.startActiveSpan(async (span) => _performLLMInferenceImpl(signal, span), {
476480
name: 'llm_node',
481+
context: currentContext,
477482
});
478483

479484
return [
@@ -527,8 +532,14 @@ export function performTTSInference(
527532
}
528533
};
529534

535+
// Capture the current context (agent_turn) to ensure tts_node is properly parented
536+
const currentContext = otelContext.active();
537+
530538
const inferenceTask = async (signal: AbortSignal) =>
531-
tracer.startActiveSpan(async () => _performTTSInferenceImpl(signal), { name: 'tts_node' });
539+
tracer.startActiveSpan(async () => _performTTSInferenceImpl(signal), {
540+
name: 'tts_node',
541+
context: currentContext,
542+
});
532543

533544
return [
534545
Task.from((controller) => inferenceTask(controller.signal), controller, 'performTTSInference'),

0 commit comments

Comments
 (0)