Skip to content
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

python: Add metadata to log() #232

Merged
merged 4 commits into from
Feb 24, 2025
Merged

python: Add metadata to log() #232

merged 4 commits into from
Feb 24, 2025

Conversation

amacneil
Copy link
Contributor

@amacneil amacneil commented Feb 21, 2025

Changelog

None

Docs

None

Description

  • Allow custom timestamps in python:
chan = fg.Channel(topic="/aranet", schema=schema)
chan.log(msg, log_time=123, publish_time=456, sequence=42)

@amacneil amacneil requested review from eloff and bryfox February 21, 2025 23:11
@amacneil amacneil marked this pull request as ready for review February 21, 2025 23:11
Comment on lines +77 to +79
log_time: Optional[int] = None,
publish_time: Optional[int] = None,
sequence: Optional[int] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

For typed channels, we have log(bytes) and log_with_meta(bytes, PartialMetadata). We should be consistent.

FWIW, I prefer the style in this PR, or passing in metadata as optional kwargs. We could get rid of PartialMetadata from the python API.

Copy link
Contributor

Choose a reason for hiding this comment

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

#234

We can either merge it into your branch, or merge it to main separately, or even discard it, as folks prefer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Passing a metadata struct works in Rust, because it's a zero-cost abstraction. In Python it's clunky and it involves an allocation.

This is built on top of @amacneil's #232, and we can either merge it
into that PR branch, or merge it to main separately.

The idea is to make typed channels consistent with raw channels by
removing `log_with_meta` and adding keyword-only arguments to `log` for
timestamps and sequence.

Fixes: FG-10468
@amacneil amacneil changed the title python: allow timestamps on custom channels python: Use kwargs for log() metadata Feb 24, 2025
@amacneil amacneil changed the title python: Use kwargs for log() metadata python: Add metadata args to log() Feb 24, 2025
@amacneil amacneil requested a review from gasmith February 24, 2025 17:42
Copy link
Contributor

@gasmith gasmith left a comment

Choose a reason for hiding this comment

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

🚢

@amacneil amacneil changed the title python: Add metadata args to log() python: Add metadata to log() Feb 24, 2025
@amacneil amacneil merged commit 8bc304b into main Feb 24, 2025
28 checks passed
@amacneil amacneil deleted the adrian/log-timestamps branch February 24, 2025 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants