44import decimal
55import enum
66import io
7+ import json
8+ import re
79import sys
810from datetime import datetime
911from typing import Any
1719from opentelemetry ._logs import SeverityNumber , get_logger
1820from opentelemetry .sdk ._logs import LogRecord
1921from opentelemetry .sdk .trace import ReadableSpan
22+ from opentelemetry .trace import get_tracer
2023from opentelemetry .version import __version__ as otel_version
2124
2225import logfire
@@ -993,6 +996,7 @@ class MyIntEnum(int, enum.Enum):
993996 e = MyEnum .ABC ,
994997 se = MyStrEnum .STR ,
995998 ie = MyIntEnum .INT ,
999+ rp = re .compile (r'^[\w\.-]+@[\w\.-]+\.\w+$' ),
9961000 )
9971001
9981002 assert capsys .readouterr ().out .splitlines () == snapshot (
@@ -1005,5 +1009,39 @@ class MyIntEnum(int, enum.Enum):
10051009 "│ e=MyEnum('abc')" ,
10061010 "│ se=MyStrEnum('str_val')" ,
10071011 '│ ie=MyIntEnum(1)' ,
1012+ '│ rp=^[\\ w\\ .-]+@[\\ w\\ .-]+\\ .\\ w+$' ,
1013+ ]
1014+ )
1015+
1016+
1017+ def test_console_exporter_list_data_with_object_schema_mismatch (capsys : pytest .CaptureFixture [str ]) -> None :
1018+ logfire .configure (
1019+ send_to_logfire = False ,
1020+ console = ConsoleOptions (verbose = True , colors = 'never' , include_timestamps = False ),
1021+ )
1022+
1023+ get_tracer (__name__ ).start_span (
1024+ 'test_span' ,
1025+ attributes = {
1026+ 'foo' : json .dumps (['item1' , 'item2' , 'item3' ]),
1027+ 'bar' : json .dumps ({'name' : 'Alice' , 'age' : 30 }),
1028+ 'logfire.json_schema' : json .dumps (
1029+ {
1030+ 'type' : 'object' ,
1031+ 'properties' : {
1032+ # These are wrong
1033+ 'foo' : {'type' : 'object' },
1034+ 'bar' : {'type' : 'array' },
1035+ },
1036+ }
1037+ ),
1038+ },
1039+ ).end ()
1040+
1041+ assert capsys .readouterr ().out .splitlines () == snapshot (
1042+ [
1043+ 'test_span' ,
1044+ "│ foo=['item1', 'item2', 'item3']" ,
1045+ "│ bar={'name': 'Alice', 'age': 30}" ,
10081046 ]
10091047 )
0 commit comments