Skip to content

Remove LogData in tests #3636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,27 @@ def restore(self):


class _LogWrapper:
def __init__(self, log_data):
self._log_data = log_data
def __init__(self, log_record):
self._log_record = log_record

@property
def scope(self):
return self._log_data.instrumentation_scope
return self._log_record.instrumentation_scope

@property
def resource(self):
return self._log_data.log_record.resource
return self._log_record.resource

@property
def attributes(self):
return self._log_data.log_record.attributes
return self._log_record.attributes

@property
def body(self):
return self._log_data.log_record.body
return self._log_record.body

def __str__(self):
return self._log_data.log_record.to_json()
return self._log_record.to_json()


class _MetricDataPointWrapper:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,13 @@ async def test_async_chat_completion_streaming_unsampled(
}
assert_message_in_logs(logs[1], "gen_ai.choice", choice_event, None)

assert logs[0].log_record.trace_id is not None
assert logs[0].log_record.span_id is not None
assert logs[0].log_record.trace_flags == 0
assert logs[0].trace_id is not None
assert logs[0].span_id is not None
assert logs[0].trace_flags == 0

assert logs[0].log_record.trace_id == logs[1].log_record.trace_id
assert logs[0].log_record.span_id == logs[1].log_record.span_id
assert logs[0].log_record.trace_flags == logs[1].log_record.trace_flags
assert logs[0].trace_id == logs[1].trace_id
assert logs[0].span_id == logs[1].span_id
assert logs[0].trace_flags == logs[1].trace_flags


