fix(utils): Prevent logger
circular dependencies
#4069
Merged
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.
Multiple times over the years, we've had to rearrange code in
@sentry/utils
in order to not end up with one or more circular dependencies. Often this has been alogger
->misc
->logger
cycle, since each of them contained very low-level code. Having just hit it again, I decided to stop making piecemeal fixes and actually organize things so that it will stop happening once and for all. To do that, I made three changes:getGlobalObject
to its own module.consoleSandbox
into the logger module itself, since that's the only place it's used.logger.ts
's dependencies (not knowing that that's what they are) any function which logs to the console using the logger - I added a warning comment at the top of both dependencies.While I was moving things around, I noticed that when I'd separated out
node.ts
andbrowser.ts
(in order to fix an earlier incarnation of this very same problem), I'd missed movinggetLocationHref
into the browser module, so I did that here, too.