Skip to content

bug(experimenter): make glean writes to stdout more atomic#13905

Merged
relud merged 1 commit intomainfrom
relud-experimenter-glean-stdout
Nov 5, 2025
Merged

bug(experimenter): make glean writes to stdout more atomic#13905
relud merged 1 commit intomainfrom
relud-experimenter-glean-stdout

Conversation

@relud
Copy link
Contributor

@relud relud commented Nov 4, 2025

Because

  • In prod glean pings are coming out as {ping}{ping}\n\n instead of {ping}\n{ping}\n and markh suggested this might fix it

This commit

  • Overrides the glean generated emit_record methods to use stdout.write(f"{ping}\n") instead of print(ping)

Fixes #13893

@relud
Copy link
Contributor Author

relud commented Nov 4, 2025

if this works, we should move the change upstream to glean-parser, and revert it here when we pick up the change

@relud relud force-pushed the relud-experimenter-glean-stdout branch from 55eeeba to 265d2b2 Compare November 4, 2025 22:37
Comment on lines +17 to +25
def emit_record(now: datetime, ping: dict[str, Any]):
ping_envelope = {
"Timestamp": now.isoformat(),
"Logger": "glean",
"Type": GLEAN_EVENT_MOZLOG_TYPE,
"Fields": ping,
}
ping_envelope_serialized = f"{json.dumps(ping_envelope)}\n"
stdout.write(ping_envelope_serialized)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the original method is:

 def emit_record(self, now: datetime, ping:dict[str, Any]) -> None:
        """Log the ping to STDOUT.
        Applications might want to override this method to use their own logging.
        If doing so, make sure to log the ping as JSON, and to include the
        `Type: GLEAN_EVENT_MOZLOG_TYPE`."""
        ping_envelope = {
            "Timestamp": now.isoformat(),
            "Logger": "glean",
            "Type": GLEAN_EVENT_MOZLOG_TYPE,
            "Fields": ping,
        }
        ping_envelope_serialized = json.dumps(ping_envelope)

        print(ping_envelope_serialized)

Copy link
Contributor

@yashikakhurana yashikakhurana left a comment

Choose a reason for hiding this comment

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

Thanks @relud

@relud relud force-pushed the relud-experimenter-glean-stdout branch from 265d2b2 to 4ada34e Compare November 5, 2025 00:19
@relud relud force-pushed the relud-experimenter-glean-stdout branch from 4ada34e to 3a56370 Compare November 5, 2025 00:21
@relud relud enabled auto-merge November 5, 2025 00:24
@relud relud added this pull request to the merge queue Nov 5, 2025
Merged via the queue into main with commit e1c204a Nov 5, 2025
17 checks passed
@relud relud deleted the relud-experimenter-glean-stdout branch November 5, 2025 01:07
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.

server-side glean pings aren't being delivered

2 participants