Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG-loongsuite.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased

### Changed

- Adopt upstream semantic conventions for LoongSuite instrumentation packages.
Comment on lines 12 to +16

## Version 0.5.0 (2026-05-11)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def handle_response(
| None,
) -> None:
attributes = (
get_server_attributes(instance.api_endpoint) # type: ignore[reportUnknownMemberType]
get_server_attributes(instance.api_endpoint)
| request_attributes
| get_genai_response_attributes(response)
)
Expand Down Expand Up @@ -257,7 +257,7 @@ def _with_default_instrumentation(
kwargs: Any,
):
params = _extract_params(*args, **kwargs)
api_endpoint: str = instance.api_endpoint # type: ignore[reportUnknownMemberType]
api_endpoint: str = instance.api_endpoint
span_attributes = {
**get_genai_request_attributes(False, params),
**get_server_attributes(api_endpoint),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,11 @@ async def wrap_tool_call(wrapped, instance, args, kwargs, handler):
matched_skill = _match_skill_for_tool(instance, tool_args)

# Create invocation object with all tool data
# NOTE: tool_type is set to "function" as agentscope currently only
# supports function-type tools. Update when other types are supported.
invocation = ExecuteToolInvocation(
tool_name=tool_name,
tool_type="function",
Comment thread
123liuziming marked this conversation as resolved.
tool_call_id=tool_id,
tool_description=tool_description,
tool_call_arguments=tool_args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ async def fake_tool_generator():

invocation = ExecuteToolInvocation(
tool_name="read_file",
tool_type="function",
skill_name="news",
skill_id="workspace:default:news",
skill_description="Latest news",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ def _instrument(self, **kwargs: Any) -> None:
wrap_function_wrapper(
module="claude_agent_sdk",
name="ClaudeSDKClient.__init__",
wrapper=lambda wrapped,
instance,
args,
kwargs: wrap_claude_client_init(
wrapped,
instance,
args,
kwargs,
handler=ClaudeAgentSDKInstrumentor._handler,
wrapper=lambda wrapped, instance, args, kwargs: (
wrap_claude_client_init(
wrapped,
instance,
args,
kwargs,
handler=ClaudeAgentSDKInstrumentor._handler,
)
),
)
except Exception as e:
Expand All @@ -122,15 +121,14 @@ def _instrument(self, **kwargs: Any) -> None:
wrap_function_wrapper(
module="claude_agent_sdk",
name="ClaudeSDKClient.query",
wrapper=lambda wrapped,
instance,
args,
kwargs: wrap_claude_client_query(
wrapped,
instance,
args,
kwargs,
handler=ClaudeAgentSDKInstrumentor._handler,
wrapper=lambda wrapped, instance, args, kwargs: (
wrap_claude_client_query(
wrapped,
instance,
args,
kwargs,
handler=ClaudeAgentSDKInstrumentor._handler,
)
),
)
except Exception as e:
Expand All @@ -140,15 +138,14 @@ def _instrument(self, **kwargs: Any) -> None:
wrap_function_wrapper(
module="claude_agent_sdk",
name="ClaudeSDKClient.receive_response",
wrapper=lambda wrapped,
instance,
args,
kwargs: wrap_claude_client_receive_response(
wrapped,
instance,
args,
kwargs,
handler=ClaudeAgentSDKInstrumentor._handler,
wrapper=lambda wrapped, instance, args, kwargs: (
wrap_claude_client_receive_response(
wrapped,
instance,
args,
kwargs,
handler=ClaudeAgentSDKInstrumentor._handler,
)
),
)
except Exception as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def _create_tool_spans_from_message(
try:
tool_invocation = ExecuteToolInvocation(
tool_name=tool_name,
tool_type="function",
tool_call_id=tool_use_id,
tool_call_arguments=tool_input,
tool_description=tool_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,38 @@
# string instead of reading it from ``gen_ai_attributes``.
GEN_AI_TOOL_DEFINITIONS = "gen_ai.tool.definitions"


def _infer_provider_name(provider: Any) -> str:
"""Infer gen_ai.provider.name from the provider instance."""
Comment thread
123liuziming marked this conversation as resolved.
if provider is None:
return "claw-eval"
# Try provider_name attribute
pn = getattr(provider, "provider_name", None)
if pn:
return str(pn)
# Infer from class name
cls_name = type(provider).__name__.lower()
if "openai" in cls_name:
return "openai"
if "anthropic" in cls_name:
return "anthropic"
if "dashscope" in cls_name:
return "dashscope"
if "gemini" in cls_name or "google" in cls_name:
return "google"
# Infer from model_id
model_id = str(getattr(provider, "model_id", "") or "")
if model_id.startswith(("gpt-", "o1-", "o3-", "chatgpt-")):
return "openai"
Comment thread
123liuziming marked this conversation as resolved.
if model_id.startswith(("claude-",)):
return "anthropic"
if model_id.startswith(("qwen",)):
return "dashscope"
Comment thread
123liuziming marked this conversation as resolved.
if model_id.startswith(("gemini",)):
return "google"
return "unknown"


# ---------------------------------------------------------------------------
# ContextVars for STEP lifecycle & compact-depth tracking
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -514,6 +546,10 @@ def __call__(self, wrapped, instance, args, kwargs):
span.set_attribute(GenAI.GEN_AI_AGENT_NAME, "claw-eval")
span.set_attribute("claw_eval.task_id", str(task_id))

# Set gen_ai.provider.name (Required attribute)
_provider_name = _infer_provider_name(provider)
span.set_attribute(GenAI.GEN_AI_PROVIDER_NAME, _provider_name)

model_id = ""
if provider is not None:
model_id = str(getattr(provider, "model_id", "") or "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def wrap_text_embedding_call(wrapped, instance, args, kwargs, handler=None):
# Create embedding invocation object
invocation = EmbeddingInvocation(request_model=model)
invocation.provider = "dashscope"
invocation.server_address = "dashscope.aliyuncs.com"
invocation.server_port = 443

# Extract parameters from kwargs or kwargs["parameters"] dict
parameters = kwargs.get("parameters", {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,48 @@ def _extract_usage(response: Any) -> tuple[Optional[int], Optional[int]]:
return None, None


def _extract_cache_tokens(
response: Any,
) -> tuple[Optional[int], Optional[int]]:
"""Extract cache token usage from DashScope response.

Args:
response: DashScope response object

Returns:
Tuple of (cache_creation_input_tokens, cache_read_input_tokens)
"""
if not response:
return None, None

try:
usage = getattr(response, "usage", None)
if not usage:
return None, None

# DashScope may report cache tokens in various fields
cache_creation = getattr(
usage, "cache_creation_input_tokens", None
) or getattr(usage, "cache_creation_tokens", None)
cache_read = (
getattr(usage, "cache_read_input_tokens", None)
or getattr(usage, "cache_read_tokens", None)
or getattr(usage, "prompt_cache_hit_tokens", None)
)

# Also check prompt_tokens_details (OpenAI-compatible format)
prompt_details = getattr(usage, "prompt_tokens_details", None)
if prompt_details and cache_read is None:
cache_read = getattr(prompt_details, "cached_tokens", None)

return (
cache_creation if cache_creation and cache_creation > 0 else None,
cache_read if cache_read and cache_read > 0 else None,
)
except (KeyError, AttributeError):
return None, None


def _extract_task_id(task: Any) -> Optional[str]:
"""Extract task_id from task parameter (can be str or Response object).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ def _create_invocation_from_generation(

invocation = LLMInvocation(request_model=request_model)
invocation.provider = "dashscope"
Comment thread
123liuziming marked this conversation as resolved.
# DashScope SDK always targets dashscope.aliyuncs.com; if custom endpoint
# support is added in the future, extract from instance/env instead.
invocation.server_address = "dashscope.aliyuncs.com"
invocation.server_port = 443
Comment on lines 471 to +475
invocation.input_messages = _extract_input_messages(kwargs)

# Extract tool definitions and convert to FunctionToolDefinition objects
Expand Down Expand Up @@ -568,6 +572,15 @@ def _update_invocation_from_response(
invocation.input_tokens = input_tokens
invocation.output_tokens = output_tokens

# Extract cache token usage
from ..utils.common import _extract_cache_tokens # noqa: PLC0415

cache_creation, cache_read = _extract_cache_tokens(response)
if cache_creation is not None:
invocation.usage_cache_creation_input_tokens = cache_creation
if cache_read is not None:
invocation.usage_cache_read_input_tokens = cache_read

# Extract response model name (if available)
response_model = _safe_get(response, "model")
if response_model:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_text_embedding_basic(instrument, span_exporter):
"""Test basic text embedding call."""

response = TextEmbedding.call(
model="text-embedding-v1", input="Hello, world!"
model="text-embedding-v4", input="Hello, world!"
)

assert response is not None
Expand All @@ -165,7 +165,7 @@ def test_text_embedding_basic(instrument, span_exporter):
# Assert all span attributes
_assert_embedding_span_attributes(
span,
request_model="text-embedding-v1",
request_model="text-embedding-v4",
response=response,
input_tokens=input_tokens,
)
Expand All @@ -178,7 +178,7 @@ def test_text_embedding_batch(instrument, span_exporter):
"""Test text embedding with batch input."""

response = TextEmbedding.call(
model="text-embedding-v1", input=["Hello", "World"]
model="text-embedding-v4", input=["Hello", "World"]
)

assert response is not None
Expand All @@ -202,7 +202,7 @@ def test_text_embedding_batch(instrument, span_exporter):
# Assert all span attributes
_assert_embedding_span_attributes(
span,
request_model="text-embedding-v1",
request_model="text-embedding-v4",
response=response,
input_tokens=input_tokens,
)
Expand All @@ -215,7 +215,7 @@ def test_text_embedding_with_text_type(instrument, span_exporter):
"""Test text embedding with text_type parameter."""

response = TextEmbedding.call(
model="text-embedding-v1",
model="text-embedding-v4",
input="What is machine learning?",
text_type="query",
)
Expand All @@ -241,7 +241,7 @@ def test_text_embedding_with_text_type(instrument, span_exporter):
# Assert all span attributes
_assert_embedding_span_attributes(
span,
request_model="text-embedding-v1",
request_model="text-embedding-v4",
response=response,
input_tokens=input_tokens,
)
Expand All @@ -254,7 +254,7 @@ def test_text_embedding_with_dimension(instrument, span_exporter):
"""Test text embedding with dimension parameter."""

response = TextEmbedding.call(
model="text-embedding-v1",
model="text-embedding-v4",
input="What is machine learning?",
dimension=512,
)
Expand All @@ -280,7 +280,7 @@ def test_text_embedding_with_dimension(instrument, span_exporter):
# Assert all span attributes including dimension_count
_assert_embedding_span_attributes(
span,
request_model="text-embedding-v1",
request_model="text-embedding-v4",
response=response,
input_tokens=input_tokens,
dimension_count=512, # Should be captured from request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ async def before_run_callback(
invocation = InvokeAgentInvocation(
provider="google_adk",
agent_name=invocation_context.app_name,
agent_id=invocation_context.app_name,
)

# Set conversation_id if available
Expand Down Expand Up @@ -275,6 +276,7 @@ async def before_agent_callback(
invocation = InvokeAgentInvocation(
provider="google_adk",
agent_name=agent.name,
agent_id=agent.name,
)

# Set agent attributes
Expand Down Expand Up @@ -508,6 +510,7 @@ async def before_tool_callback(
# Create invocation object
invocation = ExecuteToolInvocation(
tool_name=tool.name,
tool_type="function",
provider="google_adk",
)

Expand Down
Loading
Loading