Skip to content

Commit ef310e1

Browse files
committed
Fix tests
1 parent 46a32a1 commit ef310e1

File tree

4 files changed

+9
-21
lines changed

4 files changed

+9
-21
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from openai import Stream
2020

21-
from opentelemetry._logs import LogRecord, Logger
21+
from opentelemetry._logs import Logger, LogRecord
2222
from opentelemetry.semconv._incubating.attributes import (
2323
gen_ai_attributes as GenAIAttributes,
2424
)
@@ -65,9 +65,7 @@ def traced_method(wrapped, instance, args, kwargs):
6565
try:
6666
result = wrapped(*args, **kwargs)
6767
if is_streaming(kwargs):
68-
return StreamWrapper(
69-
result, span, logger, capture_content
70-
)
68+
return StreamWrapper(result, span, logger, capture_content)
7169

7270
if span.is_recording():
7371
_set_response_attributes(
@@ -123,9 +121,7 @@ async def traced_method(wrapped, instance, args, kwargs):
123121
try:
124122
result = await wrapped(*args, **kwargs)
125123
if is_streaming(kwargs):
126-
return StreamWrapper(
127-
result, span, logger, capture_content
128-
)
124+
return StreamWrapper(result, span, logger, capture_content)
129125

130126
if span.is_recording():
131127
_set_response_attributes(

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ def fixture_tracer_provider(span_exporter):
5454
provider.add_span_processor(SimpleSpanProcessor(span_exporter))
5555
return provider
5656

57+
5758
@pytest.fixture(scope="function", name="logger_provider")
5859
def fixture_logger_provider(log_exporter):
5960
provider = LoggerProvider()
6061
provider.add_log_record_processor(SimpleLogRecordProcessor(log_exporter))
6162
return provider
6263

64+
6365
@pytest.fixture(scope="function", name="meter_provider")
6466
def fixture_meter_provider(metric_reader):
6567
meter_provider = MeterProvider(
@@ -100,9 +102,7 @@ def vcr_config():
100102

101103

102104
@pytest.fixture(scope="function")
103-
def instrument_no_content(
104-
tracer_provider, logger_provider, meter_provider
105-
):
105+
def instrument_no_content(tracer_provider, logger_provider, meter_provider):
106106
os.environ.update(
107107
{OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "False"}
108108
)
@@ -120,9 +120,7 @@ def instrument_no_content(
120120

121121

122122
@pytest.fixture(scope="function")
123-
def instrument_with_content(
124-
tracer_provider, logger_provider, meter_provider
125-
):
123+
def instrument_with_content(tracer_provider, logger_provider, meter_provider):
126124
os.environ.update(
127125
{OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "True"}
128126
)

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
from opentelemetry.semconv._incubating.attributes import (
2424
error_attributes as ErrorAttributes,
2525
)
26-
from opentelemetry.semconv._incubating.attributes import (
27-
event_attributes as EventAttributes,
28-
)
2926
from opentelemetry.semconv._incubating.attributes import (
3027
gen_ai_attributes as GenAIAttributes,
3128
)
@@ -797,7 +794,7 @@ async def async_chat_completion_multiple_tools_streaming(
797794

798795

799796
def assert_message_in_logs(log, event_name, expected_content, parent_span):
800-
assert log.log_record.attributes[EventAttributes.EVENT_NAME] == event_name
797+
assert log.log_record.event_name == event_name
801798
assert (
802799
log.log_record.attributes[GenAIAttributes.GEN_AI_SYSTEM]
803800
== GenAIAttributes.GenAiSystemValues.OPENAI.value

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
from opentelemetry.semconv._incubating.attributes import (
2424
error_attributes as ErrorAttributes,
2525
)
26-
from opentelemetry.semconv._incubating.attributes import (
27-
event_attributes as EventAttributes,
28-
)
2926
from opentelemetry.semconv._incubating.attributes import (
3027
gen_ai_attributes as GenAIAttributes,
3128
)
@@ -812,7 +809,7 @@ def chat_completion_multiple_tools_streaming(
812809

813810

814811
def assert_message_in_logs(log, event_name, expected_content, parent_span):
815-
assert log.log_record.attributes[EventAttributes.EVENT_NAME] == event_name
812+
assert log.log_record.event_name == event_name
816813
assert (
817814
log.log_record.attributes[GenAIAttributes.GEN_AI_SYSTEM]
818815
== GenAIAttributes.GenAiSystemValues.OPENAI.value

0 commit comments

Comments
 (0)