@@ -299,6 +299,24 @@ def observed_foo(x):
299
299
assert json .loads (spans [0 ].attributes ["lmnr.span.input" ]) == {"x" : 2 }
300
300
301
301
302
+ def test_observe_input_formatter_exception (exporter : InMemorySpanExporter ):
303
+ def input_formatter (x ):
304
+ raise ValueError ("test" )
305
+
306
+ @observe (input_formatter = input_formatter )
307
+ def observed_foo (x ):
308
+ return x
309
+
310
+ result = observed_foo (1 )
311
+ spans = exporter .get_finished_spans ()
312
+ assert result == 1
313
+ assert len (spans ) == 1
314
+ assert spans [0 ].name == "observed_foo"
315
+ assert spans [0 ].attributes ["lmnr.span.instrumentation_source" ] == "python"
316
+ assert spans [0 ].attributes ["lmnr.span.path" ] == ("observed_foo" ,)
317
+ assert "lmnr.span.input" not in spans [0 ].attributes
318
+
319
+
302
320
def test_observe_input_formatter_with_kwargs (exporter : InMemorySpanExporter ):
303
321
def input_formatter (x , ** kwargs ):
304
322
return {"x" : x + 1 , "custom-A" : f"{ kwargs .get ('a' )} --" }
@@ -369,6 +387,21 @@ def observed_foo(x):
369
387
assert json .loads (spans [0 ].attributes ["lmnr.span.output" ]) == {"x" : 2 }
370
388
371
389
390
+ def test_observe_output_formatter_exception (exporter : InMemorySpanExporter ):
391
+ def output_formatter (x ):
392
+ raise ValueError ("test" )
393
+
394
+ @observe (output_formatter = output_formatter )
395
+ def observed_foo (x ):
396
+ return x
397
+
398
+ result = observed_foo (1 )
399
+ spans = exporter .get_finished_spans ()
400
+ assert result == 1
401
+ assert len (spans ) == 1
402
+ assert "lmnr.span.output" not in spans [0 ].attributes
403
+
404
+
372
405
@pytest .mark .asyncio
373
406
async def test_observe_output_formatter_async (exporter : InMemorySpanExporter ):
374
407
def output_formatter (x ):
0 commit comments