You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding a before-call-begins fxevent, to help with troubleshooting (#1267)
# What
Adds a "BeforeRun" fxevent.Event, mirroring "Run" but it is called
_before_ the provided func is called by Dig, rather than after.
This relies on uber-go/dig#431 (released as
v1.19.0).
# Motivation
A recent startup-issue debugging session included logs like this:
```
{"level":"info","ts":1742516783.6106565,"caller":"fxevent/zap.go:51","message":"provided","constructor":"a", ...
...
{"level":"info","ts":1742516783.6106653,"caller":"fxevent/zap.go:51","message":"provided","constructor":"q", ...
...
{"level":"info","ts":1742516783.6106734,"caller":"fxevent/zap.go:51","message":"provided","constructor":"z", ...
...
{"level":"info","ts":1742516784.7998207,"caller":"fxevent/zap.go:51","message":"run","name":"a", ...
{"level":"info","ts":1742516784.7999196,"caller":"fxevent/zap.go:51","message":"run","name":"b", ...
{"level":"info","ts":1742516784.9025834,"caller":"application.go:123", ...
{"level":"info","ts":1742516789.5810778,"caller":"application.go:234", ...
{"level":"info","ts":1742516790.740516,"caller":"application.go:345", ...
# EOF
```
which accurately reflected the logs the app produced: during startup, it
was getting OOM-killed after the final log, several seconds after the
last Fx-"run" event.
Unfortunately, Fx's `Run` event is logged _after_ a call completes, so
the fxevent log immediately before the application-produced logs tells
us _almost nothing_ about what is currently running. That seems... kinda
not ideal. I've run into this quite a few times over the years, but I
finally decided to do something about it.
So I added a "before run" event, so this log will be much easier to
diagnose:
```
{"level":"info","ts":1742516784.7899196,"caller":"fxevent/zap.go:51","message":"before run","name":"b", ...
{"level":"info","ts":1742516784.7999196,"caller":"fxevent/zap.go:51","message":"run","name":"b", ...
{"level":"info","ts":1742516784.8000196,"caller":"fxevent/zap.go:51","message":"before run","name":"c", ...
{"level":"info","ts":1742516784.9025834,"caller":"application.go:123", ...
# ^ clearly logged during "c"
```
After a quick attempt in Fx it became pretty clear that it would be
difficult or almost impossible to do without changing Dig, so this PR
relies on a change to Dig: uber-go/dig#431
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Enhanced the logging system to provide proactive notifications before
key lifecycle events, offering clearer insight into system operations.
- **Tests**
- Modified test cases to validate the improved event logging flow for
greater accuracy in monitoring system behavior.
- **Chores**
- Updated a core dependency to support the new logging enhancements.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Jacob Oaks <joaks@uber.com>
0 commit comments