|
4 | 4 | import type { AudioFrame } from '@livekit/rtc-node'; |
5 | 5 | import { AudioResampler } from '@livekit/rtc-node'; |
6 | 6 | import type { Span } from '@opentelemetry/api'; |
| 7 | +import { context as otelContext } from '@opentelemetry/api'; |
7 | 8 | import type { ReadableStream, ReadableStreamDefaultReader } from 'stream/web'; |
8 | 9 | import { |
9 | 10 | type ChatContext, |
@@ -471,9 +472,13 @@ export function performLLMInference( |
471 | 472 | } |
472 | 473 | }; |
473 | 474 |
|
| 475 | + // Capture the current context (agent_turn) to ensure llm_node is properly parented |
| 476 | + const currentContext = otelContext.active(); |
| 477 | + |
474 | 478 | const inferenceTask = async (signal: AbortSignal) => |
475 | 479 | tracer.startActiveSpan(async (span) => _performLLMInferenceImpl(signal, span), { |
476 | 480 | name: 'llm_node', |
| 481 | + context: currentContext, |
477 | 482 | }); |
478 | 483 |
|
479 | 484 | return [ |
@@ -527,8 +532,14 @@ export function performTTSInference( |
527 | 532 | } |
528 | 533 | }; |
529 | 534 |
|
| 535 | + // Capture the current context (agent_turn) to ensure tts_node is properly parented |
| 536 | + const currentContext = otelContext.active(); |
| 537 | + |
530 | 538 | 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 | + }); |
532 | 543 |
|
533 | 544 | return [ |
534 | 545 | Task.from((controller) => inferenceTask(controller.signal), controller, 'performTTSInference'), |
|
0 commit comments