|
27 | 27 | ) |
28 | 28 | from ..converter import convert_traces |
29 | 29 | from ..extraction import get_extractor |
| 30 | +from ..loader import load_traces |
30 | 31 | from ..loader.otlp import OtlpJsonLoader |
31 | 32 | from ..runner import ( |
32 | 33 | RunResult, |
33 | | - get_loader, |
34 | 34 | load_eval_set, |
35 | 35 | load_eval_set_from_dict, |
36 | 36 | run_evaluation, |
@@ -331,17 +331,10 @@ def _serialize_invocation(inv) -> dict[str, Any]: |
331 | 331 | return _camel_keys(inv_dict) |
332 | 332 |
|
333 | 333 |
|
334 | | -def _get_format_for_file(path: str, explicit_format: str) -> str: |
335 | | - """Return the loader format for a single file, auto-detecting from extension.""" |
336 | | - if explicit_format: |
337 | | - return explicit_format |
338 | | - return "otlp-json" if path.lower().endswith(".jsonl") else "jaeger-json" |
339 | | - |
340 | | - |
341 | 334 | @router.post("/convert", response_model=StandardResponse[ConvertTracesData]) |
342 | 335 | async def convert_trace_files( |
343 | 336 | trace_files: list[UploadFile] = File(...), |
344 | | - trace_format: str = Form(""), |
| 337 | + trace_format: str | None = Form(None), |
345 | 338 | ): |
346 | 339 | """Convert trace files to invocations and metadata without running evaluation.""" |
347 | 340 | temp_dir = tempfile.mkdtemp() |
@@ -380,10 +373,8 @@ async def convert_trace_files( |
380 | 373 | trace_to_filename: dict[str, str] = {} |
381 | 374 | load_warnings: list[str] = [] |
382 | 375 | for path, original in saved_files: |
383 | | - fmt = _get_format_for_file(path, trace_format) |
384 | | - loader = get_loader(fmt) |
385 | 376 | try: |
386 | | - traces = loader.load(path) |
| 377 | + traces = load_traces(path, format=trace_format or None) |
387 | 378 | for t in traces: |
388 | 379 | trace_to_filename[t.trace_id] = original |
389 | 380 | all_traces.extend(traces) |
@@ -496,12 +487,6 @@ async def evaluate_traces( |
496 | 487 | ) |
497 | 488 |
|
498 | 489 | trace_format = config_dict.get("trace_format") |
499 | | - if not trace_format: |
500 | | - first_file = trace_paths[0] |
501 | | - if first_file.endswith(".jsonl"): |
502 | | - trace_format = "otlp-json" |
503 | | - else: |
504 | | - trace_format = "jaeger-json" |
505 | 490 |
|
506 | 491 | eval_set_path = None |
507 | 492 | if eval_set_file and eval_set_file.filename: |
@@ -612,12 +597,6 @@ async def event_generator(): |
612 | 597 | return |
613 | 598 |
|
614 | 599 | trace_format = config_dict.get("trace_format") |
615 | | - if not trace_format: |
616 | | - first_file = trace_paths[0] |
617 | | - if first_file.endswith(".jsonl"): |
618 | | - trace_format = "otlp-json" |
619 | | - else: |
620 | | - trace_format = "jaeger-json" |
621 | 600 |
|
622 | 601 | eval_set_path = None |
623 | 602 | if eval_set_file and eval_set_file.filename: |
@@ -663,10 +642,9 @@ async def event_generator(): |
663 | 642 | trajectory_match_type=config_dict.get("trajectoryMatchType"), |
664 | 643 | ) |
665 | 644 |
|
666 | | - loader = get_loader(eval_config.trace_format) |
667 | 645 | for trace_file_path in trace_paths: |
668 | 646 | try: |
669 | | - traces = loader.load(trace_file_path) |
| 647 | + traces = load_traces(trace_file_path, format=eval_config.trace_format) |
670 | 648 | for trace in traces: |
671 | 649 | extractor = get_extractor(trace) |
672 | 650 | perf_metrics = _camel_keys(extract_performance_metrics(trace, extractor)) |
|
0 commit comments