async def async_chat_completion_multiple_tools_streaming(
Expand Down Expand Up @@ -797,19 +797,17 @@ async def async_chat_completion_multiple_tools_streaming(


def assert_message_in_logs(log, event_name, expected_content, parent_span):
assert log.log_record.attributes[EventAttributes.EVENT_NAME] == event_name
assert log.attributes[EventAttributes.EVENT_NAME] == event_name
assert (
log.log_record.attributes[GenAIAttributes.GEN_AI_SYSTEM]
log.attributes[GenAIAttributes.GEN_AI_SYSTEM]
== GenAIAttributes.GenAiSystemValues.OPENAI.value
)

if not expected_content:
assert not log.log_record.body
assert not log.body
else:
assert log.log_record.body
assert dict(log.log_record.body) == remove_none_values(
expected_content
)
assert log.body
assert dict(log.body) == remove_none_values(expected_content)
assert_log_parent(log, parent_span)


Expand Down Expand Up @@ -906,11 +904,9 @@ def assert_all_attributes(

def assert_log_parent(log, span):
if span:
assert log.log_record.trace_id == span.get_span_context().trace_id
assert log.log_record.span_id == span.get_span_context().span_id
assert (
log.log_record.trace_flags == span.get_span_context().trace_flags
)
assert log.trace_id == span.get_span_context().trace_id
assert log.span_id == span.get_span_context().span_id
assert log.trace_flags == span.get_span_context().trace_flags


def get_current_weather_tool_definition():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,13 +692,13 @@ def test_chat_completion_with_content_span_unsampled(
}
assert_message_in_logs(logs[1], "gen_ai.choice", choice_event, None)

assert logs[0].log_record.trace_id is not None
assert logs[0].log_record.span_id is not None
assert logs[0].log_record.trace_flags == 0
assert logs[0].trace_id is not None
assert logs[0].span_id is not None
assert logs[0].trace_flags == 0

assert logs[0].log_record.trace_id == logs[1].log_record.trace_id
assert logs[0].log_record.span_id == logs[1].log_record.span_id
assert logs[0].log_record.trace_flags == logs[1].log_record.trace_flags
assert logs[0].trace_id == logs[1].trace_id
assert logs[0].span_id == logs[1].span_id
assert logs[0].trace_flags == logs[1].trace_flags


def chat_completion_multiple_tools_streaming(
Expand Down Expand Up @@ -812,19 +812,17 @@ def chat_completion_multiple_tools_streaming(


def assert_message_in_logs(log, event_name, expected_content, parent_span):
assert log.log_record.attributes[EventAttributes.EVENT_NAME] == event_name
assert log.attributes[EventAttributes.EVENT_NAME] == event_name
assert (
log.log_record.attributes[GenAIAttributes.GEN_AI_SYSTEM]
log.attributes[GenAIAttributes.GEN_AI_SYSTEM]
== GenAIAttributes.GenAiSystemValues.OPENAI.value
)

if not expected_content:
assert not log.log_record.body
assert not log.body
else:
assert log.log_record.body
assert dict(log.log_record.body) == remove_none_values(
expected_content
)
assert log.body
assert dict(log.body) == remove_none_values(expected_content)
assert_log_parent(log, parent_span)


Expand Down Expand Up @@ -921,11 +919,9 @@ def assert_all_attributes(

def assert_log_parent(log, span):
if span:
assert log.log_record.trace_id == span.get_span_context().trace_id
assert log.log_record.span_id == span.get_span_context().span_id
assert (
log.log_record.trace_flags == span.get_span_context().trace_flags
)
assert log.trace_id == span.get_span_context().trace_id
assert log.span_id == span.get_span_context().span_id
assert log.trace_flags == span.get_span_context().trace_flags


def get_current_weather_tool_definition():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_generate_content(
# Emits user and choice events
logs = log_exporter.get_finished_logs()
assert len(logs) == 2
user_log, choice_log = [log_data.log_record for log_data in logs]
user_log, choice_log = logs

span_context = spans[0].get_span_context()
assert user_log.trace_id == span_context.trace_id
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_generate_content_without_events(
# Emits user and choice event without body.content
logs = log_exporter.get_finished_logs()
assert len(logs) == 2
user_log, choice_log = [log_data.log_record for log_data in logs]
user_log, choice_log = logs
assert user_log.attributes == {
"gen_ai.system": "vertex_ai",
"event.name": "gen_ai.user.message",
Expand Down Expand Up @@ -285,11 +285,11 @@ def test_generate_content_invalid_role(
# Emits the faulty content which caused the request to fail
logs = log_exporter.get_finished_logs()
assert len(logs) == 1
assert logs[0].log_record.attributes == {
assert logs[0].attributes == {
"gen_ai.system": "vertex_ai",
"event.name": "gen_ai.user.message",
}
assert logs[0].log_record.body == {
assert logs[0].body == {
"content": [{"text": "Say this is a test"}],
"role": "invalid_role",
}
Expand Down Expand Up @@ -414,9 +414,7 @@ def generate_content_all_input_events(
# Emits a system event, 2 users events, an assistant event, and the choice (response) event
logs = log_exporter.get_finished_logs()
assert len(logs) == 5
system_log, user_log1, assistant_log, user_log2, choice_log = [
log_data.log_record for log_data in logs
]
system_log, user_log1, assistant_log, user_log2, choice_log = logs

assert system_log.attributes == {
"gen_ai.system": "vertex_ai",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_function_call_choice(
# Emits user and choice events
logs = log_exporter.get_finished_logs()
assert len(logs) == 2
user_log, choice_log = [log_data.log_record for log_data in logs]
user_log, choice_log = logs
assert user_log.attributes == {
"gen_ai.system": "vertex_ai",
"event.name": "gen_ai.user.message",
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_function_call_choice_no_content(
# Emits user and choice events
logs = log_exporter.get_finished_logs()
assert len(logs) == 2
user_log, choice_log = [log_data.log_record for log_data in logs]
user_log, choice_log = logs
assert user_log.attributes == {
"gen_ai.system": "vertex_ai",
"event.name": "gen_ai.user.message",
Expand Down Expand Up @@ -169,9 +169,7 @@ def test_tool_events(
# Emits user, assistant, two tool, and choice events
logs = log_exporter.get_finished_logs()
assert len(logs) == 5
user_log, assistant_log, tool_log1, tool_log2, choice_log = [
log_data.log_record for log_data in logs
]
user_log, assistant_log, tool_log1, tool_log2, choice_log = logs
assert user_log.attributes == {
"gen_ai.system": "vertex_ai",
"event.name": "gen_ai.user.message",
Expand Down Expand Up @@ -271,9 +269,7 @@ def test_tool_events_no_content(
# Emits user, assistant, two tool, and choice events
logs = log_exporter.get_finished_logs()
assert len(logs) == 5
user_log, assistant_log, tool_log1, tool_log2, choice_log = [
log_data.log_record for log_data in logs
]
user_log, assistant_log, tool_log1, tool_log2, choice_log = logs
assert user_log.attributes == {
"gen_ai.system": "vertex_ai",
"event.name": "gen_ai.user.message",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,32 +280,32 @@ def remove_none_values(body):
return result


def assert_log_parent(log, span):
def assert_log_parent(log_record, span):
if span:
assert log.log_record.trace_id == span.get_span_context().trace_id
assert log.log_record.span_id == span.get_span_context().span_id
assert (
log.log_record.trace_flags == span.get_span_context().trace_flags
)
assert log_record.trace_id == span.get_span_context().trace_id
assert log_record.span_id == span.get_span_context().span_id
assert log_record.trace_flags == span.get_span_context().trace_flags


def assert_message_in_logs(log, event_name, expected_content, parent_span):
def assert_message_in_logs(
log_record, event_name, expected_content, parent_span
):
assert (
log.log_record.attributes[EventAttributes.EVENT_NAME] == event_name
), log.log_record.attributes[EventAttributes.EVENT_NAME]
log_record.attributes[EventAttributes.EVENT_NAME] == event_name
), log_record.attributes[EventAttributes.EVENT_NAME]
assert (
log.log_record.attributes[GenAIAttributes.GEN_AI_SYSTEM]
log_record.attributes[GenAIAttributes.GEN_AI_SYSTEM]
== GenAIAttributes.GenAiSystemValues.AWS_BEDROCK.value
)

if not expected_content:
assert not log.log_record.body
assert not log_record.body
else:
assert log.log_record.body
assert dict(log.log_record.body) == remove_none_values(
assert log_record.body
assert dict(log_record.body) == remove_none_values(
expected_content
), dict(log.log_record.body)
assert_log_parent(log, parent_span)
), dict(log_record.body)
assert_log_parent(log_record, parent_span)


def assert_all_metric_attributes(
Expand Down
Loading