openlit: [Bug]: App fails when OpenLIT is used

πŸ› What’s Going Wrong?

I have a small LangChain-based app that works. When I add openlit.init(), it fails to start with the following exceptions:

Failed to instrument transformers: No module named 'transformers.pipelines'; 'transformers' is not a package
...
  File "/Users/User/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/langchain_community/embeddings/bedrock.py", line 150, in _embedding_func
    raise ValueError(f"Error raised by inference endpoint: {e}")
ValueError: Error raised by inference endpoint: 'SSO' object has no attribute 'invoke_model'

If I remove transformers package it complains about the absense:

DependencyConflict: requested: "transformers >= 4.39.3" but found: "None"

πŸ•΅οΈ Steps to Reproduce

I have an app that makes use of the following:

  • langchain 0.2.5
  • chromadb 0.5.3
  • Amazon Bedrock with Claude 3 and Titan v2 Embeddings

Here is the code with logic stripped for brevity:

import openlit

from langchain_community.embeddings.bedrock import BedrockEmbeddings
from langchain_community.vectorstores.chroma import Chroma
from langchain_aws import ChatBedrock
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate

openlit.init()

text_for_search = ""

be = BedrockEmbeddings(model_id='amazon.titan-embed-text-v2:0')
ch = Chroma(persist_directory='./chroma', embedding_function=be)
sres = ch.similarity_search_with_score(query=text_for_search)

prompt = """prompt {input} {search_result}"""

llm = ChatBedrock(model_id="anthropic.claude-3-opus-20240229-v1:0")
prompt = ChatPromptTemplate.from_template(prompt)
output_parser = StrOutputParser()
chain = prompt | llm | output_parser

r = chain.invoke({"input": "some input", "search_result": sres[0][0].page_content})

When I comment out openlit.init(), it works.

🎯 What Did You Expect?

The app gets instrumented with traces.

πŸ“Έ Any Screenshots?

Pictures can say a thousand words and can be super helpful!

πŸ’» Your Setup

  • OpenLIT Version: 1.14.1
  • Deployment Method: Docker

πŸ“ Additional Notes

Got more to say? Tell us here.

πŸ‘ Want to Help Make It Happen?

  • Yes, I’d like to volunteer and help out with this!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Hi @patcher9

Unfortunately the error persists. Here is the full trace. I suspect that may be connected to the fact I’m authenticating to AWS using SSO.

{
    "name": "bedrock.invoke_model",
    "context": {
        "trace_id": "0xccb8c145f0cbb83b6a9fb507f2f7298f",
        "span_id": "0x8929caf4aa31c01f",
        "trace_state": "[]"
    },
    "kind": "SpanKind.CLIENT",
    "parent_id": null,
    "start_time": "2024-07-01T16:58:04.064154Z",
    "end_time": "2024-07-01T16:58:04.098340Z",
    "status": {
        "status_code": "ERROR",
        "description": "AttributeError: 'SSO' object has no attribute 'invoke_model'"
    },
    "attributes": {},
    "events": [
        {
            "name": "exception",
            "timestamp": "2024-07-01T16:58:04.098168Z",
            "attributes": {
                "exception.type": "AttributeError",
                "exception.message": "'SSO' object has no attribute 'invoke_model'",
                "exception.stacktrace": "Traceback (most recent call last):\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/opentelemetry/trace/__init__.py\", line 570, in use_span\n    yield span\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/opentelemetry/sdk/trace/__init__.py\", line 1071, in start_as_current_span\n    yield span\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/openlit/instrumentation/bedrock/bedrock.py\", line 375, in add_instrumentation\n    response = original_method(*method_args, **method_kwargs)\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/client.py\", line 565, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/client.py\", line 1001, in _make_api_call\n    http, parsed_response = self._make_request(\n                            ^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/client.py\", line 1027, in _make_request\n    return self._endpoint.make_request(operation_model, request_dict)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/endpoint.py\", line 119, in make_request\n    return self._send_request(request_dict, operation_model)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/endpoint.py\", line 198, in _send_request\n    request = self.create_request(request_dict, operation_model)\n              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/endpoint.py\", line 134, in create_request\n    self._event_emitter.emit(\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/hooks.py\", line 412, in emit\n    return self._emitter.emit(aliased_event_name, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/hooks.py\", line 256, in emit\n    return self._emit(event_name, kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/hooks.py\", line 239, in _emit\n    response = handler(**kwargs)\n               ^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/signers.py\", line 105, in handler\n    return self.sign(operation_name, request)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/signers.py\", line 190, in sign\n    auth = self.get_auth_instance(**kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/signers.py\", line 310, in get_auth_instance\n    frozen_credentials = credentials.get_frozen_credentials()\n                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/credentials.py\", line 634, in get_frozen_credentials\n    self._refresh()\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/credentials.py\", line 522, in _refresh\n    self._protected_refresh(is_mandatory=is_mandatory_refresh)\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/credentials.py\", line 538, in _protected_refresh\n    metadata = self._refresh_using()\n               ^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/credentials.py\", line 685, in fetch_credentials\n    return self._get_cached_credentials()\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/credentials.py\", line 695, in _get_cached_credentials\n    response = self._get_credentials()\n               ^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/credentials.py\", line 2147, in _get_credentials\n    client = self._client_creator('sso', config=config)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/session.py\", line 997, in create_client\n    client = client_creator.create_client(\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/openlit/instrumentation/bedrock/bedrock.py\", line 430, in wrapper\n    original_invoke_model = client.invoke_model\n                            ^^^^^^^^^^^^^^^^^^^\n  File \"/Users/Gennadii_Aleksandrov/Library/Caches/pypoetry/virtualenvs/librefactor-k7sXJnK--py3.12/lib/python3.12/site-packages/botocore/client.py\", line 918, in __getattr__\n    raise AttributeError(\nAttributeError: 'SSO' object has no attribute 'invoke_model'\n",
                "exception.escaped": "False"
            }
        }
    ],
    "links": [],
    "resource": {
        "attributes": {
            "service.name": "default",
            "deployment.environment": "default",
            "telemetry.sdk.name": "openlit"
        },
        "schema_url": ""
    }
}