Skip to content

Bug 2041186, bug 2058322 - replace mozlog with stdlib logging and MozLogFormatter - #174

Open
jcristau wants to merge 2 commits into
mozilla-conduit:mainfrom
jcristau:bug2041186-stdlib-logging
Open

jcristau wants to merge 2 commits into
mozilla-conduit:mainfrom
jcristau:bug2041186-stdlib-logging

Conversation

@jcristau

Copy link
Copy Markdown
Contributor

No description provided.

mozlog's StructuredLogger bypasses the stdlib logging module. Switch to
plain `logging` loggers, formatted as mozlog JSON on stdout by a
MozLogFormatter adapted from Lando.

Loggers are now named after their module (`git_hg_sync.*`), and the name
is reported in the `source`/`Type` fields; previously `source` was
always "service" and the per-module name was in `component`.

The mozlog command line options are replaced by a single `--log-level`.
…t captures

Now that we log through the stdlib logging module, sentry's default
LoggingIntegration turns ERROR records into events, so most explicit
capture_exception calls are redundant:

- repo_synchronizer: the wrapping RepoSyncError was already reported
  again by Application.
- cli: sentry is never initialised in git-hg-cli, so this was a no-op.
- retry: every failed attempt was reported, even when a later one
  succeeded or the caller handled the error. The final failure is now
  logged as a warning (with traceback); callers report it if fatal.
- application: log the sync failure with logger.exception, so it becomes
  the single sentry event for a failed push, carrying the destination
  and operations.

Also downgrade pulse connection errors to a warning: kombu retries them,
and they'd otherwise create one sentry event per reconnection attempt.
@jcristau
jcristau marked this pull request as ready for review October 15, 2026 16:51
@jcristau
jcristau requested a review from a team as a code owner October 15, 2026 16:51
@shtrom shtrom changed the title Bug 2041186 - replace mozlog with stdlib logging and MozLogFormatter Bug 2041186, bug 2058322 - replace mozlog with stdlib logging and MozLogFormatter Oct 16, 2026

@shtrom shtrom left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just blocking to confirm the source commit from the lando import for log.py.

In the meantime, I'll push it to dev to see how it goes.

Comment thread git_hg_sync/retry.py
sentry_sdk.capture_exception(exc)
action_text = f" {action}" if action else ""
if attempt < tries:
logger.warning(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.warning(
logger.info(

Comment thread git_hg_sync/log.py
if TYPE_CHECKING:
import argparse

# Adapted from Lando's lando/main/logging.py.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth noting the actual SHA of the commit you got it from.

Comment thread git_hg_sync/cli.py

args = parser.parse_args()
logger = commandline.setup_logging("service", args)
setup_logging(args.log_level)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I don't think we want the MozLog format for the CLI, because that's used manually, and JSON is harder to parse with one's eyes.

Suggested change
setup_logging(args.log_level)
logging.basicConfig(args.log_level.upper())

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants