Spaces:
Sleeping
Sleeping
Delete crewai/telemtry/telemetry.py
Browse files- crewai/telemtry/telemetry.py +0 -114
crewai/telemtry/telemetry.py
DELETED
|
@@ -1,114 +0,0 @@
|
|
| 1 |
-
import json
|
| 2 |
-
import os
|
| 3 |
-
import platform
|
| 4 |
-
import socket
|
| 5 |
-
|
| 6 |
-
import pkg_resources
|
| 7 |
-
from opentelemetry import trace
|
| 8 |
-
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
| 9 |
-
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
|
| 10 |
-
from opentelemetry.sdk.trace import TracerProvider
|
| 11 |
-
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
| 12 |
-
from opentelemetry.trace import Status, StatusCode
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
class Telemetry:
|
| 16 |
-
"""A class to handle anonymous telemetry for the crewai package.
|
| 17 |
-
|
| 18 |
-
The data being collected is for development purpose, all data is anonymous.
|
| 19 |
-
|
| 20 |
-
There is NO data being collected on the prompts, tasks descriptions
|
| 21 |
-
agents backstories or goals nor responses or any data that is being
|
| 22 |
-
processed by the agents, nor any secrets and env vars.
|
| 23 |
-
|
| 24 |
-
Data collected includes:
|
| 25 |
-
- Version of crewAI
|
| 26 |
-
- Version of Python
|
| 27 |
-
- General OS (e.g. number of CPUs, macOS/Windows/Linux)
|
| 28 |
-
- Number of agents and tasks in a crew
|
| 29 |
-
- Crew Process being used
|
| 30 |
-
- If Agents are using memory or allowing delegation
|
| 31 |
-
- If Tasks are being executed in parallel or sequentially
|
| 32 |
-
- Language model being used
|
| 33 |
-
- Roles of agents in a crew
|
| 34 |
-
- Tools names available
|
| 35 |
-
"""
|
| 36 |
-
|
| 37 |
-
def __init__(self):
|
| 38 |
-
telemetry_endpoint = "http://telemetry.crewai.com:4318"
|
| 39 |
-
self.resource = Resource(attributes={SERVICE_NAME: "crewAI-telemetry"})
|
| 40 |
-
provider = TracerProvider(resource=self.resource)
|
| 41 |
-
processor = BatchSpanProcessor(
|
| 42 |
-
OTLPSpanExporter(endpoint=f"{telemetry_endpoint}/v1/traces")
|
| 43 |
-
)
|
| 44 |
-
provider.add_span_processor(processor)
|
| 45 |
-
trace.set_tracer_provider(provider)
|
| 46 |
-
|
| 47 |
-
def crew_creation(self, crew):
|
| 48 |
-
"""Records the creation of a crew."""
|
| 49 |
-
try:
|
| 50 |
-
tracer = trace.get_tracer("crewai.telemetry")
|
| 51 |
-
span = tracer.start_span("Crew Created")
|
| 52 |
-
self.add_attribute(
|
| 53 |
-
span, "crewai_version", pkg_resources.get_distribution("crewai").version
|
| 54 |
-
)
|
| 55 |
-
self.add_attribute(span, "python_version", platform.python_version())
|
| 56 |
-
self.add_attribute(span, "hostname", socket.gethostname())
|
| 57 |
-
self.add_attribute(span, "crewid", str(crew.id))
|
| 58 |
-
self.add_attribute(span, "crew_process", crew.process)
|
| 59 |
-
self.add_attribute(span, "crew_language", crew.language)
|
| 60 |
-
self.add_attribute(span, "crew_number_of_tasks", len(crew.tasks))
|
| 61 |
-
self.add_attribute(span, "crew_number_of_agents", len(crew.agents))
|
| 62 |
-
self.add_attribute(
|
| 63 |
-
span,
|
| 64 |
-
"crew_agents",
|
| 65 |
-
json.dumps(
|
| 66 |
-
[
|
| 67 |
-
{
|
| 68 |
-
"id": str(agent.id),
|
| 69 |
-
"role": agent.role,
|
| 70 |
-
"memory_enabled?": agent.memory,
|
| 71 |
-
"llm": json.dumps(self._safe_llm_attributes(agent.llm)),
|
| 72 |
-
"delegation_enabled?": agent.allow_delegation,
|
| 73 |
-
"tools_names": [tool.name for tool in agent.tools],
|
| 74 |
-
}
|
| 75 |
-
for agent in crew.agents
|
| 76 |
-
]
|
| 77 |
-
),
|
| 78 |
-
)
|
| 79 |
-
self.add_attribute(
|
| 80 |
-
span,
|
| 81 |
-
"crew_tasks",
|
| 82 |
-
json.dumps(
|
| 83 |
-
[
|
| 84 |
-
{
|
| 85 |
-
"id": str(task.id),
|
| 86 |
-
"async_execution?": task.async_execution,
|
| 87 |
-
"tools_names": [tool.name for tool in task.tools],
|
| 88 |
-
}
|
| 89 |
-
for task in crew.tasks
|
| 90 |
-
]
|
| 91 |
-
),
|
| 92 |
-
)
|
| 93 |
-
self.add_attribute(span, "platform", platform.platform())
|
| 94 |
-
self.add_attribute(span, "platform_release", platform.release())
|
| 95 |
-
self.add_attribute(span, "platform_system", platform.system())
|
| 96 |
-
self.add_attribute(span, "platform_version", platform.version())
|
| 97 |
-
self.add_attribute(span, "cpus", os.cpu_count())
|
| 98 |
-
span.set_status(Status(StatusCode.OK))
|
| 99 |
-
span.end()
|
| 100 |
-
except Exception:
|
| 101 |
-
pass
|
| 102 |
-
|
| 103 |
-
def add_attribute(self, span, key, value):
|
| 104 |
-
"""Add an attribute to a span."""
|
| 105 |
-
try:
|
| 106 |
-
return span.set_attribute(key, value)
|
| 107 |
-
except Exception:
|
| 108 |
-
pass
|
| 109 |
-
|
| 110 |
-
def _safe_llm_attributes(self, llm):
|
| 111 |
-
attributes = ["name", "model_name", "base_url", "model", "top_k", "temperature"]
|
| 112 |
-
safe_attributes = {k: v for k, v in vars(llm).items() if k in attributes}
|
| 113 |
-
safe_attributes["class"] = llm.__class__.__name__
|
| 114 |
-
return safe_attributes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|