()
| 235 | } |
| 236 | |
| 237 | export function endInteractionSpan(): void { |
| 238 | const spanContext = interactionContext.getStore() |
| 239 | if (!spanContext) { |
| 240 | return |
| 241 | } |
| 242 | |
| 243 | if (spanContext.ended) { |
| 244 | return |
| 245 | } |
| 246 | |
| 247 | // End Perfetto span |
| 248 | if (spanContext.perfettoSpanId) { |
| 249 | endInteractionPerfettoSpan(spanContext.perfettoSpanId) |
| 250 | } |
| 251 | |
| 252 | if (!isAnyTracingEnabled()) { |
| 253 | spanContext.ended = true |
| 254 | activeSpans.delete(getSpanId(spanContext.span)) |
| 255 | // Clear the store so async continuations created after this point (timers, |
| 256 | // promise callbacks, I/O) do not inherit a reference to the ended span. |
| 257 | // enterWith(undefined) is intentional: exit(() => {}) is a no-op because it |
| 258 | // only suppresses the store inside the callback and returns immediately. |
| 259 | interactionContext.enterWith(undefined) |
| 260 | return |
| 261 | } |
| 262 | |
| 263 | const duration = Date.now() - spanContext.startTime |
| 264 | spanContext.span.setAttributes({ |
| 265 | 'interaction.duration_ms': duration, |
| 266 | }) |
| 267 | |
| 268 | spanContext.span.end() |
| 269 | spanContext.ended = true |
| 270 | activeSpans.delete(getSpanId(spanContext.span)) |
| 271 | interactionContext.enterWith(undefined) |
| 272 | } |
| 273 | |
| 274 | export function startLLMRequestSpan( |
| 275 | model: string, |
no test coverage detected