-
Notifications
You must be signed in to change notification settings - Fork 675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(sdk): support a "block-list" of things to not instrument #1958
Merged
nirga
merged 6 commits into
traceloop:main
from
codehruv:disable-requests-instrumentation
Oct 31, 2024
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
573a7bb
disable auto-tracing of requests
codehruv 00bb29c
use block instruments instead of disable requests
codehruv 7d6c5b6
combine init and block instruments logic into a single function
codehruv 9a66946
fix: pr review issues
nirga d96d703
Merge branch 'main' into pr/1958
nirga 5607c9b
fix: ci
nirga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ def __new__( | |
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) | ||
|
@@ -125,9 +126,16 @@ def __new__( | |
|
||
instrument_set = False | ||
if instruments is None: | ||
init_instrumentations(should_enrich_metrics) | ||
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): | ||
|
@@ -525,35 +533,65 @@ def init_tracer_provider(resource: Resource) -> TracerProvider: | |
return provider | ||
|
||
|
||
def init_instrumentations(should_enrich_metrics: 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_requests_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() | ||
def init_instrumentations(should_enrich_metrics: bool, block_instruments: Optional[Set[Instruments]] = None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ideally this might be an opportunity to combine these 2 ways and just have |
||
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() | ||
|
||
|
||
def init_openai_instrumentor(should_enrich_metrics: bool): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?