Skip to content

Commit cc95a5a

Browse files
authored
Obinna/fix awsbedrock streaming response (#538)
* fix aws bedrock streaming bug * bump version * add deprecated dependency * restrict current pinecone instrumentation to v6.0.2 * hard code boto3 dependency version
1 parent 8f5aba4 commit cc95a5a

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ dependencies = [
3232
"transformers>=4.11.3",
3333
"sentry-sdk>=2.14.0",
3434
"ujson>=5.10.0",
35-
"boto3",
35+
"boto3==1.38.0",
3636
"setuptools",
37+
"Deprecated==1.2.18",
3738
]
3839

3940
requires-python = ">=3.9"
@@ -47,7 +48,7 @@ dev = [
4748
"qdrant-client",
4849
"graphlit-client",
4950
"python-dotenv",
50-
"pinecone",
51+
"pinecone>=3.1.0,<=6.0.2",
5152
"langchain",
5253
"langchain-community",
5354
"langchain-openai",

src/langtrace_python_sdk/instrumentation/aws_bedrock/patch.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import json
1818

1919
from wrapt import ObjectProxy
20+
from itertools import tee
2021
from .stream_body_wrapper import BufferedStreamBody
2122
from functools import wraps
2223
from langtrace.trace_attributes import (
@@ -128,7 +129,9 @@ def traced_method(*args, **kwargs):
128129
response = original_method(*args, **kwargs)
129130

130131
if span.is_recording():
131-
set_span_streaming_response(span, response)
132+
stream1, stream2 = tee(response["stream"])
133+
set_span_streaming_response(span, stream1)
134+
response["stream"] = stream2
132135
return response
133136

134137
return traced_method
@@ -442,10 +445,10 @@ def _set_response_attributes(span, kwargs, result):
442445
)
443446

444447

445-
def set_span_streaming_response(span, response):
448+
def set_span_streaming_response(span, response_stream):
446449
streaming_response = ""
447450
role = None
448-
for event in response["stream"]:
451+
for event in response_stream:
449452
if "messageStart" in event:
450453
role = event["messageStart"]["role"]
451454
elif "contentBlockDelta" in event:

src/langtrace_python_sdk/instrumentation/pinecone/instrumentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class PineconeInstrumentation(BaseInstrumentor):
3333
The PineconeInstrumentation class represents the Pinecone instrumentation"""
3434

3535
def instrumentation_dependencies(self) -> Collection[str]:
36-
return ["pinecone >= 3.1.0"]
36+
return ["pinecone >= 3.1.0", "pinecone <= 6.0.2"]
3737

3838
def _instrument(self, **kwargs):
3939
tracer_provider = kwargs.get("tracer_provider")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.8.18"
1+
__version__ = "3.8.19"

0 commit comments

Comments
 (0)