Skip to content

Commit

Permalink
feat: add file tracer file convertion to new format
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianSchepersAA authored and SebastianNiehusAA committed Jun 4, 2024
1 parent 026bb22 commit f49ac12
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
- All models raise an error during initialization if an incompatible `name` is passed, instead of only when they are used.
- Add `aggregation_overviews_to_pandas` function to allow for easier comparison of multiple aggregation overviews
- Add `parameter_optimization.ipynb` notebook to demonstrate the optimization of tasks by comparing different parameter combinations.
- Add `convert_file_for_viewing` in the `FileTracer` to convert the trace file format to the new (OpenTelemetry style) format and save as a new file.
- All tracers can now call `submit_to_trace_viewer` to send the trace to the Trace Viewer.

### Fixes
- The document index client now correctly URL-encodes document names in its queries.
Expand Down
8 changes: 8 additions & 0 deletions src/intelligence_layer/core/tracer/file_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ def traces(self, trace_id: Optional[str] = None) -> InMemoryTracer:
)
return self._parse_log(filtered_traces)

def convert_file_for_viewing(self, file_path: Path | str) -> None:
in_memory_tracer = self.traces()
traces = in_memory_tracer.export_for_viewing()
path_to_file = Path(file_path)
with path_to_file.open(mode="w", encoding="utf-8") as file:
for exportedSpan in traces:
file.write(exportedSpan.model_dump_json() + "\n")


class FileSpan(PersistentSpan, FileTracer):
"""A `Span` created by `FileTracer.span`."""
Expand Down
4 changes: 3 additions & 1 deletion src/intelligence_layer/core/tracer/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ def submit_to_trace_viewer(self) -> bool:
"Content-Type": "application/json",
"Accept": "application/json",
},
json=ExportedSpanList(self.export_for_viewing()).model_dump(mode="json"),
json=ExportedSpanList(self.export_for_viewing()).model_dump(
mode="json"
),
)
print(res)
if res.status_code != 200:
Expand Down

0 comments on commit f49ac12

Please sign in to comment.