@@ -823,7 +823,7 @@ class StrSubclass(str):
823823 pytest .param (
824824 [{str : bytes , int : float }],
825825 "[{<class 'str'>: <class 'bytes'>, <class 'int'>: <class 'float'>}]" ,
826- '[{"<class \' str\' >":"<class \' bytes\' >","<class \' int\' >":"<class ' "' float'> \ " }]" ,
826+ '[{"<class \' str\' >":"<class \' bytes\' >","<class \' int\' >":"<class \' float\' > "}]' ,
827827 {
828828 'items' : {
829829 'properties' : {
@@ -1235,3 +1235,83 @@ class Model:
12351235 }
12361236 ]
12371237 )
1238+
1239+
1240+ def test_numpy_array_truncation (exporter : TestExporter ):
1241+ logfire .info ('hi' , m = numpy .arange (13 * 3 * 11 ).reshape (13 , 3 , 11 ))
1242+
1243+ truncated = [
1244+ [
1245+ [0 , 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 ],
1246+ [11 , 12 , 13 , 14 , 15 , 17 , 18 , 19 , 20 , 21 ],
1247+ [22 , 23 , 24 , 25 , 26 , 28 , 29 , 30 , 31 , 32 ],
1248+ ],
1249+ [
1250+ [33 , 34 , 35 , 36 , 37 , 39 , 40 , 41 , 42 , 43 ],
1251+ [44 , 45 , 46 , 47 , 48 , 50 , 51 , 52 , 53 , 54 ],
1252+ [55 , 56 , 57 , 58 , 59 , 61 , 62 , 63 , 64 , 65 ],
1253+ ],
1254+ [
1255+ [66 , 67 , 68 , 69 , 70 , 72 , 73 , 74 , 75 , 76 ],
1256+ [77 , 78 , 79 , 80 , 81 , 83 , 84 , 85 , 86 , 87 ],
1257+ [88 , 89 , 90 , 91 , 92 , 94 , 95 , 96 , 97 , 98 ],
1258+ ],
1259+ [
1260+ [99 , 100 , 101 , 102 , 103 , 105 , 106 , 107 , 108 , 109 ],
1261+ [110 , 111 , 112 , 113 , 114 , 116 , 117 , 118 , 119 , 120 ],
1262+ [121 , 122 , 123 , 124 , 125 , 127 , 128 , 129 , 130 , 131 ],
1263+ ],
1264+ [
1265+ [132 , 133 , 134 , 135 , 136 , 138 , 139 , 140 , 141 , 142 ],
1266+ [143 , 144 , 145 , 146 , 147 , 149 , 150 , 151 , 152 , 153 ],
1267+ [154 , 155 , 156 , 157 , 158 , 160 , 161 , 162 , 163 , 164 ],
1268+ ],
1269+ [
1270+ [264 , 265 , 266 , 267 , 268 , 270 , 271 , 272 , 273 , 274 ],
1271+ [275 , 276 , 277 , 278 , 279 , 281 , 282 , 283 , 284 , 285 ],
1272+ [286 , 287 , 288 , 289 , 290 , 292 , 293 , 294 , 295 , 296 ],
1273+ ],
1274+ [
1275+ [297 , 298 , 299 , 300 , 301 , 303 , 304 , 305 , 306 , 307 ],
1276+ [308 , 309 , 310 , 311 , 312 , 314 , 315 , 316 , 317 , 318 ],
1277+ [319 , 320 , 321 , 322 , 323 , 325 , 326 , 327 , 328 , 329 ],
1278+ ],
1279+ [
1280+ [330 , 331 , 332 , 333 , 334 , 336 , 337 , 338 , 339 , 340 ],
1281+ [341 , 342 , 343 , 344 , 345 , 347 , 348 , 349 , 350 , 351 ],
1282+ [352 , 353 , 354 , 355 , 356 , 358 , 359 , 360 , 361 , 362 ],
1283+ ],
1284+ [
1285+ [363 , 364 , 365 , 366 , 367 , 369 , 370 , 371 , 372 , 373 ],
1286+ [374 , 375 , 376 , 377 , 378 , 380 , 381 , 382 , 383 , 384 ],
1287+ [385 , 386 , 387 , 388 , 389 , 391 , 392 , 393 , 394 , 395 ],
1288+ ],
1289+ [
1290+ [396 , 397 , 398 , 399 , 400 , 402 , 403 , 404 , 405 , 406 ],
1291+ [407 , 408 , 409 , 410 , 411 , 413 , 414 , 415 , 416 , 417 ],
1292+ [418 , 419 , 420 , 421 , 422 , 424 , 425 , 426 , 427 , 428 ],
1293+ ],
1294+ ]
1295+ assert numpy .array (truncated ).shape == (10 , 3 , 10 )
1296+ assert exporter .exported_spans_as_dict () == snapshot (
1297+ [
1298+ {
1299+ 'name' : 'hi' ,
1300+ 'context' : {'trace_id' : 1 , 'span_id' : 1 , 'is_remote' : False },
1301+ 'parent' : None ,
1302+ 'start_time' : 1000000000 ,
1303+ 'end_time' : 1000000000 ,
1304+ 'attributes' : {
1305+ 'logfire.span_type' : 'log' ,
1306+ 'logfire.level_num' : 9 ,
1307+ 'logfire.msg_template' : 'hi' ,
1308+ 'logfire.msg' : 'hi' ,
1309+ 'code.filepath' : 'test_json_args.py' ,
1310+ 'code.function' : 'test_numpy_array_truncation' ,
1311+ 'code.lineno' : 123 ,
1312+ 'm' : IsJson (truncated ),
1313+ 'logfire.json_schema' : '{"type":"object","properties":{"m":{"type":"array","x-python-datatype":"ndarray","x-shape":[13,3,11],"x-dtype":"int64"}}}' ,
1314+ },
1315+ }
1316+ ]
1317+ )
0 commit comments