StartFallback begins a runtime.fallback span covering the whole fallback chain for one agent turn. Each per-model attempt produces its own `chat {model}` CLIENT child span (created by the provider decorator). Attributes set up front: primary model name, agent name, in-cooldown flag. The caller updat
(ctx context.Context, agentName, primaryModel string, inCooldown bool)
| 64 | // flag. The caller updates final model / attempts / outcome through the |
| 65 | // returned handle and calls End to flush. |
| 66 | func StartFallback(ctx context.Context, agentName, primaryModel string, inCooldown bool) (context.Context, *FallbackSpan) { |
| 67 | tracer := otel.Tracer(instrumentationName) |
| 68 | attrs := []attribute.KeyValue{ |
| 69 | attribute.String(AttrAgentNameRuntime, agentName), |
| 70 | attribute.Bool(AttrFallbackInCooldown, inCooldown), |
| 71 | } |
| 72 | if primaryModel != "" { |
| 73 | attrs = append(attrs, attribute.String(AttrFallbackPrimaryModel, primaryModel)) |
| 74 | } |
| 75 | if conv, ok := conversationAttribute(ctx); ok { |
| 76 | attrs = append(attrs, conv) |
| 77 | } |
| 78 | ctx, span := tracer.Start(ctx, "runtime.fallback", |
| 79 | trace.WithSpanKind(trace.SpanKindInternal), |
| 80 | trace.WithAttributes(attrs...), |
| 81 | ) |
| 82 | return ctx, &FallbackSpan{ |
| 83 | span: span, |
| 84 | startedAt: time.Now(), |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // IncrementAttempt counts one attempt against the chain. Called once per |
| 89 | // (model × retry) iteration so the final span carries the total count. |
no test coverage detected