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
9 changes: 5 additions & 4 deletions instrumentation-loongsuite/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

| Instrumentation | Supported Packages | Metrics support | Semconv status |
| --------------- | ------------------ | --------------- | -------------- |
| [loongsuite-instrumentation-agentscope](./loongsuite-instrumentation-agentscope) | agentscope >= 0.1.5.dev0 | No | development
| [loongsuite-instrumentation-agno](./loongsuite-instrumentation-agno) | agno >= 1.5.0 | No | development
| [loongsuite-instrumentation-agentscope](./loongsuite-instrumentation-agentscope) | agentscope >= 1.0.0 | No | development
| [loongsuite-instrumentation-agno](./loongsuite-instrumentation-agno) | agno | No | development
| [loongsuite-instrumentation-dashscope](./loongsuite-instrumentation-dashscope) | dashscope >= 1.0.0 | No | development
| [loongsuite-instrumentation-dify](./loongsuite-instrumentation-dify) | dify | No | development
| [loongsuite-instrumentation-langchain](./loongsuite-instrumentation-langchain) | langchain_core >= 0.1.0 | Yes | development
| [loongsuite-instrumentation-mcp](./loongsuite-instrumentation-mcp) | mcp>=1.3.0 | Yes | development
| [loongsuite-instrumentation-langchain](./loongsuite-instrumentation-langchain) | langchain_core >= 0.1.0 | No | development
| [loongsuite-instrumentation-mcp](./loongsuite-instrumentation-mcp) | mcp >= 1.3.0, <= 1.13.1 | No | development
| [loongsuite-instrumentation-mem0](./loongsuite-instrumentation-mem0) | mem0ai >= 1.0.0 | No | development
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ classifiers = [
]
dependencies = [
"opentelemetry-api ~= 1.37",
"opentelemetry-instrumentation ~= 0.58b0",
"opentelemetry-semantic-conventions ~= 0.58b0",
"opentelemetry-instrumentation >= 0.58b0",
"opentelemetry-semantic-conventions >= 0.58b0",
"opentelemetry-util-genai",
"wrapt",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def _setup_tracing_patch(self, wrapped, instance, args, kwargs):
"""Replace setup_tracing with no-op to use OTEL instead."""
pass

def _check_tracing_enabled_patch(self, wrapped, instance, args, kwargs):
"""Return False to disable tracing in native AgentScope library."""
return False

def _instrument(self, **kwargs: Any) -> None:
"""Enable AgentScope instrumentation."""
tracer_provider = kwargs.get("tracer_provider")
Expand Down Expand Up @@ -199,6 +203,18 @@ def wrap_formatter_with_tracer(wrapped, instance, args, kwargs):
logger.debug("Patched setup_tracing")
except Exception as e:
logger.warning(f"Failed to patch setup_tracing: {e}")

# Patch _check_tracing_enabled to return False
# We always want to disable tracing in native AgentScope library
try:
wrap_function_wrapper(
module="agentscope.tracing._trace",
name="_check_tracing_enabled",
wrapper=self._check_tracing_enabled_patch,
)
logger.debug("Patched _check_tracing_enabled")
except Exception as e:
logger.warning(f"Failed to patch _check_tracing_enabled: {e}")

def _uninstrument(self, **kwargs: Any) -> None:
"""Disable AgentScope instrumentation."""
Expand Down Expand Up @@ -269,3 +285,11 @@ def _uninstrument(self, **kwargs: Any) -> None:
logger.debug("Uninstrumented setup_tracing")
except Exception as e:
logger.warning(f"Failed to uninstrument setup_tracing: {e}")

try:
import agentscope.tracing # noqa: PLC0415

unwrap(agentscope.tracing, "_check_tracing_enabled")
logger.debug("Uninstrumented _check_tracing_enabled")
except Exception as e:
logger.warning(f"Failed to uninstrument _check_tracing_enabled: {e}")
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,7 @@ def convert_agentscope_messages_to_genai_format(
if isinstance(msg, Msg):
msg_dict = _format_msg_to_parts(msg)
elif isinstance(msg, dict):
if provider_name:
try:
converted = get_message_converter(provider_name)([msg])
msg_dict = converted[0] if converted else msg
except Exception:
msg_dict = msg
else:
msg_dict = msg
msg_dict = msg
else:
continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ classifiers = [
]
dependencies = [
"opentelemetry-api ~= 1.37",
"opentelemetry-instrumentation ~= 0.58b0",
"opentelemetry-semantic-conventions ~= 0.58b0",
"opentelemetry-instrumentation >= 0.58b0",
"opentelemetry-semantic-conventions >= 0.58b0",
]

[project.optional-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ classifiers = [
]
dependencies = [
"opentelemetry-api ~= 1.37",
"opentelemetry-instrumentation ~= 0.58b0",
"opentelemetry-semantic-conventions ~= 0.58b0",
"opentelemetry-util-genai ~= 0.2b0",
"opentelemetry-instrumentation >= 0.58b0",
"opentelemetry-semantic-conventions >= 0.58b0",
"opentelemetry-util-genai > 0.2b0",
]

[project.optional-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ classifiers = [
]
dependencies = [
"opentelemetry-api ~= 1.37",
"opentelemetry-instrumentation ~= 0.58b0",
"opentelemetry-semantic-conventions ~= 0.58b0",
"opentelemetry-instrumentation >= 0.58b0",
"opentelemetry-semantic-conventions >= 0.58b0",
]

[project.optional-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ classifiers = [
]
dependencies = [
"opentelemetry-api ~= 1.37",
"opentelemetry-instrumentation ~= 0.58b0",
"opentelemetry-semantic-conventions ~= 0.58b0",
"opentelemetry-instrumentation >= 0.58b0",
"opentelemetry-semantic-conventions >= 0.58b0",
]

[project.optional-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dynamic = ["version"]
description = "OpenTelemetry MCP (Model Context Protocol) instrumentation"
readme = "README.md"
license = "Apache-2.0"
requires-python = ">=3.10, <=3.13"
requires-python = ">=3.10"
authors = [
{ name = "LoongSuite Python Agent Authors"},
]
Expand All @@ -31,7 +31,7 @@ dependencies = [

[project.optional-dependencies]
instruments = [
"mcp >= 1.3.0, <= 1.13.1",
"mcp >= 1.3.0, <= 1.25.0",
]
test = [
"opentelemetry-sdk",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
from opentelemetry.instrumentation.mcp.utils import (
_get_logger,
_get_streamable_http_client_name,
_is_version_supported,
_is_ws_installed,
)
Expand Down Expand Up @@ -53,6 +54,8 @@
for method_name, rpc_name in RPC_NAME_MAPPING.items()
]

_streamable_http_client_name = _get_streamable_http_client_name()


class MCPInstrumentor(BaseInstrumentor):
"""
Expand Down Expand Up @@ -99,7 +102,7 @@ def _instrument(self, **kwargs: Any) -> None:
)
wrap_function_wrapper(
module="mcp.client.streamable_http",
name="streamablehttp_client",
name=_streamable_http_client_name,
wrapper=streamable_http_client_wrapper(),
)
wrap_function_wrapper(
Expand Down Expand Up @@ -140,10 +143,10 @@ def _uninstrument(self, **kwargs: Any) -> None:
try:
import mcp.client.streamable_http # noqa: PLC0415

unwrap(mcp.client.streamable_http, "streamablehttp_client")
unwrap(mcp.client.streamable_http, _streamable_http_client_name)
except Exception:
logger.warning(
"Fail to uninstrument streamablehttp_client", exc_info=True
"Fail to uninstrument streamable_http_client", exc_info=True
)

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@
_has_mcp_types = False

MIN_SUPPORTED_VERSION = (1, 3, 0)
MAX_SUPPORTED_VERSION = (1, 13, 1)
MAX_SUPPORTED_VERSION = (1, 25, 0)
MCP_PACKAGE_NAME = "mcp"
DEFAULT_MAX_ATTRIBUTE_LENGTH = 1024 * 1024

# Version thresholds for API changes
# v1.24.0: streamable_http_client was added (streamablehttp_client deprecated)
STREAMABLE_HTTP_CLIENT_NEW_NAME_VERSION = (1, 24, 0)
# Streamable HTTP client function names
STREAMABLE_HTTP_CLIENT_NEW_NAME = "streamable_http_client"
STREAMABLE_HTTP_CLIENT_OLD_NAME = "streamablehttp_client"

_max_attributes_length = None


Expand Down Expand Up @@ -77,6 +84,18 @@ def _is_version_supported() -> bool:
)


def _get_streamable_http_client_name() -> str:
"""
Get the correct streamable HTTP client function name based on MCP version.
- v1.24.0+: uses `streamable_http_client` (new name)
- v1.3.0 - v1.23.x: uses `streamablehttp_client` (old name)
"""
current_version = _get_mcp_version()
if current_version >= STREAMABLE_HTTP_CLIENT_NEW_NAME_VERSION:
return STREAMABLE_HTTP_CLIENT_NEW_NAME
return STREAMABLE_HTTP_CLIENT_OLD_NAME


def _is_capture_content_enabled() -> bool:
capture_content = environ.get(
MCPEnvironmentVariables.CAPTURE_INPUT_ENABLED, "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ classifiers = [
dependencies = [
"wrapt >=1.17.3",
"opentelemetry-api ~=1.37",
"opentelemetry-instrumentation ~=0.58b0",
"opentelemetry-semantic-conventions ~=0.58b0",
"opentelemetry-util-genai ~= 0.2b0",
"opentelemetry-instrumentation >=0.58b0",
"opentelemetry-semantic-conventions >=0.58b0",
"opentelemetry-util-genai >= 0.2b0",
]

[project.optional-dependencies]
Expand Down
Loading
Loading