Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix: send more event data for telemetry in python SDK
angrybayblade15d476df67fa
diff --git a/python/composio/__init__.py b/python/composio/__init__.pyindex 51076bf7d..fa9adfb03 100644--- a/python/composio/__init__.py+++ b/python/composio/__init__.py@@ -1,3 +1,4 @@+from .__version__ import __version__from .core.models.tools import (after_execute,before_execute,@@ -5,4 +6,10 @@ from .core.models.tools import ()from .sdk import Composio-__all__ = ["Composio", "after_execute", "before_execute", "schema_modifier"]+__all__ = (+ "Composio",+ "after_execute",+ "before_execute",+ "schema_modifier",+ "__version__",+)diff --git a/python/composio/__version__.py b/python/composio/__version__.pynew file mode 100644index 000000000..76595651c--- /dev/null+++ b/python/composio/__version__.py@@ -0,0 +1 @@+__version__ = "1.0.0-rc2"diff --git a/python/composio/core/models/_telemetry.py b/python/composio/core/models/_telemetry.pyindex 790497926..dadd687b2 100644--- a/python/composio/core/models/_telemetry.py+++ b/python/composio/core/models/_telemetry.py@@ -15,20 +15,72 @@ ERROR_ENDPOINT = f"{TELEMETRY_URL}/errors"class ErrorData(te.TypedDict):name: str+ "The name of the error"+code: te.NotRequired[str]+ "The code of the error"+errorId: te.NotRequired[str]+ "The error ID of the error"+message: te.NotRequired[str]+ "The message of the error"+stack: te.NotRequired[str]+ "The stack trace of the error"+++class SourceData(te.TypedDict):+ host: te.NotRequired[str]+ "The name of the source/host"++ service: te.NotRequired[te.Literal["sdk", "apollo", "hermes", "thermos"]]+ "The service of the source"++ language: te.NotRequired[te.Literal["python", "typescript", "go", "rust"]]+ "The language of the function that was invoked"++ version: te.NotRequired[str]+ "The version of the source"++ platform: te.NotRequired[str]+ "The platform of the source"++ environment: te.NotRequired[+ te.Literal["development", "production", "ci", "staging", "test"]+ ]+ "The environment of the source, eg: development, production, ci etc"+++class Metadata(te.TypedDict):+ projectId: te.NotRequired[str]+ "The project ID of the source"++ provider: te.NotRequired[str]+ "The provider used in the source"class TelemetryData(te.TypedDict):functionName: str+ "The name of the function that was invoked"+durationMs: te.NotRequired[float]+ "The duration of the function invocation in milliseconds"+timestamp: te.NotRequired[float]+ "The timestamp of the function invocation in epoch seconds"+props: te.NotRequired[t.Dict]- source: te.NotRequired[str]- metadata: te.NotRequired[t.Dict]+ "The properties of the function invocation"++ source: te.NotRequired[SourceData]+ """Source of the metric"""++ metadata: te.NotRequired[Metadata]+ """Runtime metadata"""+error: te.NotRequired[ErrorData]+ """Error data."""EventType: t.TypeAlias = t.Literal["metric", "error"]diff --git a/python/composio/core/models/base.py b/python/composio/core/models/base.pyindex fea0bd793..4acae874c 100644--- a/python/composio/core/models/base.py+++ b/python/composio/core/models/base.py@@ -4,10 +4,12 @@ Base resource class for representing resources in the composio client.import contextvarsimport functools+import osimport timeimport tracebackimport typing as t+from composio.__version__ import __version__from composio.client import HttpClientfrom composio.utils.logging import WithLogger@@ -16,6 +18,7 @@ from ._telemetry import Event, create_event, push_eventPayloadT = t.TypeVar("PayloadT", bound=dict)allow_tracking = contextvars.ContextVar[bool]("allow_tracking", default=True)+_environment = os.getenv("ENVIRONMENT", "development")def trace_method(method: t.Callable, name: str, **attributes: t.Any) -> t.Callable:@@ -28,19 +31,31 @@ def trace_method(method: t.Callable, name: str, **attributes: t.Any) -> t.Callabevent: t.Optional[Event] = Nonestart_time = time.time()+ event = create_event(+ type="metric",+ functionName=name,+ timestamp=time.time(),+ props=attributes,+ source={+ "environment": _environment, # type: ignore+ "language": "python",+ "service": "sdk",+ "version": __version__,+ },+ metadata={+ "provider": self._client.provider,+ },+ )try:- event = create_event(type="metric", functionName=name)return method(self, *args, **kwargs)except Exception as e:- event = create_event(- type="error",- functionName=name,- error={- "name": e.__class__.__name__,- "message": str(e),- "stack": traceback.format_exc(),- },- )+ _, payload = event+ payload["error"] = {+ "name": e.__class__.__name__,+ "message": str(e),+ "stack": traceback.format_exc(),+ }+ event = ("error", payload)raise efinally:if event is not None: