Skip to content

feat(core): v0.2.0 ergonomics release#3

Merged
seanbrar merged 5 commits intomainfrom
dev
Feb 5, 2026
Merged

feat(core): v0.2.0 ergonomics release#3
seanbrar merged 5 commits intomainfrom
dev

Conversation

@seanbrar
Copy link
Owner

@seanbrar seanbrar commented Feb 5, 2026

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

  • The _Scope optimization initially set context vars in init; corrected to enter to maintain context
    manager contract. Benchmarks confirm no performance impact from the fix.
  • Performance benchmarks added (moved from v0.4.0 roadmap) to validate the _Scope optimization.
  • uv.lock now tracked for reproducible CI.

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, plus flush()/shutdown() lifecycle forwarding to reporters (no-op implementations included for the built-in SimpleReporter).

Core timing logic is refactored from @contextmanager to an explicit _Scope context manager and tightens validation/error messaging for scope names and reporter shape (early TelemetryContext(...) 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 to 0.2.0, and begins tracking uv.lock for reproducible environments.

Written by Cursor Bugbot for commit cbb0a35. This will update automatically on new commits. Configure here.

seanbrar and others added 3 commits February 4, 2026 22:43
… 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.
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sean Brar 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).
@seanbrar seanbrar merged commit 3a4dd36 into main Feb 5, 2026
6 checks passed
@seanbrar seanbrar deleted the dev branch February 5, 2026 15:53
@seanbrar seanbrar restored the dev branch February 5, 2026 16:17
@seanbrar seanbrar deleted the dev branch February 5, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant