From 0ac2c2edec11b239af9ef372424fabbca626484d Mon Sep 17 00:00:00 2001 From: darshit-s3 <119623510+darshit-s3@users.noreply.github.com> Date: Thu, 5 Sep 2024 19:22:40 +0530 Subject: [PATCH 1/4] fix: weaviate fusion type enum handling (#328) (#329) --- src/langtrace_python_sdk/instrumentation/weaviate/patch.py | 7 +++++-- src/langtrace_python_sdk/version.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/langtrace_python_sdk/instrumentation/weaviate/patch.py b/src/langtrace_python_sdk/instrumentation/weaviate/patch.py index c2ea4b39..523b047a 100644 --- a/src/langtrace_python_sdk/instrumentation/weaviate/patch.py +++ b/src/langtrace_python_sdk/instrumentation/weaviate/patch.py @@ -47,9 +47,12 @@ def extract_inputs(args, kwargs): extracted_params = {} - kwargs_without_properties = {k: v for k, v in kwargs.items() if k != "properties"} + kwargs_without_properties = { + k: v for k, v in kwargs.items() if k not in ["properties", "fusion_type"] + } extracted_params.update(extract_input_params(args, kwargs_without_properties)) - + if kwargs.get("fusion_type", None): + extracted_params["fusion_type"] = kwargs["fusion_type"].value if kwargs.get("properties", None): extracted_params["properties"] = [] for each_prop in kwargs.get("properties"): diff --git a/src/langtrace_python_sdk/version.py b/src/langtrace_python_sdk/version.py index 4618fe65..f4bd92b2 100644 --- a/src/langtrace_python_sdk/version.py +++ b/src/langtrace_python_sdk/version.py @@ -1 +1 @@ -__version__ = "2.3.4" +__version__ = "2.3.5" From 4bbae44b1597dbbb24be48a0c12ac886a2afdfc9 Mon Sep 17 00:00:00 2001 From: Karthik Kalyanaraman <105607645+karthikscale3@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:00:27 -0700 Subject: [PATCH 2/4] Release (#336) * remove logs * remove requirements * Bump version * Squash * Bugfix (#335) --- .../instrumentation/langchain_core/patch.py | 8 +++----- src/langtrace_python_sdk/version.py | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/langtrace_python_sdk/instrumentation/langchain_core/patch.py b/src/langtrace_python_sdk/instrumentation/langchain_core/patch.py index 71441666..765c738e 100644 --- a/src/langtrace_python_sdk/instrumentation/langchain_core/patch.py +++ b/src/langtrace_python_sdk/instrumentation/langchain_core/patch.py @@ -87,13 +87,11 @@ def traced_method(wrapped, instance, args, kwargs): completion_tokens = result.usage.completion_tokens span.set_attribute(SpanAttributes.LLM_USAGE_PROMPT_TOKENS, prompt_tokens) span.set_attribute(SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, completion_tokens) - - elif result.generations[0][0].text: + elif hasattr(result, 'generations') and len(result.generations) > 0 and len(result.generations[0]) > 0 and hasattr(result.generations[0][0], 'text') and isinstance(result.generations[0][0].text, str): span.set_attribute(SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, instance.get_num_tokens(result.generations[0][0].text)) - elif isinstance(args[0][0], str): + elif len(args) > 0 and len(args[0]) > 0 and not hasattr(args[0][0], 'text') and hasattr(instance, 'get_num_tokens'): span.set_attribute(SpanAttributes.LLM_USAGE_PROMPT_TOKENS, instance.get_num_tokens(args[0][0])) - - else: + elif len(args) > 0 and len(args[0]) > 0 and hasattr(args[0][0], 'text') and isinstance(args[0][0].text, str) and hasattr(instance, 'get_num_tokens'): span.set_attribute(SpanAttributes.LLM_USAGE_PROMPT_TOKENS, instance.get_num_tokens(args[0][0].text)) span.set_status(StatusCode.OK) diff --git a/src/langtrace_python_sdk/version.py b/src/langtrace_python_sdk/version.py index a0b06b86..e121c1f3 100644 --- a/src/langtrace_python_sdk/version.py +++ b/src/langtrace_python_sdk/version.py @@ -1 +1 @@ -__version__ = "2.3.7" +__version__ = "2.3.8" From dd4bc1a70c2745ebcd63f03fd49281787b84d92b Mon Sep 17 00:00:00 2001 From: Karthik Kalyanaraman <105607645+karthikscale3@users.noreply.github.com> Date: Sat, 7 Sep 2024 23:30:02 -0700 Subject: [PATCH 3/4] Release (#338) * remove logs * remove requirements * Bump version * Squash * Bugfix (#335) * fix dspy issue (#337) --- src/langtrace_python_sdk/instrumentation/dspy/patch.py | 2 +- src/langtrace_python_sdk/version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/langtrace_python_sdk/instrumentation/dspy/patch.py b/src/langtrace_python_sdk/instrumentation/dspy/patch.py index 4b57fe16..5e44239b 100644 --- a/src/langtrace_python_sdk/instrumentation/dspy/patch.py +++ b/src/langtrace_python_sdk/instrumentation/dspy/patch.py @@ -31,7 +31,7 @@ def traced_method(wrapped, instance, args, kwargs): span_attributes["dspy.optimizer"] = instance.__class__.__name__ if len(args) > 0: span_attributes["dspy.optimizer.module"] = args[0].__class__.__name__ - if args[0].prog: + if hasattr(args[0], "prog") and args[0].prog: prog = { "name": args[0].prog.__class__.__name__, "signature": ( diff --git a/src/langtrace_python_sdk/version.py b/src/langtrace_python_sdk/version.py index e121c1f3..04510af6 100644 --- a/src/langtrace_python_sdk/version.py +++ b/src/langtrace_python_sdk/version.py @@ -1 +1 @@ -__version__ = "2.3.8" +__version__ = "2.3.9" From 1be9d465661b4607a178c5edaad817f08821aa6d Mon Sep 17 00:00:00 2001 From: Ali Waleed Date: Tue, 10 Sep 2024 12:50:48 +0300 Subject: [PATCH 4/4] fix warnings for crewai --- .../instrumentation/crewai/patch.py | 14 ++++++--- src/langtrace_python_sdk/langtrace.py | 31 +++++++++++-------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/langtrace_python_sdk/instrumentation/crewai/patch.py b/src/langtrace_python_sdk/instrumentation/crewai/patch.py index 64ed16d5..dfe20bde 100644 --- a/src/langtrace_python_sdk/instrumentation/crewai/patch.py +++ b/src/langtrace_python_sdk/instrumentation/crewai/patch.py @@ -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: @@ -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: @@ -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(): diff --git a/src/langtrace_python_sdk/langtrace.py b/src/langtrace_python_sdk/langtrace.py index 3413e5cf..7be1bf9f 100644 --- a/src/langtrace_python_sdk/langtrace.py +++ b/src/langtrace_python_sdk/langtrace.py @@ -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 @@ -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) @@ -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) @@ -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