mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 16:18:30 +00:00
avoind unnecesarry telemetry errors
This commit is contained in:
@@ -38,137 +38,89 @@ class Telemetry:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
telemetry_endpoint = "http://telemetry.crewai.com:4318"
|
self.ready = False
|
||||||
self.resource = Resource(attributes={SERVICE_NAME: "crewAI-telemetry"})
|
try:
|
||||||
provider = TracerProvider(resource=self.resource)
|
telemetry_endpoint = "http://telemetry.crewai.com:4318"
|
||||||
processor = BatchSpanProcessor(
|
self.resource = Resource(attributes={SERVICE_NAME: "crewAI-telemetry"})
|
||||||
OTLPSpanExporter(endpoint=f"{telemetry_endpoint}/v1/traces")
|
provider = TracerProvider(resource=self.resource)
|
||||||
)
|
processor = BatchSpanProcessor(
|
||||||
provider.add_span_processor(processor)
|
OTLPSpanExporter(endpoint=f"{telemetry_endpoint}/v1/traces")
|
||||||
trace.set_tracer_provider(provider)
|
)
|
||||||
|
provider.add_span_processor(processor)
|
||||||
|
trace.set_tracer_provider(provider)
|
||||||
|
self.ready = True
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
def crew_creation(self, crew):
|
def crew_creation(self, crew):
|
||||||
"""Records the creation of a crew."""
|
"""Records the creation of a crew."""
|
||||||
try:
|
if self.ready:
|
||||||
tracer = trace.get_tracer("crewai.telemetry")
|
try:
|
||||||
span = tracer.start_span("Crew Created")
|
tracer = trace.get_tracer("crewai.telemetry")
|
||||||
self._add_attribute(
|
span = tracer.start_span("Crew Created")
|
||||||
span, "crewai_version", pkg_resources.get_distribution("crewai").version
|
self._add_attribute(
|
||||||
)
|
span,
|
||||||
self._add_attribute(span, "python_version", platform.python_version())
|
"crewai_version",
|
||||||
self._add_attribute(span, "hostname", socket.gethostname())
|
pkg_resources.get_distribution("crewai").version,
|
||||||
self._add_attribute(span, "crew_id", str(crew.id))
|
)
|
||||||
self._add_attribute(span, "crew_process", crew.process)
|
self._add_attribute(span, "python_version", platform.python_version())
|
||||||
self._add_attribute(span, "crew_language", crew.language)
|
self._add_attribute(span, "hostname", socket.gethostname())
|
||||||
self._add_attribute(span, "crew_number_of_tasks", len(crew.tasks))
|
self._add_attribute(span, "crew_id", str(crew.id))
|
||||||
self._add_attribute(span, "crew_number_of_agents", len(crew.agents))
|
self._add_attribute(span, "crew_process", crew.process)
|
||||||
self._add_attribute(
|
self._add_attribute(span, "crew_language", crew.language)
|
||||||
span,
|
self._add_attribute(span, "crew_number_of_tasks", len(crew.tasks))
|
||||||
"crew_agents",
|
self._add_attribute(span, "crew_number_of_agents", len(crew.agents))
|
||||||
json.dumps(
|
self._add_attribute(
|
||||||
[
|
span,
|
||||||
{
|
"crew_agents",
|
||||||
"id": str(agent.id),
|
json.dumps(
|
||||||
"role": agent.role,
|
[
|
||||||
"memory_enabled?": agent.memory,
|
{
|
||||||
"verbose?": agent.verbose,
|
"id": str(agent.id),
|
||||||
"max_iter": agent.max_iter,
|
"role": agent.role,
|
||||||
"max_rpm": agent.max_rpm,
|
"memory_enabled?": agent.memory,
|
||||||
"i18n": agent.i18n.language,
|
"verbose?": agent.verbose,
|
||||||
"llm": json.dumps(self._safe_llm_attributes(agent.llm)),
|
"max_iter": agent.max_iter,
|
||||||
"delegation_enabled?": agent.allow_delegation,
|
"max_rpm": agent.max_rpm,
|
||||||
"tools_names": [tool.name for tool in agent.tools],
|
"i18n": agent.i18n.language,
|
||||||
}
|
"llm": json.dumps(self._safe_llm_attributes(agent.llm)),
|
||||||
for agent in crew.agents
|
"delegation_enabled?": agent.allow_delegation,
|
||||||
]
|
"tools_names": [tool.name for tool in agent.tools],
|
||||||
),
|
}
|
||||||
)
|
for agent in crew.agents
|
||||||
self._add_attribute(
|
]
|
||||||
span,
|
),
|
||||||
"crew_tasks",
|
)
|
||||||
json.dumps(
|
self._add_attribute(
|
||||||
[
|
span,
|
||||||
{
|
"crew_tasks",
|
||||||
"id": str(task.id),
|
json.dumps(
|
||||||
"async_execution?": task.async_execution,
|
[
|
||||||
"agent_role": task.agent.role if task.agent else "None",
|
{
|
||||||
"tools_names": [tool.name for tool in task.tools],
|
"id": str(task.id),
|
||||||
}
|
"async_execution?": task.async_execution,
|
||||||
for task in crew.tasks
|
"agent_role": task.agent.role if task.agent else "None",
|
||||||
]
|
"tools_names": [tool.name for tool in task.tools],
|
||||||
),
|
}
|
||||||
)
|
for task in crew.tasks
|
||||||
self._add_attribute(span, "platform", platform.platform())
|
]
|
||||||
self._add_attribute(span, "platform_release", platform.release())
|
),
|
||||||
self._add_attribute(span, "platform_system", platform.system())
|
)
|
||||||
self._add_attribute(span, "platform_version", platform.version())
|
self._add_attribute(span, "platform", platform.platform())
|
||||||
self._add_attribute(span, "cpus", os.cpu_count())
|
self._add_attribute(span, "platform_release", platform.release())
|
||||||
span.set_status(Status(StatusCode.OK))
|
self._add_attribute(span, "platform_system", platform.system())
|
||||||
span.end()
|
self._add_attribute(span, "platform_version", platform.version())
|
||||||
except Exception:
|
self._add_attribute(span, "cpus", os.cpu_count())
|
||||||
pass
|
span.set_status(Status(StatusCode.OK))
|
||||||
|
span.end()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
def crew_execution_span(self, crew):
|
def crew_execution_span(self, crew):
|
||||||
"""Records the complete execution of a crew.
|
"""Records the complete execution of a crew.
|
||||||
This is only collected if the user has opted-in to share the crew.
|
This is only collected if the user has opted-in to share the crew.
|
||||||
"""
|
"""
|
||||||
try:
|
if (self.ready) and (crew.share_crew):
|
||||||
tracer = trace.get_tracer("crewai.telemetry")
|
|
||||||
span = tracer.start_span("Crew Execution")
|
|
||||||
self._add_attribute(span, "crew_id", str(crew.id))
|
|
||||||
self._add_attribute(
|
|
||||||
span,
|
|
||||||
"crew_agents",
|
|
||||||
json.dumps(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"id": str(agent.id),
|
|
||||||
"role": agent.role,
|
|
||||||
"goal": agent.goal,
|
|
||||||
"backstory": agent.backstory,
|
|
||||||
"memory_enabled?": agent.memory,
|
|
||||||
"verbose?": agent.verbose,
|
|
||||||
"max_iter": agent.max_iter,
|
|
||||||
"max_rpm": agent.max_rpm,
|
|
||||||
"i18n": agent.i18n.language,
|
|
||||||
"llm": json.dumps(self._safe_llm_attributes(agent.llm)),
|
|
||||||
"delegation_enabled?": agent.allow_delegation,
|
|
||||||
"tools_names": [tool.name for tool in agent.tools],
|
|
||||||
}
|
|
||||||
for agent in crew.agents
|
|
||||||
]
|
|
||||||
),
|
|
||||||
)
|
|
||||||
self._add_attribute(
|
|
||||||
span,
|
|
||||||
"crew_tasks",
|
|
||||||
json.dumps(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"id": str(task.id),
|
|
||||||
"description": task.description,
|
|
||||||
"async_execution?": task.async_execution,
|
|
||||||
"output": task.expected_output,
|
|
||||||
"agent_role": task.agent.role if task.agent else "None",
|
|
||||||
"context": [task.description for task in task.context]
|
|
||||||
if task.context
|
|
||||||
else "None",
|
|
||||||
"tools_names": [tool.name for tool in task.tools],
|
|
||||||
}
|
|
||||||
for task in crew.tasks
|
|
||||||
]
|
|
||||||
),
|
|
||||||
)
|
|
||||||
span.set_status(Status(StatusCode.OK))
|
|
||||||
span.end()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def crew_execution_span(self, crew):
|
|
||||||
"""Records the complete execution of a crew.
|
|
||||||
This is only collected if the user has opted-in to share the crew.
|
|
||||||
"""
|
|
||||||
if crew.share_crew:
|
|
||||||
try:
|
try:
|
||||||
tracer = trace.get_tracer("crewai.telemetry")
|
tracer = trace.get_tracer("crewai.telemetry")
|
||||||
span = tracer.start_span("Crew Execution")
|
span = tracer.start_span("Crew Execution")
|
||||||
@@ -221,7 +173,7 @@ class Telemetry:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def end_crew(self, crew, output):
|
def end_crew(self, crew, output):
|
||||||
if crew.share_crew:
|
if (self.ready) and (crew.share_crew):
|
||||||
try:
|
try:
|
||||||
self._add_attribute(crew._execution_span, "crew_output", output)
|
self._add_attribute(crew._execution_span, "crew_output", output)
|
||||||
self._add_attribute(
|
self._add_attribute(
|
||||||
|
|||||||
Reference in New Issue
Block a user