Skip to content

Commit 9857ba2

Browse files
committed
review comments
1 parent ea05833 commit 9857ba2

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

ddtrace/contrib/internal/langchain/patch.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -582,29 +582,31 @@ def traced_similarity_search(langchain_core, pin, func, instance, args, kwargs):
582582

583583

584584
def patched_embeddings_init_subclass(func, instance, args, kwargs):
585-
try:
586-
func(*args, **kwargs)
587-
finally:
588-
cls = func.__self__
585+
func(*args, **kwargs)
586+
cls = func.__self__
589587

588+
try:
590589
embed_documents = getattr(cls, "embed_documents", None)
591590
if embed_documents and not isinstance(embed_documents, wrapt.ObjectProxy):
592591
wrap(cls, "embed_documents", traced_embedding(langchain_core))
593592

594593
embed_query = getattr(cls, "embed_query", None)
595594
if embed_query and not isinstance(embed_query, wrapt.ObjectProxy):
596595
wrap(cls, "embed_query", traced_embedding(langchain_core))
596+
except Exception:
597+
log.warning("Unable to patch LangChain Embeddings class %s", str(cls))
597598

598599

599600
def patched_vectorstore_init_subclass(func, instance, args, kwargs):
600-
try:
601-
func(*args, **kwargs)
602-
finally:
603-
cls = func.__self__
601+
func(*args, **kwargs)
602+
cls = func.__self__
604603

604+
try:
605605
method = getattr(cls, "similarity_search", None)
606606
if method and not isinstance(method, wrapt.ObjectProxy):
607607
wrap(cls, "similarity_search", traced_similarity_search(langchain_core))
608+
except Exception:
609+
log.warning("Unable to patch LangChain VectorStore class %s", str(cls))
608610

609611

610612
def patch():

tests/contrib/langchain/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def llmobs_events(llmobs, llmobs_span_writer):
6262
# `sys.modules`. Additionally, changing to "session" will fail snapshot tests.
6363
# Setting this to "module" seems to work the best.
6464
# Additionally, this likely isn't an indication of a bug in our code, but how patching happens during tests.
65-
# In userland, patching will really only happen once, and unpatching almost never.
6665
@pytest.fixture(scope="module")
6766
def langchain_core():
6867
with override_env(

0 commit comments

Comments
 (0)