-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathtest_annotations.py
126 lines (119 loc) · 5.24 KB
/
test_annotations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from inline_snapshot import snapshot
from opentelemetry.trace import get_current_span
import logfire
from logfire._internal.exporters.test import TestExporter
from logfire.experimental.annotations import get_traceparent, raw_annotate_span, record_feedback
def test_get_traceparent(exporter: TestExporter):
with logfire.span('hi') as span:
traceparent = get_traceparent(span)
assert (
traceparent
== get_traceparent(get_current_span())
== snapshot('00-00000000000000000000000000000001-0000000000000001-01')
)
raw_annotate_span(traceparent, 'my_span_name', 'my_message', {'key': 'value'})
record_feedback(
traceparent,
'factuality',
0.1,
comment='the mock agent lied',
extra={'agent_name': 'mock'},
)
record_feedback(
traceparent,
'rudeness',
'very',
)
assert exporter.exported_spans_as_dict(_include_pending_spans=True) == snapshot(
[
{
'name': 'hi',
'context': {'trace_id': 1, 'span_id': 2, 'is_remote': False},
'parent': {'trace_id': 1, 'span_id': 1, 'is_remote': False},
'start_time': 1000000000,
'end_time': 1000000000,
'attributes': {
'code.filepath': 'test_annotations.py',
'code.function': 'test_get_traceparent',
'code.lineno': 123,
'logfire.msg_template': 'hi',
'logfire.msg': 'hi',
'logfire.span_type': 'pending_span',
'logfire.pending_parent_id': '0000000000000000',
},
},
{
'name': 'hi',
'context': {'trace_id': 1, 'span_id': 1, 'is_remote': False},
'parent': None,
'start_time': 1000000000,
'end_time': 2000000000,
'attributes': {
'code.filepath': 'test_annotations.py',
'code.function': 'test_get_traceparent',
'code.lineno': 123,
'logfire.msg_template': 'hi',
'logfire.msg': 'hi',
'logfire.span_type': 'span',
},
},
{
'name': 'my_span_name',
'context': {'trace_id': 1, 'span_id': 3, 'is_remote': False},
'parent': {'trace_id': 1, 'span_id': 1, 'is_remote': True},
'start_time': 3000000000,
'end_time': 3000000000,
'attributes': {
'logfire.span_type': 'annotation',
'logfire.level_num': 9,
'logfire.msg_template': 'my_span_name',
'logfire.msg': 'my_message',
'code.filepath': 'test_annotations.py',
'code.function': 'test_get_traceparent',
'code.lineno': 123,
'key': 'value',
'logfire.json_schema': '{"type":"object","properties":{"key":{},"logfire.span_type":{}}}',
},
},
{
'name': 'feedback: factuality',
'context': {'trace_id': 1, 'span_id': 4, 'is_remote': False},
'parent': {'trace_id': 1, 'span_id': 1, 'is_remote': True},
'start_time': 4000000000,
'end_time': 4000000000,
'attributes': {
'logfire.span_type': 'annotation',
'logfire.level_num': 9,
'logfire.msg_template': 'feedback: factuality',
'logfire.msg': 'feedback: factuality = 0.1',
'code.filepath': 'test_annotations.py',
'code.function': 'test_get_traceparent',
'code.lineno': 123,
'logfire.feedback.name': 'factuality',
'factuality': 0.1,
'logfire.feedback.comment': 'the mock agent lied',
'agent_name': 'mock',
'logfire.json_schema': '{"type":"object","properties":{"logfire.feedback.name":{},"factuality":{},"agent_name":{},"logfire.feedback.comment":{},"logfire.span_type":{}}}',
},
},
{
'name': 'feedback: rudeness',
'context': {'trace_id': 1, 'span_id': 5, 'is_remote': False},
'parent': {'trace_id': 1, 'span_id': 1, 'is_remote': True},
'start_time': 5000000000,
'end_time': 5000000000,
'attributes': {
'logfire.span_type': 'annotation',
'logfire.level_num': 9,
'logfire.msg_template': 'feedback: rudeness',
'logfire.msg': "feedback: rudeness = 'very'",
'code.filepath': 'test_annotations.py',
'code.function': 'test_get_traceparent',
'code.lineno': 123,
'logfire.feedback.name': 'rudeness',
'rudeness': 'very',
'logfire.json_schema': '{"type":"object","properties":{"logfire.feedback.name":{},"rudeness":{},"logfire.span_type":{}}}',
},
},
]
)