Skip to content

Commit f97424c

Browse files
authored
Merge branch 'main' into langchain-agent-spans
2 parents 370d930 + 5279805 commit f97424c

File tree

16 files changed

+582
-23
lines changed

16 files changed

+582
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434
- `opentelemetry-instrumentation-django`: improve docs for response_hook with examples of providing attributes from middlewares
3535
([#3923](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3923))
3636
- Update for Log SDK breaking changes. Rename InMemoryLogExporter to InMemoryLogRecordExporter in several tests
37-
([#3850](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3589))
37+
([#3589](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3589))
38+
- opentelemetry-instrumentation: allow to skip all instrumentations loading with a wildcard
39+
([#3967](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3967))
3840

3941
### Fixed
4042

instrumentation-genai/opentelemetry-instrumentation-google-genai/tests/generate_content/nonstreaming_base.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from google.genai.types import GenerateContentConfig
2121
from pydantic import BaseModel, Field
2222

23-
from opentelemetry._events import Event
2423
from opentelemetry.instrumentation._semconv import (
2524
_OpenTelemetrySemanticConventionStability,
2625
_OpenTelemetryStabilitySignalType,
@@ -324,7 +323,7 @@ def test_new_semconv_record_completion_as_log(self):
324323
event.attributes,
325324
)
326325
else:
327-
attrs = {
326+
expected_event_attributes = {
328327
gen_ai_attributes.GEN_AI_INPUT_MESSAGES: (
329328
{
330329
"role": "user",
@@ -346,31 +345,27 @@ def test_new_semconv_record_completion_as_log(self):
346345
{"content": sys_instr, "type": "text"},
347346
),
348347
}
349-
expected_event = Event(
350-
"gen_ai.client.inference.operation.details",
351-
attributes=attrs,
352-
)
353348
self.assertEqual(
354349
event.attributes[
355350
gen_ai_attributes.GEN_AI_INPUT_MESSAGES
356351
],
357-
expected_event.attributes[
352+
expected_event_attributes[
358353
gen_ai_attributes.GEN_AI_INPUT_MESSAGES
359354
],
360355
)
361356
self.assertEqual(
362357
event.attributes[
363358
gen_ai_attributes.GEN_AI_OUTPUT_MESSAGES
364359
],
365-
expected_event.attributes[
360+
expected_event_attributes[
366361
gen_ai_attributes.GEN_AI_OUTPUT_MESSAGES
367362
],
368363
)
369364
self.assertEqual(
370365
event.attributes[
371366
gen_ai_attributes.GEN_AI_SYSTEM_INSTRUCTIONS
372367
],
373-
expected_event.attributes[
368+
expected_event_attributes[
374369
gen_ai_attributes.GEN_AI_SYSTEM_INSTRUCTIONS
375370
],
376371
)

instrumentation-genai/opentelemetry-instrumentation-openai-v2/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## Version 2.2b0 (2025-11-25)
11+
1012
- Fix service tier attribute names: use `GEN_AI_OPENAI_REQUEST_SERVICE_TIER` for request
1113
attributes and `GEN_AI_OPENAI_RESPONSE_SERVICE_TIER` for response attributes.
1214
([#3920](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3920))
1315
- Added support for OpenAI embeddings instrumentation
1416
([#3461](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3461))
1517
- Record prompt and completion events regardless of span sampling decision.
1618
([#3226](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3226))
19+
- Filter out attributes with the value of NotGiven instances
20+
([#3760](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3760))
1721
- Migrate off the deprecated events API to use the logs API
1822
([#3625](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3628))
1923

@@ -37,4 +41,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3741
([#2925](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2925))
3842

3943
- Initial OpenAI instrumentation
40-
([#2759](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2759))
44+
([#2759](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2759))

instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/utils.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
from os import environ
16-
from typing import Mapping, Optional, Union
18+
from typing import Mapping
1719
from urllib.parse import urlparse
1820

1921
from httpx import URL
20-
from openai import NOT_GIVEN
22+
from openai import NotGiven
2123

2224
from opentelemetry._logs import LogRecord
2325
from opentelemetry.semconv._incubating.attributes import (
@@ -179,8 +181,12 @@ def is_streaming(kwargs):
179181
return non_numerical_value_is_set(kwargs.get("stream"))
180182

181183

182-
def non_numerical_value_is_set(value: Optional[Union[bool, str]]):
183-
return bool(value) and value != NOT_GIVEN
184+
def non_numerical_value_is_set(value: bool | str | NotGiven | None):
185+
return bool(value) and value_is_set(value)
186+
187+
188+
def value_is_set(value):
189+
return value is not None and not isinstance(value, NotGiven)
184190

185191

186192
def get_llm_request_attributes(
@@ -257,8 +263,8 @@ def get_llm_request_attributes(
257263

258264
set_server_address_and_port(client_instance, attributes)
259265

260-
# filter out None values
261-
return {k: v for k, v in attributes.items() if v is not None}
266+
# filter out values not set
267+
return {k: v for k, v in attributes.items() if value_is_set(v)}
262268

263269

264270
def handle_span_exception(span, error):

instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "2.2b0.dev"
15+
__version__ = "2.3b0.dev"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Recording calls
2+
3+
If you need to record calls you need to export the `OPENAI_API_KEY` as environment variable.
4+
Since tox blocks environment variables by default you need to override its configuration to let them pass:
5+
6+
```
7+
export TOX_OVERRIDE=testenv.pass_env=OPENAI_API_KEY
8+
```
9+
10+
We are not adding it to tox.ini because of security concerns.
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
interactions:
2+
- request:
3+
body: |-
4+
{
5+
"messages": [
6+
{
7+
"role": "user",
8+
"content": "Say this is a test"
9+
}
10+
],
11+
"model": "gpt-4o-mini",
12+
"stream": false
13+
}
14+
headers:
15+
accept:
16+
- application/json
17+
accept-encoding:
18+
- gzip, deflate
19+
authorization:
20+
- Bearer test_openai_api_key
21+
connection:
22+
- keep-alive
23+
content-length:
24+
- '106'
25+
content-type:
26+
- application/json
27+
host:
28+
- api.openai.com
29+
user-agent:
30+
- OpenAI/Python 1.109.1
31+
x-stainless-arch:
32+
- x64
33+
x-stainless-async:
34+
- 'false'
35+
x-stainless-lang:
36+
- python
37+
x-stainless-os:
38+
- Linux
39+
x-stainless-package-version:
40+
- 1.109.1
41+
x-stainless-read-timeout:
42+
- '600'
43+
x-stainless-retry-count:
44+
- '0'
45+
x-stainless-runtime:
46+
- CPython
47+
x-stainless-runtime-version:
48+
- 3.10.12
49+
method: POST
50+
uri: https://api.openai.com/v1/chat/completions
51+
response:
52+
body:
53+
string: |-
54+
{
55+
"id": "chatcmpl-CZDvsSHdMnAgYuQ8J81NMgOK2wfam",
56+
"object": "chat.completion",
57+
"created": 1762511072,
58+
"model": "gpt-4o-mini-2024-07-18",
59+
"choices": [
60+
{
61+
"index": 0,
62+
"message": {
63+
"role": "assistant",
64+
"content": "This is a test. How can I assist you today?",
65+
"refusal": null,
66+
"annotations": []
67+
},
68+
"logprobs": null,
69+
"finish_reason": "stop"
70+
}
71+
],
72+
"usage": {
73+
"prompt_tokens": 12,
74+
"completion_tokens": 12,
75+
"total_tokens": 24,
76+
"prompt_tokens_details": {
77+
"cached_tokens": 0,
78+
"audio_tokens": 0
79+
},
80+
"completion_tokens_details": {
81+
"reasoning_tokens": 0,
82+
"audio_tokens": 0,
83+
"accepted_prediction_tokens": 0,
84+
"rejected_prediction_tokens": 0
85+
}
86+
},
87+
"service_tier": "default",
88+
"system_fingerprint": "fp_560af6e559"
89+
}
90+
headers:
91+
CF-RAY:
92+
- 99ac1f128834ed5e-MXP
93+
Connection:
94+
- keep-alive
95+
Content-Type:
96+
- application/json
97+
Date:
98+
- Fri, 07 Nov 2025 10:24:32 GMT
99+
Server:
100+
- cloudflare
101+
Set-Cookie: test_set_cookie
102+
Strict-Transport-Security:
103+
- max-age=31536000; includeSubDomains; preload
104+
Transfer-Encoding:
105+
- chunked
106+
X-Content-Type-Options:
107+
- nosniff
108+
access-control-expose-headers:
109+
- X-Request-ID
110+
alt-svc:
111+
- h3=":443"; ma=86400
112+
cf-cache-status:
113+
- DYNAMIC
114+
content-length:
115+
- '850'
116+
openai-organization: test_openai_org_id
117+
openai-processing-ms:
118+
- '512'
119+
openai-project:
120+
- proj_Pf1eM5R55Z35wBy4rt8PxAGq
121+
openai-version:
122+
- '2020-10-01'
123+
x-envoy-upstream-service-time:
124+
- '797'
125+
x-openai-proxy-wasm:
126+
- v0.1
127+
x-ratelimit-limit-requests:
128+
- '10000'
129+
x-ratelimit-limit-tokens:
130+
- '10000000'
131+
x-ratelimit-remaining-requests:
132+
- '9999'
133+
x-ratelimit-remaining-tokens:
134+
- '9999993'
135+
x-ratelimit-reset-requests:
136+
- 6ms
137+
x-ratelimit-reset-tokens:
138+
- 0s
139+
x-request-id:
140+
- req_9eac1833161f4ac89019c12f24002ef4
141+
status:
142+
code: 200
143+
message: OK
144+
version: 1

0 commit comments

Comments
 (0)