Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/langtrace_python_sdk/instrumentation/crewai/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def traced_method(wrapped, instance, args, kwargs):
)
if result:
span.set_status(Status(StatusCode.OK))
span.end()
return result

except Exception as err:
Expand Down Expand Up @@ -102,7 +101,6 @@ def traced_method(wrapped, instance, args, kwargs):
span.set_attribute(
f"crewai.crew.{attr}", str(getattr(result, attr))
)
span.end()
return result

except Exception as err:
Expand Down Expand Up @@ -139,21 +137,27 @@ def run(self):
for key, value in self.crew.items():
key = f"crewai.crew.{key}"
if value is not None:
set_span_attribute(self.span, key, value)
set_span_attribute(
self.span, key, str(value) if isinstance(value, list) else value
)

elif instance_name == "Agent":
agent = self.set_agent_attributes()
for key, value in agent.items():
key = f"crewai.agent.{key}"
if value is not None:
set_span_attribute(self.span, key, value)
set_span_attribute(
self.span, key, str(value) if isinstance(value, list) else value
)

elif instance_name == "Task":
task = self.set_task_attributes()
for key, value in task.items():
key = f"crewai.task.{key}"
if value is not None:
set_span_attribute(self.span, key, value)
set_span_attribute(
self.span, key, str(value) if isinstance(value, list) else value
)

def set_crew_attributes(self):
for key, value in self.instance.__dict__.items():
Expand Down
31 changes: 18 additions & 13 deletions src/langtrace_python_sdk/langtrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os
import sys
from typing import Optional

import importlib.util
from colorama import Fore
from opentelemetry import trace
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
Expand Down Expand Up @@ -120,25 +120,25 @@ def init(
all_instrumentations = {
"openai": OpenAIInstrumentation(),
"groq": GroqInstrumentation(),
"pinecone": PineconeInstrumentation(),
"llamaindex": LlamaindexInstrumentation(),
"chroma": ChromaInstrumentation(),
"pinecone-client": PineconeInstrumentation(),
"llama-index": LlamaindexInstrumentation(),
"chromadb": ChromaInstrumentation(),
"embedchain": EmbedchainInstrumentation(),
"qdrant": QdrantInstrumentation(),
"qdrant-client": QdrantInstrumentation(),
"langchain": LangchainInstrumentation(),
"langchain_core": LangchainCoreInstrumentation(),
"langchain_community": LangchainCommunityInstrumentation(),
"langchain-core": LangchainCoreInstrumentation(),
"langchain-community": LangchainCommunityInstrumentation(),
"langgraph": LanggraphInstrumentation(),
"anthropic": AnthropicInstrumentation(),
"cohere": CohereInstrumentation(),
"weaviate": WeaviateInstrumentation(),
"weaviate-client": WeaviateInstrumentation(),
"sqlalchemy": SQLAlchemyInstrumentor(),
"ollama": OllamaInstrumentor(),
"dspy": DspyInstrumentation(),
"dspy-ai": DspyInstrumentation(),
"crewai": CrewAIInstrumentation(),
"vertexai": VertexAIInstrumentation(),
"gemini": GeminiInstrumentation(),
"mistral": MistralInstrumentation(),
"google-cloud-aiplatform": VertexAIInstrumentation(),
"google-generativeai": GeminiInstrumentation(),
"mistralai": MistralInstrumentation(),
}

init_instrumentations(disable_instrumentations, all_instrumentations)
Expand Down Expand Up @@ -171,8 +171,9 @@ def init_instrumentations(
):
if disable_instrumentations is None:
for idx, (name, v) in enumerate(all_instrumentations.items()):
if is_package_installed(name):
v.instrument()

v.instrument()
else:

validate_instrumentations(disable_instrumentations)
Expand Down Expand Up @@ -229,3 +230,7 @@ def validate_instrumentations(disable_instrumentations):
raise ValueError(
"Cannot specify both only and all_except in disable_instrumentations"
)


def is_package_installed(package_name):
return importlib.util.find_spec(package_name) is not None