From 573a7bb868e28f16ef676ecf579297ab6be440d5 Mon Sep 17 00:00:00 2001 From: Dhruv Singh Date: Fri, 13 Sep 2024 12:28:40 -0400 Subject: [PATCH 1/5] disable auto-tracing of requests --- packages/traceloop-sdk/traceloop/sdk/__init__.py | 2 ++ packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/traceloop-sdk/traceloop/sdk/__init__.py b/packages/traceloop-sdk/traceloop/sdk/__init__.py index babcd3ffd..f51b6e18c 100644 --- a/packages/traceloop-sdk/traceloop/sdk/__init__.py +++ b/packages/traceloop-sdk/traceloop/sdk/__init__.py @@ -44,6 +44,7 @@ def init( api_key: str = None, headers: Dict[str, str] = {}, disable_batch=False, + disable_requests_instrumentation: bool = True, exporter: SpanExporter = None, metrics_exporter: MetricExporter = None, metrics_headers: Dict[str, str] = None, @@ -125,6 +126,7 @@ def init( ) Traceloop.__tracer_wrapper = TracerWrapper( disable_batch=disable_batch, + disable_requests_instrumentation=disable_requests_instrumentation, processor=processor, propagator=propagator, exporter=exporter, diff --git a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py index e0bc210f7..30996b5d4 100644 --- a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py +++ b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py @@ -62,6 +62,7 @@ class TracerWrapper(object): def __new__( cls, disable_batch=False, + disable_requests_instrumentation=True, processor: SpanProcessor = None, propagator: TextMapPropagator = None, exporter: SpanExporter = None, @@ -125,7 +126,7 @@ def __new__( instrument_set = False if instruments is None: - init_instrumentations(should_enrich_metrics) + init_instrumentations(should_enrich_metrics, disable_requests_instrumentation) instrument_set = True else: for instrument in instruments: @@ -525,7 +526,7 @@ def init_tracer_provider(resource: Resource) -> TracerProvider: return provider -def init_instrumentations(should_enrich_metrics: bool): +def init_instrumentations(should_enrich_metrics: bool, disable_requests_instrumentation: bool): init_openai_instrumentor(should_enrich_metrics) init_anthropic_instrumentor(should_enrich_metrics) init_cohere_instrumentor() @@ -542,7 +543,6 @@ def init_instrumentations(should_enrich_metrics: bool): init_transformers_instrumentor() init_together_instrumentor() init_redis_instrumentor() - init_requests_instrumentor() init_urllib3_instrumentor() init_pymysql_instrumentor() init_bedrock_instrumentor(should_enrich_metrics) @@ -555,6 +555,9 @@ def init_instrumentations(should_enrich_metrics: bool): init_lancedb_instrumentor() init_groq_instrumentor() + if not disable_requests_instrumentation: + init_requests_instrumentor() + def init_openai_instrumentor(should_enrich_metrics: bool): try: From 00bb29c70593a59505850be64ed799efe88b3853 Mon Sep 17 00:00:00 2001 From: Dhruv Singh Date: Mon, 16 Sep 2024 10:58:23 -0400 Subject: [PATCH 2/5] use block instruments instead of disable requests --- .../traceloop/sdk/tracing/tracing.py | 99 +++++++++++++------ 1 file changed, 67 insertions(+), 32 deletions(-) diff --git a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py index 30996b5d4..a2968b112 100644 --- a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py +++ b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py @@ -62,12 +62,12 @@ class TracerWrapper(object): def __new__( cls, disable_batch=False, - disable_requests_instrumentation=True, processor: SpanProcessor = None, propagator: TextMapPropagator = None, exporter: SpanExporter = None, should_enrich_metrics: bool = True, instruments: Optional[Set[Instruments]] = None, + block_instruments: Optional[Set[Instruments]] = None, ) -> "TracerWrapper": if not hasattr(cls, "instance"): obj = cls.instance = super(TracerWrapper, cls).__new__(cls) @@ -126,9 +126,16 @@ def __new__( instrument_set = False if instruments is None: - init_instrumentations(should_enrich_metrics, disable_requests_instrumentation) + init_instrumentations(should_enrich_metrics, block_instruments) instrument_set = True else: + # Remove any instruments that were explicitly blocked + if block_instruments: + # Create a copy of instruments to avoid modification during iteration + for instrument in list(instruments): + if instrument in block_instruments: + instruments.remove(instrument) + for instrument in instruments: if instrument == Instruments.OPENAI: if not init_openai_instrumentor(should_enrich_metrics): @@ -526,36 +533,64 @@ def init_tracer_provider(resource: Resource) -> TracerProvider: return provider -def init_instrumentations(should_enrich_metrics: bool, disable_requests_instrumentation: bool): - init_openai_instrumentor(should_enrich_metrics) - init_anthropic_instrumentor(should_enrich_metrics) - init_cohere_instrumentor() - init_pinecone_instrumentor() - init_qdrant_instrumentor() - init_chroma_instrumentor() - init_google_generativeai_instrumentor() - init_haystack_instrumentor() - init_langchain_instrumentor() - init_mistralai_instrumentor() - init_ollama_instrumentor() - init_llama_index_instrumentor() - init_milvus_instrumentor() - init_transformers_instrumentor() - init_together_instrumentor() - init_redis_instrumentor() - init_urllib3_instrumentor() - init_pymysql_instrumentor() - init_bedrock_instrumentor(should_enrich_metrics) - init_replicate_instrumentor() - init_vertexai_instrumentor() - init_watsonx_instrumentor() - init_weaviate_instrumentor() - init_alephalpha_instrumentor() - init_marqo_instrumentor() - init_lancedb_instrumentor() - init_groq_instrumentor() - - if not disable_requests_instrumentation: +def init_instrumentations(should_enrich_metrics: bool, block_instruments: Optional[Set[Instruments]] = None): + block_instruments = block_instruments or set() + + if Instruments.OPENAI not in block_instruments: + init_openai_instrumentor(should_enrich_metrics) + if Instruments.ANTHROPIC not in block_instruments: + init_anthropic_instrumentor(should_enrich_metrics) + if Instruments.COHERE not in block_instruments: + init_cohere_instrumentor() + if Instruments.PINECONE not in block_instruments: + init_pinecone_instrumentor() + if Instruments.QDRANT not in block_instruments: + init_qdrant_instrumentor() + if Instruments.CHROMA not in block_instruments: + init_chroma_instrumentor() + if Instruments.GOOGLE_GENERATIVEAI not in block_instruments: + init_google_generativeai_instrumentor() + if Instruments.HAYSTACK not in block_instruments: + init_haystack_instrumentor() + if Instruments.LANGCHAIN not in block_instruments: + init_langchain_instrumentor() + if Instruments.MISTRAL not in block_instruments: + init_mistralai_instrumentor() + if Instruments.OLLAMA not in block_instruments: + init_ollama_instrumentor() + if Instruments.LLAMA_INDEX not in block_instruments: + init_llama_index_instrumentor() + if Instruments.MILVUS not in block_instruments: + init_milvus_instrumentor() + if Instruments.TRANSFORMERS not in block_instruments: + init_transformers_instrumentor() + if Instruments.TOGETHER not in block_instruments: + init_together_instrumentor() + if Instruments.REDIS not in block_instruments: + init_redis_instrumentor() + if Instruments.URLLIB3 not in block_instruments: + init_urllib3_instrumentor() + if Instruments.PYMYSQL not in block_instruments: + init_pymysql_instrumentor() + if Instruments.BEDROCK not in block_instruments: + init_bedrock_instrumentor(should_enrich_metrics) + if Instruments.REPLICATE not in block_instruments: + init_replicate_instrumentor() + if Instruments.VERTEXAI not in block_instruments: + init_vertexai_instrumentor() + if Instruments.WATSONX not in block_instruments: + init_watsonx_instrumentor() + if Instruments.WEAVIATE not in block_instruments: + init_weaviate_instrumentor() + if Instruments.ALEPHALPHA not in block_instruments: + init_alephalpha_instrumentor() + if Instruments.MARQO not in block_instruments: + init_marqo_instrumentor() + if Instruments.LANCEDB not in block_instruments: + init_lancedb_instrumentor() + if Instruments.GROQ not in block_instruments: + init_groq_instrumentor() + if Instruments.REQUESTS not in block_instruments: init_requests_instrumentor() From 7d6c5b6f628e112fa93a59d9686120de066e1c9a Mon Sep 17 00:00:00 2001 From: Dhruv Singh Date: Tue, 17 Sep 2024 11:29:04 -0400 Subject: [PATCH 3/5] combine init and block instruments logic into a single function --- .../traceloop/sdk/tracing/tracing.py | 449 ++++++++---------- 1 file changed, 186 insertions(+), 263 deletions(-) diff --git a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py index a2968b112..c4bbaa3ae 100644 --- a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py +++ b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py @@ -124,212 +124,7 @@ def __new__( # this makes sure otel context is propagated so we always want it ThreadingInstrumentor().instrument() - instrument_set = False - if instruments is None: - init_instrumentations(should_enrich_metrics, block_instruments) - instrument_set = True - else: - # Remove any instruments that were explicitly blocked - if block_instruments: - # Create a copy of instruments to avoid modification during iteration - for instrument in list(instruments): - if instrument in block_instruments: - instruments.remove(instrument) - - for instrument in instruments: - if instrument == Instruments.OPENAI: - if not init_openai_instrumentor(should_enrich_metrics): - print(Fore.RED + "Warning: OpenAI library does not exist.") - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.ANTHROPIC: - if not init_anthropic_instrumentor(should_enrich_metrics): - print( - Fore.RED + "Warning: Anthropic library does not exist." - ) - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.COHERE: - if not init_cohere_instrumentor(): - print(Fore.RED + "Warning: Cohere library does not exist.") - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.PINECONE: - if not init_pinecone_instrumentor(): - print( - Fore.RED + "Warning: Pinecone library does not exist." - ) - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.CHROMA: - if not init_chroma_instrumentor(): - print(Fore.RED + "Warning: Chroma library does not exist.") - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.GOOGLE_GENERATIVEAI: - if not init_google_generativeai_instrumentor(): - print( - Fore.RED - + "Warning: Google Generative AI library does not exist." - ) - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.LANGCHAIN: - if not init_langchain_instrumentor(): - print( - Fore.RED + "Warning: LangChain library does not exist." - ) - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.MISTRAL: - if not init_mistralai_instrumentor(): - print( - Fore.RED + "Warning: MistralAI library does not exist." - ) - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.OLLAMA: - if not init_ollama_instrumentor(): - print(Fore.RED + "Warning: Ollama library does not exist.") - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.LLAMA_INDEX: - if not init_llama_index_instrumentor(): - print( - Fore.RED + "Warning: LlamaIndex library does not exist." - ) - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.MILVUS: - if not init_milvus_instrumentor(): - print(Fore.RED + "Warning: Milvus library does not exist.") - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.TRANSFORMERS: - if not init_transformers_instrumentor(): - print( - Fore.RED - + "Warning: Transformers library does not exist." - ) - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.TOGETHER: - if not init_together_instrumentor(): - print( - Fore.RED + "Warning: TogetherAI library does not exist." - ) - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.REQUESTS: - if not init_requests_instrumentor(): - print( - Fore.RED + "Warning: Requests library does not exist." - ) - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.URLLIB3: - if not init_urllib3_instrumentor(): - print(Fore.RED + "Warning: urllib3 library does not exist.") - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.PYMYSQL: - if not init_pymysql_instrumentor(): - print(Fore.RED + "Warning: PyMySQL library does not exist.") - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.BEDROCK: - if not init_bedrock_instrumentor(should_enrich_metrics): - print(Fore.RED + "Warning: Bedrock library does not exist.") - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.REPLICATE: - if not init_replicate_instrumentor(): - print( - Fore.RED + "Warning: Replicate library does not exist." - ) - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.VERTEXAI: - if not init_vertexai_instrumentor(): - print( - Fore.RED + "Warning: Vertex AI library does not exist." - ) - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.WATSONX: - if not init_watsonx_instrumentor(): - print(Fore.RED + "Warning: Watsonx library does not exist.") - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.WEAVIATE: - if not init_weaviate_instrumentor(): - print( - Fore.RED + "Warning: Weaviate library does not exist." - ) - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.ALEPHALPHA: - if not init_alephalpha_instrumentor(): - print( - Fore.RED - + "Warning: Aleph Alpha library does not exist." - ) - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.MARQO: - if not init_marqo_instrumentor(): - print(Fore.RED + "Warning: marqo library does not exist.") - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.LANCEDB: - if not init_lancedb_instrumentor(): - print(Fore.RED + "Warning: LanceDB library does not exist.") - print(Fore.RESET) - else: - instrument_set = True - elif instrument == Instruments.REDIS: - if not init_redis_instrumentor(): - print(Fore.RED + "Warning: redis library does not exist.") - print(Fore.RESET) - else: - instrument_set = True - - else: - print( - Fore.RED - + "Warning: " - + instrument - + " instrumentation does not exist." - ) - print( - "Usage:\n" - + "from traceloop.sdk.instruments import Instruments\n" - + 'Traceloop.init(app_name="...", instruments=set([Instruments.OPENAI]))' - ) - print(Fore.RESET) + instrument_set = init_instrumentations(should_enrich_metrics, instruments, block_instruments) if not instrument_set: print( @@ -533,65 +328,193 @@ def init_tracer_provider(resource: Resource) -> TracerProvider: return provider -def init_instrumentations(should_enrich_metrics: bool, block_instruments: Optional[Set[Instruments]] = None): +def init_instrumentations(should_enrich_metrics: bool, instruments: Optional[Set[Instruments]] = None, block_instruments: Optional[Set[Instruments]] = None): block_instruments = block_instruments or set() + instruments = instruments or set(Instruments) # Use all instruments if none specified + + # Remove any instruments that were explicitly blocked + instruments = instruments - block_instruments + + instrument_set = False + for instrument in instruments: + if instrument == Instruments.OPENAI: + if init_openai_instrumentor(should_enrich_metrics): + instrument_set = True + else: + print(Fore.RED + "Warning: OpenAI library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.ANTHROPIC: + if init_anthropic_instrumentor(should_enrich_metrics): + instrument_set = True + else: + print(Fore.RED + "Warning: Anthropic library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.COHERE: + if init_cohere_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Cohere library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.PINECONE: + if init_pinecone_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Pinecone library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.QDRANT: + if init_qdrant_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Qdrant library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.CHROMA: + if init_chroma_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Chroma library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.GOOGLE_GENERATIVEAI: + if init_google_generativeai_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Google GenerativeAI library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.HAYSTACK: + if init_haystack_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Haystack library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.LANGCHAIN: + if init_langchain_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: LangChain library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.MISTRAL: + if init_mistralai_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: MistralAI library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.OLLAMA: + if init_ollama_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Ollama library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.LLAMA_INDEX: + if init_llama_index_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: LlamaIndex library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.MILVUS: + if init_milvus_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Milvus library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.TRANSFORMERS: + if init_transformers_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Transformers library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.TOGETHER: + if init_together_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Together library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.REDIS: + if init_redis_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Redis library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.URLLIB3: + if init_urllib3_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Urllib3 library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.PYMYSQL: + if init_pymysql_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: PyMySQL library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.BEDROCK: + if init_bedrock_instrumentor(should_enrich_metrics): + instrument_set = True + else: + print(Fore.RED + "Warning: Bedrock library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.REPLICATE: + if init_replicate_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Replicate library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.VERTEXAI: + if init_vertexai_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: VertexAI library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.WATSONX: + if init_watsonx_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: WatsonX library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.WEAVIATE: + if init_weaviate_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Weaviate library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.ALEPHALPHA: + if init_alephalpha_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: AlephAlpha library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.MARQO: + if init_marqo_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Marqo library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.LANCEDB: + if init_lancedb_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: LanceDB library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.GROQ: + if init_groq_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Groq library does not exist.") + print(Fore.RESET) + elif instrument == Instruments.REQUESTS: + if init_requests_instrumentor(): + instrument_set = True + else: + print(Fore.RED + "Warning: Requests library does not exist.") + print(Fore.RESET) + else: + print(Fore.RED + f"Warning: {instrument} instrumentation does not exist.") + print("Usage:\nfrom traceloop.sdk.instruments import Instruments\nTraceloop.init(app_name='...', instruments=set([Instruments.OPENAI]))") + print(Fore.RESET) + + if not instrument_set: + print(Fore.RED + "Warning: No valid instruments set. Specify instruments or remove 'instruments' argument to use all instruments.") + print(Fore.RESET) - if Instruments.OPENAI not in block_instruments: - init_openai_instrumentor(should_enrich_metrics) - if Instruments.ANTHROPIC not in block_instruments: - init_anthropic_instrumentor(should_enrich_metrics) - if Instruments.COHERE not in block_instruments: - init_cohere_instrumentor() - if Instruments.PINECONE not in block_instruments: - init_pinecone_instrumentor() - if Instruments.QDRANT not in block_instruments: - init_qdrant_instrumentor() - if Instruments.CHROMA not in block_instruments: - init_chroma_instrumentor() - if Instruments.GOOGLE_GENERATIVEAI not in block_instruments: - init_google_generativeai_instrumentor() - if Instruments.HAYSTACK not in block_instruments: - init_haystack_instrumentor() - if Instruments.LANGCHAIN not in block_instruments: - init_langchain_instrumentor() - if Instruments.MISTRAL not in block_instruments: - init_mistralai_instrumentor() - if Instruments.OLLAMA not in block_instruments: - init_ollama_instrumentor() - if Instruments.LLAMA_INDEX not in block_instruments: - init_llama_index_instrumentor() - if Instruments.MILVUS not in block_instruments: - init_milvus_instrumentor() - if Instruments.TRANSFORMERS not in block_instruments: - init_transformers_instrumentor() - if Instruments.TOGETHER not in block_instruments: - init_together_instrumentor() - if Instruments.REDIS not in block_instruments: - init_redis_instrumentor() - if Instruments.URLLIB3 not in block_instruments: - init_urllib3_instrumentor() - if Instruments.PYMYSQL not in block_instruments: - init_pymysql_instrumentor() - if Instruments.BEDROCK not in block_instruments: - init_bedrock_instrumentor(should_enrich_metrics) - if Instruments.REPLICATE not in block_instruments: - init_replicate_instrumentor() - if Instruments.VERTEXAI not in block_instruments: - init_vertexai_instrumentor() - if Instruments.WATSONX not in block_instruments: - init_watsonx_instrumentor() - if Instruments.WEAVIATE not in block_instruments: - init_weaviate_instrumentor() - if Instruments.ALEPHALPHA not in block_instruments: - init_alephalpha_instrumentor() - if Instruments.MARQO not in block_instruments: - init_marqo_instrumentor() - if Instruments.LANCEDB not in block_instruments: - init_lancedb_instrumentor() - if Instruments.GROQ not in block_instruments: - init_groq_instrumentor() - if Instruments.REQUESTS not in block_instruments: - init_requests_instrumentor() + return instrument_set def init_openai_instrumentor(should_enrich_metrics: bool): From 9a6694634aee2cde232bdd5f69e72635b828ce46 Mon Sep 17 00:00:00 2001 From: Nir Gazit Date: Thu, 31 Oct 2024 12:01:28 +0100 Subject: [PATCH 4/5] fix: pr review issues --- packages/traceloop-sdk/traceloop/sdk/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/traceloop-sdk/traceloop/sdk/__init__.py b/packages/traceloop-sdk/traceloop/sdk/__init__.py index f51b6e18c..02a712f70 100644 --- a/packages/traceloop-sdk/traceloop/sdk/__init__.py +++ b/packages/traceloop-sdk/traceloop/sdk/__init__.py @@ -44,7 +44,6 @@ def init( api_key: str = None, headers: Dict[str, str] = {}, disable_batch=False, - disable_requests_instrumentation: bool = True, exporter: SpanExporter = None, metrics_exporter: MetricExporter = None, metrics_headers: Dict[str, str] = None, @@ -54,6 +53,7 @@ def init( should_enrich_metrics: bool = True, resource_attributes: dict = {}, instruments: Optional[Set[Instruments]] = None, + block_instruments: Optional[Set[Instruments]] = None, ) -> None: Telemetry() @@ -126,12 +126,12 @@ def init( ) Traceloop.__tracer_wrapper = TracerWrapper( disable_batch=disable_batch, - disable_requests_instrumentation=disable_requests_instrumentation, processor=processor, propagator=propagator, exporter=exporter, should_enrich_metrics=should_enrich_metrics, instruments=instruments, + block_instruments=block_instruments, ) if not metrics_exporter and exporter: From 5607c9bc3e8bc0f4d841246cdfff6a055cf0efbd Mon Sep 17 00:00:00 2001 From: Nir Gazit Date: Thu, 31 Oct 2024 12:12:10 +0100 Subject: [PATCH 5/5] fix: ci --- packages/traceloop-sdk/tests/conftest.py | 3 +- .../traceloop/sdk/instruments.py | 31 ++++++++++--------- .../traceloop/sdk/tracing/tracing.py | 13 +++++--- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/packages/traceloop-sdk/tests/conftest.py b/packages/traceloop-sdk/tests/conftest.py index 8d1a57e38..a67bf404e 100644 --- a/packages/traceloop-sdk/tests/conftest.py +++ b/packages/traceloop-sdk/tests/conftest.py @@ -77,7 +77,8 @@ def exporter_with_custom_instrumentations(): Traceloop.init( exporter=exporter, disable_batch=True, - instruments=[i for i in Instruments], + instruments={i for i in Instruments}, + block_instruments={Instruments.ANTHROPIC}, ) yield exporter diff --git a/packages/traceloop-sdk/traceloop/sdk/instruments.py b/packages/traceloop-sdk/traceloop/sdk/instruments.py index 300a37a3a..c0d34aa15 100644 --- a/packages/traceloop-sdk/traceloop/sdk/instruments.py +++ b/packages/traceloop-sdk/traceloop/sdk/instruments.py @@ -2,29 +2,32 @@ class Instruments(Enum): - OPENAI = "openai" + ALEPHALPHA = "alephalpha" ANTHROPIC = "anthropic" - COHERE = "cohere" - PINECONE = "pinecone" + BEDROCK = "bedrock" CHROMA = "chroma" + COHERE = "cohere" GOOGLE_GENERATIVEAI = "google_generativeai" + GROQ = "groq" + HAYSTACK = "haystack" + LANCEDB = "lancedb" LANGCHAIN = "langchain" - MISTRAL = "mistral" - OLLAMA = "ollama" LLAMA_INDEX = "llama_index" + MARQO = "marqo" MILVUS = "milvus" - TRANSFORMERS = "transformers" - TOGETHER = "together" + MISTRAL = "mistral" + OLLAMA = "ollama" + OPENAI = "openai" + PINECONE = "pinecone" + PYMYSQL = "pymysql" + QDRANT = "qdrant" REDIS = "redis" + REPLICATE = "replicate" REQUESTS = "requests" + SAGEMAKER = "sagemaker" + TOGETHER = "together" + TRANSFORMERS = "transformers" URLLIB3 = "urllib3" - PYMYSQL = "pymysql" - BEDROCK = "bedrock" - REPLICATE = "replicate" VERTEXAI = "vertexai" WATSONX = "watsonx" WEAVIATE = "weaviate" - ALEPHALPHA = "alephalpha" - MARQO = "marqo" - LANCEDB = "lancedb" - SAGEMAKER = "sagemaker" diff --git a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py index def1ca000..ab6e57131 100644 --- a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py +++ b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py @@ -355,13 +355,15 @@ def init_instrumentations( instrument_set = False for instrument in instruments: if instrument == Instruments.OPENAI: - if init_openai_instrumentor(should_enrich_metrics): + if init_openai_instrumentor(should_enrich_metrics, base64_image_uploader): instrument_set = True else: print(Fore.RED + "Warning: OpenAI library does not exist.") print(Fore.RESET) elif instrument == Instruments.ANTHROPIC: - if init_anthropic_instrumentor(should_enrich_metrics): + if init_anthropic_instrumentor( + should_enrich_metrics, base64_image_uploader + ): instrument_set = True else: print(Fore.RED + "Warning: Anthropic library does not exist.") @@ -525,14 +527,17 @@ def init_instrumentations( else: print(Fore.RED + f"Warning: {instrument} instrumentation does not exist.") print( - "Usage:\nfrom traceloop.sdk.instruments import Instruments\nTraceloop.init(app_name='...', instruments=set([Instruments.OPENAI]))" + "Usage:\n" + "from traceloop.sdk.instruments import Instruments\n" + "Traceloop.init(app_name='...', instruments=set([Instruments.OPENAI]))" ) print(Fore.RESET) if not instrument_set: print( Fore.RED - + "Warning: No valid instruments set. Specify instruments or remove 'instruments' argument to use all instruments." + + "Warning: No valid instruments set. " + + "Specify instruments or remove 'instruments' argument to use all instruments." ) print(Fore.RESET)