-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
fix(core): Ensure LoggerProxy
is not scoped
#11379
Conversation
@@ -61,7 +62,7 @@ export class Logger { | |||
/** Create a logger that injects the given scopes into its log metadata. */ | |||
scoped(scopes: LogScope | LogScope[]) { | |||
scopes = Array.isArray(scopes) ? scopes : [scopes]; | |||
const scopedLogger = new Logger(this.globalConfig, this.instanceSettings); | |||
const scopedLogger = new Logger(this.globalConfig, this.instanceSettings, { isRoot: false }); |
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.
do you think it might make sense to move the minimal amount of code needed for scoped loggers to a separate class, instead of reusing this class for two separate purposes?
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.
Interesting, let me try this and report back
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.
Tried this quickly here. The scoped logger relies heavily on the existing logger, so
- if the scoped logger doesn't extend from the existing logger, we'd have to extract quite a bit of deeply integrated logic or duplicate quite a bit, also using a separate scoped logger like this introduces a circular dependency
ReferenceError: Circular dependency: TargetServer. Index: 0
that I haven't spent time debugging yet - if the scoped logger does extend from the existing logger to reuse logic and avoid extracting most of it, then we're back at wanting a way to avoid initializing the proxy on every constructor call, which is what this PR is addressing
Let me know if worth investing more time into this
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.
does the scoped logger also need to use winston to write logs to the file?
also, if you prefer, we can merge this as it is, and I can have a look at splitting this in a separate PR.
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.
does the scoped logger also need to use winston to write logs to the file?
Yes, the scoped logger does everything the existing logger does, with the only addition that it auto-injects the scope string into the metadata of every log it emits, no matter the transport, etc.
also, if you prefer, we can merge this as it is, and I can have a look at splitting this in a separate PR.
Let's do this and revisit. I'd like to fix this minor bug quickly.
n8n Run #7544
Run Properties:
|
Project |
n8n
|
Branch Review |
ensure-logger-proxy-is-not-scoped
|
Run status |
Passed #7544
|
Run duration | 04m 12s |
Commit |
9f83313506: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 ivov 🗃️ e2e/*
|
Committer | Iván Ovejero |
View all properties for this run ↗︎ |
Test results | |
---|---|
Failures |
0
|
Flaky |
0
|
Pending |
0
|
Skipped |
0
|
Passing |
458
|
View all changes introduced in this branch ↗︎ |
✅ All Cypress E2E specs passed |
Got released with |
Currently we initialize a
Logger
singleton shared by most services. More recently, we allowed some services to useLogger.scoped
to instantiate a scoped logger to auto-inject scopes like'waiting-executions'
into the scoped logger's log metadata.In
Logger.constructor
we also initialize aLoggerProxy
for use byworkflow
andcore
packages. SinceLogger.scoped
callsLogger.constructor
we are unintentionally re-initializingLoggerProxy
on everyLogger.scoped
call, which causesLoggerProxy
to end up with the scopes of the lastLogger.scoped
call, e.g.LoggerProxy
incore
in regular mode is currently auto-injecting thewaiting-executions
scope.This PR ensures
LoggerProxy
is only initialized by the rootLogger.constructor
so thatLoggerProxy
does not receive scopes from further constructor calls.