Skip to content

Commit 9e273f6

Browse files
committed
add uninstrument in tests + remove any none values from span attributes
1 parent 8fc4336 commit 9e273f6

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def traced_method(wrapped, instance, args, kwargs):
5454
name=span_name, kind=SpanKind.CLIENT, attributes=span_attributes
5555
)
5656
if span.is_recording():
57-
_set_input_attributes(span, span_attributes)
5857
set_event_prompt(span, json.dumps(llm_prompts))
5958

6059
try:
@@ -84,12 +83,6 @@ def traced_method(wrapped, instance, args, kwargs):
8483
return traced_method
8584

8685

87-
@silently_fail
88-
def _set_input_attributes(span, attributes):
89-
for field, value in attributes.items():
90-
set_span_attribute(span, field, value)
91-
92-
9386
@silently_fail
9487
def _set_response_attributes(span, result):
9588
set_span_attribute(

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def get_llm_request_attributes(
143143
operation_name=GenAIAttributes.GenAiOperationNameValues.CHAT.value,
144144
):
145145

146-
return {
146+
attributes = {
147147
GenAIAttributes.GEN_AI_OPERATION_NAME: operation_name,
148148
GenAIAttributes.GEN_AI_SYSTEM: GenAIAttributes.GenAiSystemValues.OPENAI.value,
149149
GenAIAttributes.GEN_AI_REQUEST_MODEL: kwargs.get(
@@ -160,3 +160,6 @@ def get_llm_request_attributes(
160160
"frequency_penalty"
161161
),
162162
}
163+
164+
# filter out None values
165+
return {k: v for k, v in attributes.items() if v is not None}

instrumentation/opentelemetry-instrumentation-openai-v2/tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ def instrument():
5656
OpenAIInstrumentor().instrument()
5757

5858

59+
@pytest.fixture(scope="session", autouse=True)
60+
def uninstrument():
61+
OpenAIInstrumentor().uninstrument()
62+
63+
5964
def scrub_response_headers(response):
6065
"""
6166
This scrubs sensitive response headers. Note they are case-sensitive!

0 commit comments

Comments
 (0)