Conversation
Add exception tracking in scopes, LogReporter for structured logging, fix SimpleReporter rendering bugs (parent scope clobbering, gauge display, as_dict tuple output).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add exception tracking in scopes, a
LogReporterfor structured logging output, and fix threeSimpleReporterrendering bugs: parent scope clobbering in the timings tree, gauges incorrectly displayed as counters, andas_dict()returning tuples instead of dicts.Related issue
None
Test plan
8 new tests in
tests/test_core.pycovering all changes (23 total, all passing):test_report_shows_nested_and_parent_scopes— verifies parent scopes with own data render as stats lines, not just tree headers (the clobbering bug)test_report_shows_structural_headers— verifies intermediate-only nodes (e.g.,a:when onlya.b.crecorded) get visual header linestest_as_dict_returns_dicts_with_named_keys— verifies entries use{"duration": ..., **meta}/{"value": ..., **meta}instead of tuplestest_report_gauge_shows_last_value— verifies gauge metrics displayLast:instead ofTotal:test_exception_metadata_recorded_on_scope_exit— verifieserror,error_type,error_messageare captured and exception propagatestest_exception_metadata_absent_on_success— verifies zero cost on happy path (no error keys in metadata)test_log_reporter_emits_timing_record— verifies log level, message format, andextradict structureBenchmarks show no performance regression — the only hot-path change is a single
if exc_type is not None:branch in_Scope.__exit__, not taken on the happy path.Notes
_build_hierarchy+_format_treereplaced by a single_format_timingsmethod. Sorted scope names naturally put parents before children; structural headers provide visual grouping without the clobbering bug.**metadataalready covers the use case.LogReporterusesnullscope.telemetrylogger (notnullscope) to avoid colliding with the library's internal logger. Default level isDEBUGsince telemetry is high-volume.__qualname__forerror_typeto correctly handle nested classes.make checkpasses