Skip to content

Commit d99dd00

Browse files
committed
feat(claw-eval): add gen_ai.provider.name to invoke_agent_internal span
Add _infer_provider_name() helper to resolve provider name from the provider instance. This fixes a P0 compliance gap where the Required attribute gen_ai.provider.name was missing on invoke_agent_internal spans in the CLAW-eval instrumentation. Change-Id: Iad6b28ea1c9f09b4fae4aef03c625b35fcdff3d0 Co-developed-by: Qoder <noreply@qoder.com>
1 parent 4064298 commit d99dd00

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

  • instrumentation-loongsuite/loongsuite-instrumentation-claw-eval/src/opentelemetry/instrumentation/claw_eval/internal

instrumentation-loongsuite/loongsuite-instrumentation-claw-eval/src/opentelemetry/instrumentation/claw_eval/internal/wrappers.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,34 @@
6262
# string instead of reading it from ``gen_ai_attributes``.
6363
GEN_AI_TOOL_DEFINITIONS = "gen_ai.tool.definitions"
6464

65+
def _infer_provider_name(provider: Any) -> str:
66+
"""Infer gen_ai.provider.name from the provider instance."""
67+
if provider is None:
68+
return "claw-eval"
69+
# Try provider_name attribute
70+
pn = getattr(provider, "provider_name", None)
71+
if pn:
72+
return str(pn)
73+
# Infer from class name
74+
cls_name = type(provider).__name__.lower()
75+
if "openai" in cls_name:
76+
return "openai"
77+
if "anthropic" in cls_name:
78+
return "anthropic"
79+
if "dashscope" in cls_name:
80+
return "dashscope"
81+
# Infer from model_id
82+
model_id = str(getattr(provider, "model_id", "") or "")
83+
if model_id.startswith(("gpt-", "o1-", "o3-", "chatgpt-")):
84+
return "openai"
85+
if model_id.startswith(("claude-",)):
86+
return "anthropic"
87+
if model_id.startswith(("qwen",)):
88+
return "dashscope"
89+
return "openai"
90+
91+
92+
6593
# ---------------------------------------------------------------------------
6694
# ContextVars for STEP lifecycle & compact-depth tracking
6795
# ---------------------------------------------------------------------------
@@ -514,6 +542,13 @@ def __call__(self, wrapped, instance, args, kwargs):
514542
span.set_attribute(GenAI.GEN_AI_AGENT_NAME, "claw-eval")
515543
span.set_attribute("claw_eval.task_id", str(task_id))
516544

545+
# Set gen_ai.provider.name (Required attribute)
546+
_provider_name = _infer_provider_name(provider)
547+
if _provider_name:
548+
span.set_attribute(
549+
GenAI.GEN_AI_PROVIDER_NAME, _provider_name
550+
)
551+
517552
model_id = ""
518553
if provider is not None:
519554
model_id = str(getattr(provider, "model_id", "") or "")

0 commit comments

Comments
 (0)