feat: add context deadline awareness with automatic timeout warnings (#48)#62
Merged
willibrandon merged 5 commits intomainfrom Aug 23, 2025
Merged
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.
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
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.
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