Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix: send more event data for telemetry in python SDK

angrybayblade15d476df67fa
diff --git a/python/composio/__init__.py b/python/composio/__init__.py
index 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__.py
new file mode 100644
index 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.py
index 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.py
index 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 contextvars
import functools
+import os
import time
import traceback
import typing as t
+from composio.__version__ import __version__
from composio.client import HttpClient
from composio.utils.logging import WithLogger
@@ -16,6 +18,7 @@ from ._telemetry import Event, create_event, push_event
PayloadT = 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.Callab
event: t.Optional[Event] = None
start_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 e
finally:
if event is not None: