|
1 | 1 | import { SeverityNumber } from "@opentelemetry/api-logs" |
2 | | -import { SpanStatusCode, SpanKind, context, trace } from "@opentelemetry/api" |
| 2 | +import { SpanStatusCode, SpanKind, trace } from "@opentelemetry/api" |
3 | 3 | import type { AssistantMessage, EventMessageUpdated, EventMessagePartUpdated, ToolPart } from "@opencode-ai/sdk" |
4 | 4 | import { |
5 | 5 | AGENT_NAME, |
@@ -256,9 +256,10 @@ export function handleMessagePartUpdated(e: EventMessagePartUpdated, ctx: Handle |
256 | 256 | const toolSpan = isTraceEnabled("tool", ctx) |
257 | 257 | ? (() => { |
258 | 258 | const sessionSpan = ctx.sessionSpans.get(toolPart.sessionID) |
| 259 | + const baseCtx = ctx.rootContext() |
259 | 260 | const parentCtx = sessionSpan |
260 | | - ? trace.setSpan(context.active(), sessionSpan) |
261 | | - : context.active() |
| 261 | + ? trace.setSpan(baseCtx, sessionSpan) |
| 262 | + : baseCtx |
262 | 263 | return ctx.tracer.startSpan( |
263 | 264 | `${ctx.tracePrefix}tool.${toolPart.tool}`, |
264 | 265 | { |
@@ -311,9 +312,10 @@ export function handleMessagePartUpdated(e: EventMessagePartUpdated, ctx: Handle |
311 | 312 | if (isTraceEnabled("tool", ctx)) { |
312 | 313 | const toolSpan = pending?.span ?? (() => { |
313 | 314 | const sessionSpan = ctx.sessionSpans.get(toolPart.sessionID) |
| 315 | + const baseCtx = ctx.rootContext() |
314 | 316 | const parentCtx = sessionSpan |
315 | | - ? trace.setSpan(context.active(), sessionSpan) |
316 | | - : context.active() |
| 317 | + ? trace.setSpan(baseCtx, sessionSpan) |
| 318 | + : baseCtx |
317 | 319 | return ctx.tracer.startSpan( |
318 | 320 | `${ctx.tracePrefix}tool.${toolPart.tool}`, |
319 | 321 | { |
@@ -408,9 +410,10 @@ export function startMessageSpan( |
408 | 410 | const msgKey = `${sessionID}:${messageID}` |
409 | 411 | if (ctx.messageSpans.has(msgKey)) return |
410 | 412 | const sessionSpan = ctx.sessionSpans.get(sessionID) |
| 413 | + const baseCtx = ctx.rootContext() |
411 | 414 | const parentCtx = sessionSpan |
412 | | - ? trace.setSpan(context.active(), sessionSpan) |
413 | | - : context.active() |
| 415 | + ? trace.setSpan(baseCtx, sessionSpan) |
| 416 | + : baseCtx |
414 | 417 |
|
415 | 418 | const msgSpan = ctx.tracer.startSpan( |
416 | 419 | `${ctx.tracePrefix}llm`, |
|
0 commit comments