from athina_logger.tracing.trace import Trace
# Create a Trace
trace = Trace(name="trace_1")
print(trace)
# Trace(name=trace_1, dict={'name': 'trace_1', 'start_time': '2024-03-18T04:13:33.569491', 'attributes': {}, 'spans': []}, spans=[])
print("\nAssociate Spans with the Trace")
span1 = trace.create_span(name="span_1")
span2 = trace.create_span(name="span_2")
print("\nCurrent Trace:")
print(trace)
# Trace(name=trace_1, dict={'name': 'trace_1', 'start_time': '2024-03-18T04:13:33.569491', 'attributes': {}, 'spans': [{'name': 'span_1', 'start_time': '2024-03-18T04:13:33.570455', 'span_type': 'span', 'attributes': {}, 'input': {}, 'output': {}, 'children': []}, {'name': 'span_2', 'start_time': '2024-03-18T04:13:33.570467', 'span_type': 'span', 'attributes': {}, 'input': {}, 'output': {}, 'children': []}]}, spans=[Span(name=span_1, dict={'name': 'span_1', 'start_time': '2024-03-18T04:13:33.570455', 'span_type': 'span', 'attributes': {}, 'input': {}, 'output': {}, 'children': []}, children=[]), Span(name=span_2, dict={'name': 'span_2', 'start_time': '2024-03-18T04:13:33.570467', 'span_type': 'span', 'attributes': {}, 'input': {}, 'output': {}, 'children': []}, children=[])])
span1.create_span(name="span_3")
print("\nAdded a child Span to one of the Spans")
print(span1)
# Span(name=span_1, dict={'name': 'span_1', 'start_time': '2024-03-18T04:13:33.570455', 'span_type': 'span', 'attributes': {}, 'input': {}, 'output': {}, 'children': [{'name': 'span_3', 'start_time': '2024-03-18T04:13:33.570551', 'span_type': 'span', 'attributes': {}, 'input': {}, 'output': {}, 'children': []}]}, children=[Span(name=span_3, dict={'name': 'span_3', 'start_time': '2024-03-18T04:13:33.570551', 'span_type': 'span', 'attributes': {}, 'input': {}, 'output': {}, 'children': []}, children=[])])
generation1 = span2.create_generation(name="generation_1", user_query="user_query_1")
print("\nAdded a child Generation to one of the Spans")
print(span2)
# Span(name=span_2, dict={'name': 'span_2', 'start_time': '2024-03-18T04:13:33.570467', 'span_type': 'span', 'attributes': {}, 'input': {}, 'output': {}, 'children': [{'name': 'generation_1', 'start_time': '2024-03-18T04:13:33.570611', 'span_type': 'generation', 'attributes': {'user_query': 'user_query_1'}, 'input': {}, 'output': {}, 'children': []}]}, children=[Span(name=generation_1, dict={'name': 'generation_1', 'start_time': '2024-03-18T04:13:33.570611', 'span_type': 'generation', 'attributes': {'user_query': 'user_query_1'}, 'input': {}, 'output': {}, 'children': []}, children=[])])
generation1.update(response="response_2")
print("\nUpdated a Span(Generation type)")
print(generation1)
# Span(name=generation_1, dict={'name': 'generation_1', 'start_time': '2024-03-18T04:13:33.570611', 'span_type': 'generation', 'attributes': {'response': 'response_2', 'user_query': 'user_query_1'}, 'input': {}, 'output': {}, 'children': []}, children=[])