fix(dart): Route SDK diagnostic logs to browser console on web#3698
Open
theprantadutta wants to merge 1 commit into
Open
fix(dart): Route SDK diagnostic logs to browser console on web#3698theprantadutta wants to merge 1 commit into
theprantadutta wants to merge 1 commit into
Conversation
`SentryInternalLogger`'s default output uses `dart:developer.log`, which does not surface in the browser dev console on Flutter Web — SDK diagnostic messages (gated by `options.debug = true`) were silently dropped during web development. Split the default log output into platform-specific implementations selected via the existing `_io_*` / `_web_*` companion-file pattern already used in `packages/dart/lib/src/`: - `_io_default_log_output.dart` keeps the existing `dart:developer.log` behaviour for the VM, so DevTools and IDE log views are unchanged. - `_web_default_log_output.dart` forwards to `window.console.*` via `package:web` (`console.error` for fatal/error, `console.warn` for warning, `console.info` for info, `console.debug` for debug). `console.*` is preferred over `print` for two reasons: 1. `print` on Flutter Web routes through `dart:html`'s `consoleLog` indirectly; the SDK already installs a `ZoneSpecification(print:)` hook that records every `print` call as a `Breadcrumb`. Routing our own internal diagnostic output through `print` would feed those internal lines back as user-visible breadcrumbs. Calling `console.*` directly bypasses that hook entirely. 2. Mapping `SentryLevel` to the matching `console` method gives the browser dev console an opportunity to highlight warnings/errors visually rather than rendering everything as plain log lines. The SDK's internal logger is also short-circuited by `RuntimeChecker.kDebugMode` in release builds, so the new code is tree-shaken from production regardless of platform. Closes getsentry#3043
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3698 +/- ##
=======================================
Coverage 86.96% 86.96%
=======================================
Files 335 336 +1
Lines 11976 11978 +2
=======================================
+ Hits 10415 10417 +2
Misses 1561 1561
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Contributor
|
I'll rerun some of the tests later, seems like CI is acting up |
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
Splits the default output for
SentryInternalLoggerinto platform-specific implementations selected via the existing_io_*/_web_*companion-file pattern (already used by_io_platform.dart/_web_platform.dart,origin_io.dart/origin_web.dart,dart_exception_type_identifier_io.dart/_web.dart, etc.):_io_default_log_output.dartkeeps the existingdart:developer.logbehaviour on the VM, so DevTools and IDE log views are unchanged._web_default_log_output.dartforwards towindow.console.*viapackage:web, mappingSentryLevelto the matching console method:SentryLevelconsole.*fatal/errorconsole.errorwarningconsole.warninfoconsole.infodebugconsole.debug💡 Motivation and Context
dart:developer.logdoes not surface in the browser dev console on Flutter Web, so SDK diagnostic messages (the ones gated byoptions.debug = true) were silently dropped during web development.I deliberately used
package:webconsole.*instead ofprint, to address @buenaflor's concern from the issue thread:Sentry's print-breadcrumb integration installs a
ZoneSpecification(print:)hook insiderunZonedGuardedand records everyprintcall as aBreadcrumb. If the SDK's own internal diagnostic logger went throughprint, every internal line would feed back as a user-visible breadcrumb on captured events. Callingconsole.*directly bypasses that hook entirely.Additionally,
RuntimeChecker.kDebugModealready short-circuits the logger at the top of_log(), so the whole code path is tree-shaken from release builds regardless of platform — providing a second layer of safety against the breadcrumb-feedback scenario even if a future integration changes howprintis intercepted.Closes #3043
💚 How did you test it?
packages/dart/test/utils/default_log_output_test.dartwith two tests for the IO path: (a) it never produces output viaprint(so the same property holds for the web path, which usesconsole.*); (b) it accepts allSentryLevels without throwing.internal_logger_test.dartthat verifies the conditional import resolves to the IO file on the VM (noprintoutput when logging through the publicSentryInternalLogger).dart compile js -o build/main.dart.js web/main.dartinpackages/dart/example_web/succeeds with the new conditional import in place.internal_logger_test.darttests still pass.dart analyze --fatal-warningsonpackages/dart/— clean.The web
console.*behaviour itself is not unit-tested on the VM (the web file can't be exercised there); theexample_webcompile path provides the static-typecheck guarantee, and a Flutter Web app withoptions.debug = truewould surface the diagnostic logs at the appropriate severity in the dev console.📝 Checklist
sendDefaultPiiis enabled