fix: surface provider decision in otel diagnostics

This commit is contained in:
Codex
2026-07-01 16:39:40 +00:00
parent 0dcdf0f5f7
commit 6222744119
3 changed files with 112 additions and 1 deletions
@@ -90,6 +90,13 @@ IMPORTANT_ATTRS = [
"error.code", "error.category", "error.layer",
"stage", "causeStage", "causeCode",
"eventType", "runnerId", "attemptId", "backendProfile",
"providerProfile", "model", "modelId", "providerModel",
"code_agent.stage", "agent.chat.session_id",
"agent.chat.provider_profile", "agent.chat.provider_profile_source",
"agent.chat.model", "agent.chat.model_id", "agent.chat.provider_model",
"defaultProviderProfile", "adapter", "adapterEnabled",
"agentRunManagerHost", "agentRunRunnerNamespace",
"agentRunSourceCommitPresent",
"sourceCommit", "jobName", "podName", "logPath",
"toolName", "type", "itemType", "itemId", "status", "exitCode",
"durationMs", "cwd", "processId", "command", "commandFingerprint",
@@ -407,6 +414,13 @@ IMPORTANT_ATTRS = [
"error.code", "error.category", "error.layer",
"stage", "causeStage", "causeCode",
"eventType", "runnerId", "attemptId", "backendProfile",
"providerProfile", "model", "modelId", "providerModel",
"code_agent.stage", "agent.chat.session_id",
"agent.chat.provider_profile", "agent.chat.provider_profile_source",
"agent.chat.model", "agent.chat.model_id", "agent.chat.provider_model",
"defaultProviderProfile", "adapter", "adapterEnabled",
"agentRunManagerHost", "agentRunRunnerNamespace",
"agentRunSourceCommitPresent",
"sourceCommit", "jobName", "podName", "logPath",
"toolName", "type", "itemType", "itemId", "status", "exitCode",
"durationMs", "cwd", "processId", "command", "commandFingerprint",
@@ -972,6 +986,13 @@ IMPORTANT_ATTRS = [
"error.code", "error.category", "error.layer",
"stage", "causeStage", "causeCode",
"eventType", "runnerId", "attemptId", "backendProfile",
"providerProfile", "model", "modelId", "providerModel",
"code_agent.stage", "agent.chat.session_id",
"agent.chat.provider_profile", "agent.chat.provider_profile_source",
"agent.chat.model", "agent.chat.model_id", "agent.chat.provider_model",
"defaultProviderProfile", "adapter", "adapterEnabled",
"agentRunManagerHost", "agentRunRunnerNamespace",
"agentRunSourceCommitPresent",
"sourceCommit", "jobName", "podName", "logPath",
"toolName", "type", "itemType", "itemId", "status", "exitCode",
"durationMs", "cwd", "processId", "command", "commandFingerprint",
@@ -1412,6 +1433,13 @@ def tiny_span(item):
"hwlab.live_builds.service_id", "hwlab.live_builds.service_kind",
"hwlab.live_builds.external", "hwlab.live_builds.deploy_manifest_status",
"hwlab.live_builds.artifact_catalog_status",
"providerProfile", "model", "modelId", "providerModel",
"code_agent.stage", "agent.chat.session_id",
"agent.chat.provider_profile", "agent.chat.provider_profile_source",
"agent.chat.model", "agent.chat.model_id", "agent.chat.provider_model",
"defaultProviderProfile", "adapter", "adapterEnabled",
"agentRunManagerHost", "agentRunRunnerNamespace",
"agentRunSourceCommitPresent",
):
if key in attrs:
keep_attrs[key] = attrs[key]
@@ -1450,6 +1478,55 @@ def identity_from_spans(spans):
identity[key] = preferred if preferred is not None else fallback
return identity
def attr_first(attrs, keys):
if not isinstance(attrs, dict):
return None
for key in keys:
value = attrs.get(key)
if value not in (None, ""):
return value
return None
def provider_decision_summary(spans):
rows = []
for item in spans:
attrs = item.get("attributes", {}) if isinstance(item.get("attributes"), dict) else {}
name = str(item.get("name") or "")
if name != "provider_decision" and attr_first(attrs, ("agent.chat.provider_profile", "providerProfile", "defaultProviderProfile")) in (None, ""):
continue
row = {
"span": name or None,
"service": item.get("service"),
"traceId": attr_first(attrs, ("traceId", "workbench.trace_id", "workbench.turn_id")),
"sessionId": attr_first(attrs, ("agent.chat.session_id", "sessionId", "workbench.session_id")),
"providerProfile": attr_first(attrs, ("agent.chat.provider_profile", "providerProfile", "backendProfile", "defaultProviderProfile")),
"providerProfileSource": attr_first(attrs, ("agent.chat.provider_profile_source", "providerProfileSource")),
"defaultProviderProfile": attr_first(attrs, ("defaultProviderProfile",)),
"model": attr_first(attrs, ("agent.chat.model", "agent.chat.model_id", "agent.chat.provider_model", "model", "modelId", "providerModel")),
"adapter": attr_first(attrs, ("adapter",)),
"adapterEnabled": attr_first(attrs, ("adapterEnabled",)),
"managerHost": attr_first(attrs, ("agentRunManagerHost",)),
"runnerNamespace": attr_first(attrs, ("agentRunRunnerNamespace",)),
"sourceCommitPresent": attr_first(attrs, ("agentRunSourceCommitPresent",)),
}
compact = {key: value for key, value in row.items() if value not in (None, "")}
if compact:
rows.append(compact)
primary = rows[0] if rows else {}
return {
"providerProfile": primary.get("providerProfile"),
"providerProfileSource": primary.get("providerProfileSource"),
"defaultProviderProfile": primary.get("defaultProviderProfile"),
"model": primary.get("model"),
"adapter": primary.get("adapter"),
"adapterEnabled": primary.get("adapterEnabled"),
"managerHost": primary.get("managerHost"),
"runnerNamespace": primary.get("runnerNamespace"),
"sourceCommitPresent": primary.get("sourceCommitPresent"),
"spanCount": len(rows),
"decisions": rows[:5],
}
def span_business_trace_id(item):
attrs = item.get("attributes", {}) if isinstance(item.get("attributes"), dict) else {}
for key in ("traceId", "workbench.trace_id", "workbench.turn_id"):
@@ -2036,6 +2113,7 @@ def candidate_score(trace_id, meta, trace_body, trace_rc, trace_err):
"terminalStatus": agentrun.get("terminalStatus"),
"errorSpanCount": len(error_spans),
"businessTraceScope": business_scope,
"providerDecision": provider_decision_summary(spans),
"candidateQuality": candidate_quality,
"lowConfidence": candidate_quality != "normal",
"rootTraceName": meta_root_name or None,
@@ -2187,6 +2265,7 @@ idle_warning_spans = [item for item in spans if str(item.get("name") or "") == "
http_summary = http_status_summary(spans)
read_model = hwlab_read_model_summary(spans)
identity = identity_from_spans(spans)
provider_decision = provider_decision_summary(spans)
agentrun_authority = agentrun_authority_summary(identity)
agentrun = agentrun_summary(spans, agentrun_authority)
lag = projection_lag_summary(agentrun, read_model)
@@ -2254,6 +2333,9 @@ summary = {
"failureKind": agentrun.get("failureKind"),
"observabilityGap": observability_gap.get("status"),
"businessTraceScope": business_scope.get("mode"),
"providerProfile": provider_decision.get("providerProfile"),
"providerModel": provider_decision.get("model"),
"providerAdapter": provider_decision.get("adapter"),
},
}
evidence = {
@@ -2284,6 +2366,7 @@ payload = {
"observabilityGap": observability_gap,
"businessTraceIds": business_trace_ids[:20],
"businessTraceScope": business_scope,
"providerDecision": provider_decision,
"identity": identity,
"agentrun": {
"terminalStatus": agentrun.get("terminalStatus"),