Conversation
… handling (#1) ## Summary - Implement full telemetry API with scope timing, metrics (count/gauge), and a `@timed` decorator supporting both sync and async functions - Add early validation for scope names and reporters with explicit error messages - Optimize performance by replacing `@contextmanager` with an explicit `_Scope` class and using an `_identity` function to avoid lambda allocation in no-op decorators ## Notes - The `_Scope` class uses `__slots__` for memory efficiency and avoids the overhead of generator-based context managers - Reporter lifecycle hooks (`flush`, `shutdown`) are optional and fail gracefully if not implemented - Strict scope name validation is gated behind `NULLSCOPE_STRICT=1` to preserve backwards compatibility
## Summary Adds test coverage, performance benchmarks, and documentation for the v0.2.0 ergonomics features (decorators, lifecycle hooks, async safety, strict mode). Core implementation was landed in #1. ## Notes - Performance benchmarks were pulled forward from the v0.4.0 roadmap to v0.2.0—they were needed to validate the `_Scope` class optimization and establish baselines. - `NULLSCOPE_STRICT` is documented only in the README env var table for now; design.md addition deferred unless users request clarification. - `uv.lock` is now tracked for reproducible CI.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
added 2 commits
February 5, 2026 01:59
…Scope The v0.2.0 optimization inadvertently moved ContextVar mutations to _Scope.__init__, violating the context manager contract. If a scope was created but never entered (e.g., conditional entry), context vars would be corrupted indefinitely, causing incorrect parent_scope/depth metadata. Relocate _scope_stack_var.set() and _call_count_var.set() to __enter__ where side effects belong. No measured performance impact (~1.5% within run-to-run variance).
…ype hints and assertions.
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
Adds decorator support (@telemetry.timed), reporter lifecycle hooks (flush/shutdown), strict scope
validation, and async isolation guarantees. Replaces @contextmanager with an explicit _Scope class for
16-29% performance improvements in enabled mode, with proper context manager contract compliance.
Notes
manager contract. Benchmarks confirm no performance impact from the fix.
Note
Medium Risk
Touches core scope entry/exit and validation paths, so subtle behavior/performance regressions are possible despite added benchmarks and expanded test coverage.
Overview
Delivers the v0.2.0 ergonomics release by adding
telemetry.timed()for sync/async function instrumentation, plusflush()/shutdown()lifecycle forwarding to reporters (no-op implementations included for the built-inSimpleReporter).Core timing logic is refactored from
@contextmanagerto an explicit_Scopecontext manager and tightens validation/error messaging for scope names and reporter shape (earlyTelemetryContext(...)validation), alongside minor metric path construction optimizations.Updates documentation to cover decorators, lifecycle, strict scope mode (
NULLSCOPE_STRICT), and async task isolation; adds a benchmark suite (benchmarks/) with baseline results, expands tests (including async isolation + lifecycle + validation), bumps version to0.2.0, and begins trackinguv.lockfor reproducible environments.Written by Cursor Bugbot for commit cbb0a35. This will update automatically on new commits. Configure here.