-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add context deadline awareness with automatic timeout warnings (#48) #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…48) - Add automatic warnings when operations approach context deadlines - Implement zero-overhead deadline detection (2.7ns, 0 allocations when no deadline) - Add context-aware logging methods (InfoContext, ErrorContext, etc.) - Add separate LRU set for first warning tracking to ensure semantic correctness - Add WithDeadlineWarning() method to Logger interface for derived logger configuration - Add WithDeadlinePercentageOnly() for cleaner percentage-based thresholds - Expose deadline statistics via DeadlineStats() for production observability - Add comprehensive documentation with troubleshooting and SLA configuration guides - Add examples for metrics integration and common context patterns - Fix memory leak by properly tracking first warnings in bounded LRU set
- Add DeadlineStats() and WithDeadlineWarning() to mock loggers in otel adapter tests - Add context-aware methods (VerboseContext, DebugContext, etc.) to all test mocks - Update noOpLogger in middleware adapter to implement complete Logger interface - Fix build failures in adapters/otel and adapters/middleware test suites
- Remove unused clear() methods from deadline cache and first warning set - Remove unused hasWarned() method from first warning set - Remove unused hasDeadlineAwareness() method from logger - Fix empty else branch warning in deadline enricher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements automatic context deadline awareness feature that detects and warns when operations approach their context deadlines. The feature provides zero-overhead deadline tracking with configurable thresholds and comprehensive metrics integration.
- Adds context-aware logging methods (
InfoContext,ErrorContext, etc.) to all logging interfaces - Implements deadline detection with both absolute and percentage-based thresholds
- Adds comprehensive caching system with LRU eviction and TTL support for efficient deadline tracking
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| options.go | Adds deadline enricher configuration options and integration with logger pipeline |
| logger.go | Implements context-aware logging methods and deadline enricher integration |
| internal/enrichers/deadline.go | Core deadline detection logic with configurable thresholds and custom handlers |
| internal/enrichers/deadline_cache.go | Sharded LRU cache implementation for efficient deadline context tracking |
| internal/enrichers/first_warning_set.go | Bounded set for tracking first warnings to prevent duplicate alerts |
| core/logger.go | Extends Logger interface with context-aware methods and deadline statistics |
| examples/deadline-awareness/main.go | Comprehensive examples demonstrating deadline awareness usage patterns |
| integration/deadline_integration_test.go | Integration tests for concurrent contexts and real-world scenarios |
| docs/ | Documentation updates including quick reference and context guide |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- Replace magic string "__context__" with internalContextKey constant - Replace unsafe.Pointer sharding with safe hash-based approach using FNV-1a
Description
Implements automatic detection and warning when operations approach context deadlines, helping developers catch timeout-related issues before they fail in production. The feature provides zero-overhead deadline tracking (2.7ns, 0 allocations when no deadline present) with configurable absolute and percentage-based thresholds.
Type of change
Checklist
go test ./...)golangci-lint run)Additional notes
deadline.remaining_ms,deadline.at,deadline.approachingFixes #48