11from unittest import TestCase
2- < << << << HEAD
3- from unittest .mock import MagicMock , patch , call
4- == == == =
52from unittest .mock import MagicMock , call , patch
6- > >> >> >> 770 f906 (add custom batch export )
73
84from amazon .opentelemetry .distro .llo_handler import LLOHandler
95from opentelemetry ._events import Event
@@ -71,23 +67,6 @@ def test_is_llo_attribute_no_match(self):
7167 self .assertFalse (self .llo_handler ._is_llo_attribute ("some.other.attribute" ))
7268
7369 def test_is_llo_attribute_traceloop_match (self ):
74- < << << << HEAD
75- """
76- Test _is_llo_attribute method with Traceloop patterns
77- """
78- # Test exact matches for Traceloop attributes
79- self .assertTrue (self .llo_handler ._is_llo_attribute ("traceloop.entity.input" ))
80- self .assertTrue (self .llo_handler ._is_llo_attribute ("traceloop.entity.output" ))
81-
82- def test_is_llo_attribute_openlit_match (self ):
83- """
84- Test _is_llo_attribute method with OpenLit patterns
85- """
86- # Test exact matches for direct OpenLit attributes
87- self .assertTrue (self .llo_handler ._is_llo_attribute ("gen_ai.prompt" ))
88- self .assertTrue (self .llo_handler ._is_llo_attribute ("gen_ai.completion" ))
89- self .assertTrue (self .llo_handler ._is_llo_attribute ("gen_ai.content.revised_prompt" ))
90- == == == =
9170 """
9271 Test _is_llo_attribute method with Traceloop patterns
9372 """
@@ -103,7 +82,6 @@ def test_is_llo_attribute_openlit_match(self):
10382 self .assertTrue (self .llo_handler ._is_llo_attribute ("gen_ai.prompt" ))
10483 self .assertTrue (self .llo_handler ._is_llo_attribute ("gen_ai.completion" ))
10584 self .assertTrue (self .llo_handler ._is_llo_attribute ("gen_ai.content.revised_prompt" ))
106- >> >> >> > 770 f906 (add custom batch export )
10785
10886 def test_is_llo_attribute_openinference_match (self ):
10987 """
@@ -318,107 +296,6 @@ def test_extract_traceloop_events(self):
318296 self .assertEqual (output_event .timestamp , 1234567899 ) # end_time
319297
320298 def test_extract_openlit_direct_prompt (self ):
321- < << << << HEAD
322- """
323- Test _extract_openlit_span_event_attributes with direct prompt attribute
324- """
325- attributes = {
326- "gen_ai.prompt" : "user direct prompt" ,
327- "gen_ai.system" : "openlit"
328- }
329-
330- span = self ._create_mock_span (attributes )
331-
332- events = self .llo_handler ._extract_openlit_span_event_attributes (span , attributes )
333-
334- self .assertEqual (len (events ), 1 )
335- event = events [0 ]
336- self .assertEqual (event .name , "gen_ai.user.message" )
337- self .assertEqual (event .body ["content" ], "user direct prompt" )
338- self .assertEqual (event .body ["role" ], "user" )
339- self .assertEqual (event .attributes ["gen_ai.system" ], "openlit" )
340- self .assertEqual (event .attributes ["original_attribute" ], "gen_ai.prompt" )
341- self .assertEqual (event .timestamp , 1234567890 ) # start_time
342-
343- def test_extract_openlit_direct_completion (self ):
344- """
345- Test _extract_openlit_span_event_attributes with direct completion attribute
346- """
347- attributes = {
348- "gen_ai.completion" : "assistant direct completion" ,
349- "gen_ai.system" : "openlit"
350- }
351-
352- span = self ._create_mock_span (attributes )
353- span .end_time = 1234567899
354-
355- events = self .llo_handler ._extract_openlit_span_event_attributes (span , attributes )
356-
357- self .assertEqual (len (events ), 1 )
358- event = events [0 ]
359- self .assertEqual (event .name , "gen_ai.assistant.message" )
360- self .assertEqual (event .body ["content" ], "assistant direct completion" )
361- self .assertEqual (event .body ["role" ], "assistant" )
362- self .assertEqual (event .attributes ["gen_ai.system" ], "openlit" )
363- self .assertEqual (event .attributes ["original_attribute" ], "gen_ai.completion" )
364- self .assertEqual (event .timestamp , 1234567899 ) # end_time
365-
366- def test_extract_openlit_all_attributes (self ):
367- """
368- Test _extract_openlit_span_event_attributes with all OpenLit attributes
369- """
370- attributes = {
371- "gen_ai.prompt" : "user prompt" ,
372- "gen_ai.completion" : "assistant response" ,
373- "gen_ai.content.revised_prompt" : "revised prompt" ,
374- "gen_ai.system" : "langchain"
375- }
376-
377- span = self ._create_mock_span (attributes )
378- span .end_time = 1234567899
379-
380- events = self .llo_handler ._extract_openlit_span_event_attributes (span , attributes )
381-
382- self .assertEqual (len (events ), 3 )
383-
384- # Check that all events have the correct system
385- for event in events :
386- self .assertEqual (event .attributes ["gen_ai.system" ], "langchain" )
387-
388- # Check we have the expected event types
389- event_types = {event .name for event in events }
390- self .assertIn ("gen_ai.user.message" , event_types )
391- self .assertIn ("gen_ai.assistant.message" , event_types )
392- self .assertIn ("gen_ai.system.message" , event_types )
393-
394- # Check original attributes
395- original_attrs = {event .attributes ["original_attribute" ] for event in events }
396- self .assertIn ("gen_ai.prompt" , original_attrs )
397- self .assertIn ("gen_ai.completion" , original_attrs )
398- self .assertIn ("gen_ai.content.revised_prompt" , original_attrs )
399-
400- def test_extract_openlit_revised_prompt (self ):
401- """
402- Test _extract_openlit_span_event_attributes with revised prompt attribute
403- """
404- attributes = {
405- "gen_ai.content.revised_prompt" : "revised system prompt" ,
406- "gen_ai.system" : "openlit"
407- }
408-
409- span = self ._create_mock_span (attributes )
410-
411- events = self .llo_handler ._extract_openlit_span_event_attributes (span , attributes )
412-
413- self .assertEqual (len (events ), 1 )
414- event = events [0 ]
415- self .assertEqual (event .name , "gen_ai.system.message" )
416- self .assertEqual (event .body ["content" ], "revised system prompt" )
417- self .assertEqual (event .body ["role" ], "system" )
418- self .assertEqual (event .attributes ["gen_ai.system" ], "openlit" )
419- self .assertEqual (event .attributes ["original_attribute" ], "gen_ai.content.revised_prompt" )
420- self .assertEqual (event .timestamp , 1234567890 ) # start_time
421- == == == =
422299 """
423300 Test _extract_openlit_span_event_attributes with direct prompt attribute
424301 """
@@ -509,7 +386,6 @@ def test_extract_openlit_revised_prompt(self):
509386 self .assertEqual (event .attributes ["gen_ai.system" ], "openlit" )
510387 self .assertEqual (event .attributes ["original_attribute" ], "gen_ai.content.revised_prompt" )
511388 self .assertEqual (event .timestamp , 1234567890 ) # start_time
512- >> >> >> > 770 f906 (add custom batch export )
513389
514390 def test_extract_openinference_direct_attributes (self ):
515391 """
0 commit comments