Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Langchain embedding span support([#157](https://github.com/alibaba/loongsuite-python-agent/pull/157))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Langchain embedding span support([#157](https://github.com/alibaba/loongsuite-python-agent/pull/157))
- LangChain embedding span support
([#157](https://github.com/alibaba/loongsuite-python-agent/pull/157))

- Rerank / document-compressor span support
([#149](https://github.com/alibaba/loongsuite-python-agent/pull/149))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ loongsuite-instrument <your_run_command>
| ReAct Step | `STEP` | `gen_ai.operation.name=react`, `gen_ai.react.round`, `gen_ai.react.finish_reason` |
| Tool | `TOOL` | `gen_ai.operation.name=execute_tool` |
| Retriever | `RETRIEVER` | `gen_ai.operation.name=retrieval` |
| Embedding | `EMBEDDING` | `gen_ai.operation.name=embeddings`, `gen_ai.request.model`, `gen_ai.provider.name`, `server.address`, `server.port`, `gen_ai.embeddings.dimension.count`, `gen_ai.request.encoding_formats` |
| Reranker | `RERANKER` | `gen_ai.operation.name=rerank_documents`, `gen_ai.request.model`, `gen_ai.rerank.documents.count`, `gen_ai.request.top_k`, `gen_ai.rerank.input_documents`, `gen_ai.rerank.output_documents` (when content capture enabled) |

ReAct Step spans are created for each Reasoning-Acting iteration, with the hierarchy: Agent > ReAct Step > LLM/Tool. Supported agent types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,29 @@ def _uninstrument_create_agent() -> None:
_patched_create_agent_locations.clear()


# ------------------------------------------------------------------
# Embeddings patch
# ------------------------------------------------------------------


def _instrument_embeddings(handler: Any) -> None:
"""Wrap all current and future ``Embeddings`` subclasses."""
from opentelemetry.instrumentation.langchain.internal.patch_embedding import ( # noqa: PLC0415
instrument_embeddings,
)

instrument_embeddings(handler)


def _uninstrument_embeddings() -> None:
"""Restore original ``Embeddings`` methods."""
from opentelemetry.instrumentation.langchain.internal.patch_embedding import ( # noqa: PLC0415
uninstrument_embeddings,
)

uninstrument_embeddings()


# ------------------------------------------------------------------
# BaseDocumentCompressor patch (rerank / compression)
# ------------------------------------------------------------------
Expand Down Expand Up @@ -268,6 +291,7 @@ def _instrument(self, **kwargs: Any) -> None:
_instrument_agent_executor()
_instrument_create_agent()
_instrument_document_compressor(handler)
_instrument_embeddings(handler)

def _uninstrument(self, **kwargs: Any) -> None:
try:
Expand All @@ -281,6 +305,7 @@ def _uninstrument(self, **kwargs: Any) -> None:
_uninstrument_agent_executor()
_uninstrument_create_agent()
_uninstrument_document_compressor()
_uninstrument_embeddings()


class _BaseCallbackManagerInit:
Expand Down
Loading
Loading