Skip to content

Commit d0eff63

Browse files
Merge remote-tracking branch 'origin/main' into fix/remove-suppress-language-model-key
Co-authored-by: Cursor <cursoragent@cursor.com>
2 parents 49d4120 + f8269ad commit d0eff63

5 files changed

Lines changed: 35 additions & 25 deletions

File tree

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Fixed
11+
12+
- Fix `AttributeError: 'StreamWrapper' object has no attribute 'headers'` when
13+
using `with_raw_response.create(stream=True)` (e.g. via LiteLLM's Azure provider).
14+
`_parse_response` was calling `.parse()` on the `LegacyAPIResponse` before wrapping
15+
in `StreamWrapper`, discarding the raw HTTP headers. `StreamWrapper` now captures
16+
headers from the `LegacyAPIResponse` before it is parsed and exposes them directly,
17+
and adds a `parse()` method returning `self` so callers can treat the wrapper as
18+
a drop-in for the raw response. Also adds `__getattr__` to proxy any other unknown
19+
attributes to the underlying stream. Inspired by upstream fix
20+
([opentelemetry-python-contrib#4184](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4184),
21+
fixes [#4113](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/4113)).
22+
1023
### Added
1124
- **`SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION` env var** — Global alternative to
12-
the per-request `suppress_language_model_instrumentation` OTel context key.
13-
When set to a truthy value (`true`, `1`, `yes`, `on`), the openai-v2
14-
instrumentor skips creating spans entirely. Intended for zero-code deployments
15-
alongside `OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=openai`.
25+
the per-request `suppress_language_model_instrumentation` OTel context key
26+
(the env var is the uppercase form of the same string). When set to a truthy
27+
value (`true`, `1`, `yes`, `on`), the openai-v2 instrumentor skips creating
28+
spans entirely. Intended for zero-code deployments alongside
29+
`OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=openai`.
1630

1731
### Fixed
1832

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
)
3131
from opentelemetry.trace import Span
3232
from opentelemetry.util.genai.attributes import (
33-
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_ENV_VAR,
3433
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY,
3534
)
3635
from opentelemetry.util.genai.handler import (
@@ -74,7 +73,9 @@ def _is_instrumentation_suppressed() -> bool:
7473
"""
7574
if context_api.get_value(SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY):
7675
return True
77-
raw = os.environ.get(SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_ENV_VAR, "")
76+
raw = os.environ.get(
77+
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY.upper(), ""
78+
)
7879
return raw.strip().lower() in ("true", "1", "yes", "on")
7980

8081

instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/test_suppression.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@
2727

2828
from opentelemetry import context as context_api
2929
from opentelemetry.util.genai.attributes import (
30-
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_ENV_VAR,
3130
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY,
3231
)
3332

33+
# The env var name is the uppercase form of the context key string.
34+
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_ENV_VAR = (
35+
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY.upper()
36+
)
37+
3438

3539
@pytest.mark.vcr()
3640
def test_chat_completion_suppressed(

util/opentelemetry-util-genai/CHANGELOG.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ All notable changes to this repository are documented in this file.
66

77
### Added
88

9-
- **`SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION` env var constant** — Added
10-
`SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_ENV_VAR` to `attributes.py` as the
11-
environment variable counterpart of the existing
12-
`SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY` context key. Allows
13-
zero-code deployments to set suppression globally without requiring the
14-
LangChain instrumentor to inject the context key per-request.
9+
- **`SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION` env var** — The uppercase form of
10+
`SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY` is now also checked as an
11+
environment variable by the openai-v2 instrumentor, allowing zero-code
12+
deployments to set suppression globally without the LangChain instrumentor
13+
injecting the context key per-request. No new constant added.
1514

1615
- **`OTEL_INSTRUMENTATION_GENAI_EMIT_EVENT` env var** — Explicit override for content event emission (`true`/`false`). When unset, defaults are derived from `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` mode.
1716

util/opentelemetry-util-genai/src/opentelemetry/util/genai/attributes.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,10 @@
9696

9797
# Context key for suppressing instrumentation to avoid duplicate telemetry
9898
# when multiple instrumentations (e.g., LangChain + OpenAI) are active.
99-
# Can be set at runtime via context (per-request) or globally via the
100-
# SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION environment variable.
99+
# The uppercase form of this string is also checked as an environment variable
100+
# (SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION) so zero-code deployments can set
101+
# suppression globally without the LangChain instrumentor injecting it
102+
# per-request. Use together with OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=openai.
101103
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY = (
102104
"suppress_language_model_instrumentation"
103105
)
104-
105-
# Environment variable name that mirrors the context key above.
106-
# When set to a truthy value ("true", "1", "yes", "on") the openai-v2
107-
# instrumentor skips creating spans globally — without requiring the
108-
# LangChain instrumentor to inject the context key per-request.
109-
# Intended for zero-code deployments together with
110-
# OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=openai.
111-
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_ENV_VAR = (
112-
"SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION"
113-
)

0 commit comments

Comments
 (0)