You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(ledger): stamp transaction groups with writer build metadata - #5463
Stamp each new ledger transaction group with the writer's full Git SHA and release version when available. This helps identify the code that booked a group during a rolling deployment. Existing groups retain their original annotations.
The service supplies its embedded revision and version as defaults for metadata.revision and metadata.version. All writers receive the resolved values through common service metadata. The existing telemetry service version and HTTP version endpoint read the same version. Native builds discover the Git revision through Go build info. Packaged binaries also support a revision supplied at build time.
Verification
The E2E test creates a grant over the v3 API, reads its persisted ledger group from PostgreSQL, and compares the version with the running server's version endpoint. Local runs covered a versioned native build, a binary built without Go VCS metadata or a release version, and independent YAML revision and environment version overrides.
Confidence Score: 4/5
The existing requirement to pass a logger into the new ledger constructors must still be satisfied before merging.
### Issue 1
openmeter/ledger/historical/ledger.go:undefined-56`NewLedgerWithWriterBuild` accepts no `*slog.Logger`, but the repository guide requires production constructors to receive one. The new `NewLedgerHistoricalLedgerWithMetadata` provider has the same omission. Pass the logger through both constructors to satisfy this requirement before merging.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary
New ledger transaction groups record the writer’s revision and version when available.
New ledger groups record the build that committed them.
Services use configurable build details for their identity.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
Build[Embedded build identifiers] --> Defaults[Configuration defaults]
Overrides[YAML or environment overrides] --> Defaults
Defaults --> Metadata[Resolved service metadata]
Metadata --> Ledger[Ledger writer]
Metadata --> Telemetry[Telemetry]
Metadata --> Version[Version endpoint]
Ledger --> NewGroup[New transaction group annotations]
The change resolves build revision and version values, passes them through configuration and container builds, and stamps known values on historical ledger transaction groups. It also adds E2E checks for the stored commit SHA and writer version.
Service binaries resolve revision data and pass revision and version values into configuration defaults. Configuration accepts metadata defaults that YAML and environment variables can override.
Container builds pass commit SHA and version values to binaries. Application metadata uses configured values, and the server version endpoint reports the configured version.
Stamp transaction groups openmeter/ledger/annotations.go, openmeter/ledger/historical/ledger.go, openmeter/ledger/historical/writer_build_test.go, openmeter/ledger/README.md, app/common/ledger.go
The historical ledger stamps eligible writer commit SHA and version values on transaction groups. The application passes metadata to the ledger; tests and documentation cover the annotation behavior.
sequenceDiagram
participant ContainerBuild
participant Server as cmd/server
participant Config as Viper configuration
participant AppMetadata as common.Metadata
participant HistoricalLedger as historical.Ledger
participant Repo
ContainerBuild->>Server: Link COMMIT_SHA and VERSION
Server->>Config: SetViperDefaultsWithMetadata(revision, version)
Config->>AppMetadata: Set metadata.revision and metadata.version defaults
AppMetadata->>HistoricalLedger: Pass revision and version to ledger constructor
HistoricalLedger->>Repo: CreateTransactionGroup with stamped annotations
Loading
Suggested labels:kind/feature
Suggested reviewers:turip
Merge Risk: Minimal · up to dbeb7
No material user-facing regression is established; the change is mergeable after normal checks.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly describes the main change: stamping ledger transaction groups with writer build metadata.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
The reason will be displayed to describe this comment to others. Learn more.
New constructors omit the logger
NewLedgerWithWriterBuild accepts no *slog.Logger, but the repository guide requires production constructors to receive one. The new NewLedgerHistoricalLedgerWithMetadata provider has the same omission. Pass the logger through both constructors to satisfy this requirement before merging.
This is a comment left during a code review.
Path: openmeter/ledger/historical/ledger.go
Line: 56
Comment:
**New constructors omit the logger**`NewLedgerWithWriterBuild` accepts no `*slog.Logger`, but the repository guide requires production constructors to receive one. The new `NewLedgerHistoricalLedgerWithMetadata` provider has the same omission. Pass the logger through both constructors to satisfy this requirement before merging.
**Context Used:** AGENTS.md ([source](https://github.com/openmeterio/openmeter/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
The reason will be displayed to describe this comment to others. Learn more.
Additional comments: 1
pkg/buildinfo/revision.go: 1
12-23: Trivial · Functional Correctness · Low value
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Heads up: a linked revision can pair with a VCS date from a different commit.
Take a binary that gets -X main.revision=<sha> from the Dockerfile and also has Go VCS stamping on. revision comes from the linker value. revisionDate still comes from vcs.time. Normally these match, so this is fine. They can diverge if the build context differs from the checkout, for example a dirty tree or a CI SHA that isn't HEAD.
Consider reading vcs.time only when the revision came from vcs.revision. Alternatively, keep the current behavior and document it. This is low impact, since the date is informational only.
Reviewing files that changed from the base of the PR and between eff57f8 and 9a1289b.
Files selected for processing: 15
Dockerfile
app/common/ledger.go
app/config/credits.go
app/config/credits_test.go
cmd/balance-worker/version.go
cmd/billing-worker/main.go
cmd/billing-worker/version.go
cmd/jobs/internal/config.go
cmd/jobs/internal/version.go
cmd/notification-service/version.go
cmd/server/main.go
cmd/server/version.go
cmd/sink-worker/version.go
openmeter/ledger/README.md
pkg/buildinfo/revision.go
Files skipped from review as they are similar to previous changes: 1
openmeter/ledger/README.md
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Additional comments: 1
app/config/config.go: 1
208-209: Trivial · Maintainability & Code Quality · Low value
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Heads up: SetViperDefaults drops the version default.
SetViperDefaults only passes Revision, so metadata.version defaults to an empty string. This is fine for current binaries, because they call SetViperDefaultsWithMetadata. Tests and any future caller of SetViperDefaults will see an empty version and silently skip the writer-version stamp. The doc comment on SetViperDefaultsWithMetadata says it supplies "the binary's build identity". A short note on SetViperDefaults would make the empty version obvious to callers.
Reviewing files that changed from the base of the PR and between eff57f8 and dbeb722.
Files selected for processing: 25
Dockerfile
app/common/ledger.go
app/common/metadata.go
app/common/metadata_test.go
app/config/config.go
app/config/config_test.go
app/config/metadata_test.go
app/config/testdata/complete.yaml
cmd/balance-worker/main.go
cmd/balance-worker/version.go
cmd/billing-worker/main.go
cmd/billing-worker/version.go
cmd/jobs/internal/config.go
cmd/jobs/internal/version.go
cmd/notification-service/main.go
cmd/notification-service/version.go
cmd/server/main.go
cmd/server/version.go
cmd/server/wire.go
cmd/server/wire_gen.go
cmd/sink-worker/main.go
cmd/sink-worker/version.go
e2e/ledger_writer_build_test.go
openmeter/ledger/README.md
pkg/buildinfo/revision.go
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
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
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.
Overview
Stamp each new ledger transaction group with the writer's full Git SHA and release version when available. This helps identify the code that booked a group during a rolling deployment. Existing groups retain their original annotations.
The service supplies its embedded revision and version as defaults for
metadata.revisionandmetadata.version. All writers receive the resolved values through common service metadata. The existing telemetry service version and HTTP version endpoint read the same version. Native builds discover the Git revision through Go build info. Packaged binaries also support a revision supplied at build time.Verification
The E2E test creates a grant over the v3 API, reads its persisted ledger group from PostgreSQL, and compares the version with the running server's version endpoint. Local runs covered a versioned native build, a binary built without Go VCS metadata or a release version, and independent YAML revision and environment version overrides.
The existing requirement to pass a logger into the new ledger constructors must still be satisfied before merging.
Fix with agent prompt
Summary
New ledger transaction groups record the writer’s revision and version when available.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR Build[Embedded build identifiers] --> Defaults[Configuration defaults] Overrides[YAML or environment overrides] --> Defaults Defaults --> Metadata[Resolved service metadata] Metadata --> Ledger[Ledger writer] Metadata --> Telemetry[Telemetry] Metadata --> Version[Version endpoint] Ledger --> NewGroup[New transaction group annotations]Reviews (3) · Last reviewed commit: "refactor(ledger): use common service met..." · Reviewed by Greptile
Summary by CodeRabbit
/versionendpoint reports the configured application version.