Skip to content

Commit 3f8ca64

Browse files
authored
Merge branch 'main' into add_redis_client_only_instrumentation
2 parents cf134ea + 96f4a03 commit 3f8ca64

22 files changed

+2549
-47
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
([#3143](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3143))
1818
- `opentelemetry-instrumentation-botocore` Add support for GenAI user events and lazy initialize tracer
1919
([#3258](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3258))
20+
- `opentelemetry-instrumentation-botocore` Add support for GenAI system events
21+
([#3266](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3266))
2022

2123
### Fixed
2224

2325
- `opentelemetry-instrumentation-redis` Add missing entry in doc string for `def _instrument`
2426
([#3247](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3247))
27+
- `opentelemetry-instrumentation-asyncpg` Fix fallback for empty queries.
28+
([#3253](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3253))
2529

2630
## Version 1.30.0/0.51b0 (2025-02-03)
2731

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<strong>
3434
<a href="CONTRIBUTING.md">Contributing<a/>
3535
&nbsp;&nbsp;&bull;&nbsp;&nbsp;
36-
<a href="https://opentelemetry-python-contrib.readthedocs.io/en/stable/#examples">Examples<a/>
36+
<a href="https://opentelemetry-python-contrib.readthedocs.io/en/latest/#instrumentations">Instrumentations<a/>
3737
</strong>
3838
</p>
3939

instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,10 @@ def _uninstrument(self, **__):
150150

151151
async def _do_execute(self, func, instance, args, kwargs):
152152
exception = None
153-
params = getattr(instance, "_params", {})
154-
name = args[0] if args[0] else params.get("database", "postgresql")
153+
params = getattr(instance, "_params", None)
154+
name = (
155+
args[0] if args[0] else getattr(params, "database", "postgresql")
156+
)
155157

156158
try:
157159
# Strip leading comments so we get the operation name.
@@ -185,11 +187,11 @@ async def _do_execute(self, func, instance, args, kwargs):
185187
async def _do_cursor_execute(self, func, instance, args, kwargs):
186188
"""Wrap cursor based functions. For every call this will generate a new span."""
187189
exception = None
188-
params = getattr(instance._connection, "_params", {})
190+
params = getattr(instance._connection, "_params", None)
189191
name = (
190192
instance._query
191193
if instance._query
192-
else params.get("database", "postgresql")
194+
else getattr(params, "database", "postgresql")
193195
)
194196

195197
try:

instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/bedrock.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,23 @@ def _set_if_not_none(attributes, key, value):
209209
attributes[key] = value
210210

211211
def _get_request_messages(self):
212+
"""Extracts and normalize system and user / assistant messages"""
212213
input_text = None
214+
if system := self._call_context.params.get("system", []):
215+
system_messages = [{"role": "system", "content": system}]
216+
else:
217+
system_messages = []
218+
213219
if not (messages := self._call_context.params.get("messages", [])):
214220
if body := self._call_context.params.get("body"):
215221
decoded_body = json.loads(body)
222+
if system := decoded_body.get("system"):
223+
if isinstance(system, str):
224+
content = [{"text": system}]
225+
else:
226+
content = system
227+
system_messages = [{"role": "system", "content": content}]
228+
216229
messages = decoded_body.get("messages", [])
217230
if not messages:
218231
# transform old school amazon titan invokeModel api to messages
@@ -221,7 +234,7 @@ def _get_request_messages(self):
221234
{"role": "user", "content": [{"text": input_text}]}
222235
]
223236

224-
return messages
237+
return system_messages + messages
225238

226239
def before_service_call(
227240
self, span: Span, instrumentor_context: _BotocoreInstrumentorContext

instrumentation/opentelemetry-instrumentation-botocore/tests/bedrock_utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ def assert_stream_completion_attributes(
161161

162162
def assert_equal_or_not_present(value, attribute_name, span):
163163
if value is not None:
164-
assert value == span.attributes[attribute_name]
164+
assert value == span.attributes[attribute_name], span.attributes[
165+
attribute_name
166+
]
165167
else:
166168
assert attribute_name not in span.attributes, attribute_name
167169

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
interactions:
2+
- request:
3+
body: |-
4+
{
5+
"system": [
6+
{
7+
"text": "You are a friendly app"
8+
}
9+
],
10+
"messages": [
11+
{
12+
"role": "user",
13+
"content": [
14+
{
15+
"text": "Say this is a test"
16+
}
17+
]
18+
},
19+
{
20+
"role": "assistant",
21+
"content": [
22+
{
23+
"text": "This is a test"
24+
}
25+
]
26+
},
27+
{
28+
"role": "user",
29+
"content": [
30+
{
31+
"text": "Say again this is a test"
32+
}
33+
]
34+
}
35+
]
36+
}
37+
headers:
38+
Content-Length:
39+
- '258'
40+
Content-Type:
41+
- application/json
42+
User-Agent:
43+
- Boto3/1.35.56 md/Botocore#1.35.56 ua/2.0 os/linux#6.1.0-1034-oem md/arch#x86_64
44+
lang/python#3.10.12 md/pyimpl#CPython cfg/retry-mode#legacy Botocore/1.35.56
45+
X-Amz-Date:
46+
- 20250213T113027Z
47+
X-Amz-Security-Token:
48+
- test_aws_security_token
49+
X-Amzn-Trace-Id:
50+
- Root=1-d9112d64-56325c43023ba04895b18fc1;Parent=d56bf41aee9dd9b2;Sampled=1
51+
amz-sdk-invocation-id:
52+
- 4e1fd77b-1b21-4b3a-9b96-d74fb74ede7c
53+
amz-sdk-request:
54+
- attempt=1
55+
authorization:
56+
- Bearer test_aws_authorization
57+
method: POST
58+
uri: https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-v2/converse
59+
response:
60+
body:
61+
string: |-
62+
{
63+
"metrics": {
64+
"latencyMs": 489
65+
},
66+
"output": {
67+
"message": {
68+
"content": [
69+
{
70+
"text": "This is a test"
71+
}
72+
],
73+
"role": "assistant"
74+
}
75+
},
76+
"stopReason": "end_turn",
77+
"usage": {
78+
"inputTokens": 37,
79+
"outputTokens": 8,
80+
"totalTokens": 45
81+
}
82+
}
83+
headers:
84+
Connection:
85+
- keep-alive
86+
Content-Type:
87+
- application/json
88+
Date:
89+
- Thu, 13 Feb 2025 11:30:28 GMT
90+
Set-Cookie: test_set_cookie
91+
x-amzn-RequestId:
92+
- 67f0b4ef-e481-4c12-853b-d8e992395129
93+
status:
94+
code: 200
95+
message: OK
96+
version: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
interactions:
2+
- request:
3+
body: |-
4+
{
5+
"system": [
6+
{
7+
"text": "You are a friendly app"
8+
}
9+
],
10+
"messages": [
11+
{
12+
"role": "user",
13+
"content": [
14+
{
15+
"text": "Say this is a test"
16+
}
17+
]
18+
},
19+
{
20+
"role": "assistant",
21+
"content": [
22+
{
23+
"text": "This is a test"
24+
}
25+
]
26+
},
27+
{
28+
"role": "user",
29+
"content": [
30+
{
31+
"text": "Say again this is a test"
32+
}
33+
]
34+
}
35+
]
36+
}
37+
headers:
38+
Content-Length:
39+
- '258'
40+
Content-Type:
41+
- application/json
42+
User-Agent:
43+
- Boto3/1.35.56 md/Botocore#1.35.56 ua/2.0 os/linux#6.1.0-1034-oem md/arch#x86_64
44+
lang/python#3.10.12 md/pyimpl#CPython cfg/retry-mode#legacy Botocore/1.35.56
45+
X-Amz-Date:
46+
- 20250213T134717Z
47+
X-Amz-Security-Token:
48+
- test_aws_security_token
49+
X-Amzn-Trace-Id:
50+
- Root=1-014325aa-ed2dea786b6b5b895661a1fd;Parent=540790d110580421;Sampled=1
51+
amz-sdk-invocation-id:
52+
- 22820432-2412-4351-98af-8c70c71c84a9
53+
amz-sdk-request:
54+
- attempt=1
55+
authorization:
56+
- Bearer test_aws_authorization
57+
method: POST
58+
uri: https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-v2/converse-stream
59+
response:
60+
body:
61+
string: !!binary |
62+
AAAAkwAAAFJ24bJxCzpldmVudC10eXBlBwAMbWVzc2FnZVN0YXJ0DTpjb250ZW50LXR5cGUHABBh
63+
cHBsaW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OnsidGV4dCI6IiB0ZXN0In0s
77+
InAiOiJhYmNkZWZnaGlqa2xtbm9wcXJzdHV2dyJ9V81m8wAAAIkAAABWW9z5Sws6ZXZlbnQtdHlw
78+
ZQcAEGNvbnRlbnRCbG9ja1N0b3ANOmNvbnRlbnQtdHlwZQcAEGFwcGxpY2F0aW9uL2pzb24NOm1l
79+
c3NhZ2UtdHlwZQcABWV2ZW50eyJjb250ZW50QmxvY2tJbmRleCI6MCwicCI6ImFiY2RlIn3nHPCv
80+
AAAAoAAAAFEJaSGdCzpldmVudC10eXBlBwALbWVzc2FnZVN0b3ANOmNvbnRlbnQtdHlwZQcAEGFw
81+
cGxpY2F0aW9uL2pzb24NOm1lc3NhZ2UtdHlwZQcABWV2ZW50eyJwIjoiYWJjZGVmZ2hpamtsbW5v
82+
cHFyc3R1dnd4eXpBQkNERSIsInN0b3BSZWFzb24iOiJlbmRfdHVybiJ9p5BdEgAAAMsAAABOaoNq
83+
NAs6ZXZlbnQtdHlwZQcACG1ldGFkYXRhDTpjb250ZW50LXR5cGUHABBhcHBsaWNhdGlvbi9qc29u
84+
DTptZXNzYWdlLXR5cGUHAAVldmVudHsibWV0cmljcyI6eyJsYXRlbmN5TXMiOjM2MX0sInAiOiJh
85+
YmNkZWZnaGlqa2wiLCJ1c2FnZSI6eyJpbnB1dFRva2VucyI6MzcsIm91dHB1dFRva2VucyI6OCwi
86+
dG90YWxUb2tlbnMiOjQ1fX1Nq2WY
87+
headers:
88+
Connection:
89+
- keep-alive
90+
Content-Type:
91+
- application/vnd.amazon.eventstream
92+
Date:
93+
- Thu, 13 Feb 2025 13:47:17 GMT
94+
Set-Cookie: test_set_cookie
95+
Transfer-Encoding:
96+
- chunked
97+
x-amzn-RequestId:
98+
- e443d332-cba6-4076-a4f6-86d6321eada3
99+
status:
100+
code: 200
101+
message: OK
102+
version: 1

0 commit comments

Comments
 (0)