(outcome, error, cancelReason)
| 456 | |
| 457 | let finished = false |
| 458 | const finish: CopilotOtelRoot['finish'] = (outcome, error, cancelReason) => { |
| 459 | if (finished) return |
| 460 | finished = true |
| 461 | const resolvedOutcome = outcome ?? RequestTraceV1Outcome.success |
| 462 | span.setAttribute(TraceAttr.CopilotRequestOutcome, resolvedOutcome) |
| 463 | // Policy: `explicit_stop` is the ONLY cancellation we treat as |
| 464 | // expected (status unset → dashboards see it as OK). Everything |
| 465 | // else — client_disconnect, unknown reason, bug-case cancels — |
| 466 | // escalates to ERROR so it shows up on error panels. |
| 467 | const isExplicitStop = cancelReason === CopilotRequestCancelReason.ExplicitStop |
| 468 | if (error) { |
| 469 | markSpanForError(span, error) |
| 470 | if (isExplicitStop || isExplicitUserStopError(error)) { |
| 471 | span.setStatus({ code: SpanStatusCode.OK }) |
| 472 | } |
| 473 | } else if (resolvedOutcome === RequestTraceV1Outcome.success) { |
| 474 | span.setStatus({ code: SpanStatusCode.OK }) |
| 475 | } else if (resolvedOutcome === RequestTraceV1Outcome.cancelled) { |
| 476 | if (isExplicitStop) { |
| 477 | span.setStatus({ code: SpanStatusCode.OK }) |
| 478 | } else { |
| 479 | span.setStatus({ |
| 480 | code: SpanStatusCode.ERROR, |
| 481 | message: `cancelled: ${cancelReason ?? 'unknown'}`, |
| 482 | }) |
| 483 | } |
| 484 | } |
| 485 | span.end() |
| 486 | } |
| 487 | |
| 488 | return { |
| 489 | span, |
nothing calls this directly
no test coverage detected