Skip to content

Commit 4759d81

Browse files
polish: removed get_attr guard.
1 parent 8fb9c83 commit 4759d81

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

  • instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ uv run tox -e typecheck
6565
- The monorepo uses `uv` workspaces.
6666
- `tox.ini` defines the test matrix - check it for available test environments.
6767
- Do not add `type: ignore` comments. If a type error arises, solve it properly or write a follow-up plan to address it in another PR.
68+
- Annotate function signatures (parameters and return types) and class attributes. Prefer `from __future__ import annotations` over runtime-quoted strings.
6869
- Whenever applicable, all code changes should have tests that actually validate the changes.
6970

7071
## Instrumentation rules

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,28 @@ def _set_response_model(self, chunk):
5252
if self._self_response_model:
5353
return
5454

55-
if getattr(chunk, "model", None):
55+
if chunk.model:
5656
self._self_response_model = chunk.model
5757

5858
def _set_response_id(self, chunk):
5959
if self._self_response_id:
6060
return
6161

62-
if getattr(chunk, "id", None):
62+
if chunk.id:
6363
self._self_response_id = chunk.id
6464

6565
def _set_response_service_tier(self, chunk):
6666
if self._self_service_tier:
6767
return
6868

69-
if getattr(chunk, "service_tier", None):
69+
if chunk.service_tier:
7070
self._self_service_tier = chunk.service_tier
7171

7272
def _build_streaming_response(self, chunk):
73-
if getattr(chunk, "choices", None) is None:
73+
if chunk.choices is None:
7474
return
7575

76-
choices = chunk.choices
77-
for choice in choices:
76+
for choice in chunk.choices:
7877
if not choice.delta:
7978
continue
8079

@@ -98,7 +97,7 @@ def _build_streaming_response(self, chunk):
9897
)
9998

10099
def _set_usage(self, chunk):
101-
if getattr(chunk, "usage", None):
100+
if chunk.usage:
102101
self._self_completion_tokens = chunk.usage.completion_tokens
103102
self._self_prompt_tokens = chunk.usage.prompt_tokens
104103

0 commit comments

Comments
 (0)