fix: use SLF4J logger in circuit breaker callbacks (fixes missing state-transition logs)#107
Open
fix: use SLF4J logger in circuit breaker callbacks (fixes missing state-transition logs)#107
Conversation
….log Akka Typed's context.log is only safe to call from within the actor's message-processing thread. CircuitBreaker onOpen/onHalfOpen/onClose callbacks fire on a Future dispatcher thread, so context.log accesses the ActorLogger from the wrong thread — resulting in the state-transition log lines never reaching CloudWatch. Replace context.log with the object-level SLF4J logger (already present as `log`), which is thread-safe and callable from any thread. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughUpdated CircuitBreaker event logging callbacks in ElasticSearchClient to use a shared SLF4J Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
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.
Root cause
CircuitBreaker.onOpen/onHalfOpen/onClosecallbacks were logging viacontext.log(Akka Typed'sActorLogger). Those callbacks fire on a Future dispatcher thread — not the actor's message-processing thread. Akka Typed'sActorLoggeris not thread-safe: it's guarded by an internal actor-thread check, and when accessed from outside the actor loop it silently drops the message (or throws anAssertionErrorthat is swallowed by the Future chain).This is why the
ElasticSearchResponseHandlerrejection warning was appearing (logged insidereceiveMessage, safe) while the three state-transition lines fromElasticSearchClientwere never appearing — despite 24k rejections proving the breaker was cycling.Fix
Replace
context.login the three callbacks with the object-levellog(LoggerFactory.getLogger(getClass), already declared at line 37 ofElasticSearchClient). A plain SLF4JLoggeris thread-safe and works correctly from any thread.Verification
After deploying,
aws logs filter-log-events --log-group-name /ecs/api --filter-pattern '"circuit breaker opened"'should return results when the breaker trips.🤖 Generated with Claude Code
Summary
This PR fixes missing circuit breaker state-transition logs in the ElasticSearch client by replacing thread-unsafe Akka actor logging with thread-safe SLF4J logging in circuit breaker callbacks.
Root Cause
The
CircuitBreaker.onOpen(),onClose(), andonHalfOpen()callbacks were using Akka Typed'scontext.log(ActorLogger). Since these callbacks execute on Future dispatcher threads rather than the actor's message-processing thread, and ActorLogger is not thread-safe with built-in actor-thread checks, log messages were silently dropped or errors were swallowed by the Future chain.Changes
Updated three circuit breaker event callbacks in
ElasticSearchClient.scala(lines 142-144) to use the existing object-level SLF4J logger instance instead ofcontext.log:onOpen():.onOpen(() => log.warn(...))onClose():.onClose(() => log.info(...))onHalfOpen():.onHalfOpen(() => log.info(...))The log levels and message strings remain unchanged; only the logging mechanism was swapped. SLF4J's Logger is thread-safe and can be safely called from any thread.
Deployment
This is a standard code change with no operational requirements. It will be deployed through the normal CI/CD pipeline and does not require manual pipeline triggers, ECS redeployment commands, or infrastructure configuration changes.
Verification
After deployment, circuit breaker state transitions should now be visible in logs. CloudWatch Logs filter queries for "circuit breaker opened" will return results when the breaker trips.