@devries-cameron20 / composio Mirror · read-only / commits / 15d476df6
Fork 0

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

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 23, 00:30 UTC

fix: send more event data for telemetry in python SDK

angrybayblade committed Jun 18, 2025 at 15:29 UTC 15d476df67fa0f2cb9481d37c9b01e5b66174b3b
4 files changed +88 -13
python/composio/__init__.py
+8 -1
@@ -1,3 +1,4 @@
1 +from .__version__ import __version__
2 from .core.models.tools import (
3 after_execute,
4 before_execute,
@@ -5,4 +6,10 @@ from .core.models.tools import (
6 )
7 from .sdk import Composio
8
8 -__all__ = ["Composio", "after_execute", "before_execute", "schema_modifier"]
9 +__all__ = (
10 + "Composio",
11 + "after_execute",
12 + "before_execute",
13 + "schema_modifier",
14 + "__version__",
15 +)
python/composio/__version__.py new
+1
@@ -0,0 +1 @@
1 +__version__ = "1.0.0-rc2"
python/composio/core/models/_telemetry.py
+54 -2
@@ -15,20 +15,72 @@ ERROR_ENDPOINT = f"{TELEMETRY_URL}/errors"
15
16 class ErrorData(te.TypedDict):
17 name: str
18 + "The name of the error"
19 +
20 code: te.NotRequired[str]
21 + "The code of the error"
22 +
23 errorId: te.NotRequired[str]
24 + "The error ID of the error"
25 +
26 message: te.NotRequired[str]
27 + "The message of the error"
28 +
29 stack: te.NotRequired[str]
30 + "The stack trace of the error"
31 +
32 +
33 +class SourceData(te.TypedDict):
34 + host: te.NotRequired[str]
35 + "The name of the source/host"
36 +
37 + service: te.NotRequired[te.Literal["sdk", "apollo", "hermes", "thermos"]]
38 + "The service of the source"
39 +
40 + language: te.NotRequired[te.Literal["python", "typescript", "go", "rust"]]
41 + "The language of the function that was invoked"
42 +
43 + version: te.NotRequired[str]
44 + "The version of the source"
45 +
46 + platform: te.NotRequired[str]
47 + "The platform of the source"
48 +
49 + environment: te.NotRequired[
50 + te.Literal["development", "production", "ci", "staging", "test"]
51 + ]
52 + "The environment of the source, eg: development, production, ci etc"
53 +
54 +
55 +class Metadata(te.TypedDict):
56 + projectId: te.NotRequired[str]
57 + "The project ID of the source"
58 +
59 + provider: te.NotRequired[str]
60 + "The provider used in the source"
61
62
63 class TelemetryData(te.TypedDict):
64 functionName: str
65 + "The name of the function that was invoked"
66 +
67 durationMs: te.NotRequired[float]
68 + "The duration of the function invocation in milliseconds"
69 +
70 timestamp: te.NotRequired[float]
71 + "The timestamp of the function invocation in epoch seconds"
72 +
73 props: te.NotRequired[t.Dict]
29 - source: te.NotRequired[str]
30 - metadata: te.NotRequired[t.Dict]
74 + "The properties of the function invocation"
75 +
76 + source: te.NotRequired[SourceData]
77 + """Source of the metric"""
78 +
79 + metadata: te.NotRequired[Metadata]
80 + """Runtime metadata"""
81 +
82 error: te.NotRequired[ErrorData]
83 + """Error data."""
84
85
86 EventType: t.TypeAlias = t.Literal["metric", "error"]
python/composio/core/models/base.py
+25 -10
@@ -4,10 +4,12 @@ Base resource class for representing resources in the composio client.
4
5 import contextvars
6 import functools
7 +import os
8 import time
9 import traceback
10 import typing as t
11
12 +from composio.__version__ import __version__
13 from composio.client import HttpClient
14 from composio.utils.logging import WithLogger
15
@@ -16,6 +18,7 @@ from ._telemetry import Event, create_event, push_event
18 PayloadT = t.TypeVar("PayloadT", bound=dict)
19
20 allow_tracking = contextvars.ContextVar[bool]("allow_tracking", default=True)
21 +_environment = os.getenv("ENVIRONMENT", "development")
22
23
24 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
31
32 event: t.Optional[Event] = None
33 start_time = time.time()
34 + event = create_event(
35 + type="metric",
36 + functionName=name,
37 + timestamp=time.time(),
38 + props=attributes,
39 + source={
40 + "environment": _environment, # type: ignore
41 + "language": "python",
42 + "service": "sdk",
43 + "version": __version__,
44 + },
45 + metadata={
46 + "provider": self._client.provider,
47 + },
48 + )
49 try:
32 - event = create_event(type="metric", functionName=name)
50 return method(self, *args, **kwargs)
51 except Exception as e:
35 - event = create_event(
36 - type="error",
37 - functionName=name,
38 - error={
39 - "name": e.__class__.__name__,
40 - "message": str(e),
41 - "stack": traceback.format_exc(),
42 - },
43 - )
52 + _, payload = event
53 + payload["error"] = {
54 + "name": e.__class__.__name__,
55 + "message": str(e),
56 + "stack": traceback.format_exc(),
57 + }
58 + event = ("error", payload)
59 raise e
60 finally:
61 if event is not None: