Skip to content

feat(ledger): stamp transaction groups with writer build metadata - #5463

Merged
GAlexIHU merged 3 commits into
mainfrom
codex/ledger-writer-build
Nov 9, 2026
Merged

GAlexIHU merged 3 commits into
mainfrom
codex/ledger-writer-build

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

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.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.

RetriggerView in GreptileConfidence Score: 4/5

The existing requirement to pass a logger into the new ledger constructors must still be satisfied before merging.

Fix All in Claude CodeFindings

  1. P2 New constructors omit the logger ▶
Fix with agent prompt
### 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]
Loading

Reviews (3) · Last reviewed commit: "refactor(ledger): use common service met..." · Reviewed by Greptile

Summary by CodeRabbit

  • New Features
    • Build revision and version information is now included in application metadata and, when available, on new ledger transaction groups.
    • The /version endpoint reports the configured application version.
    • Container builds and end-to-end tests can verify embedded build identifiers.
  • Bug Fixes
    • Configured metadata values are now used where available, with build information providing defaults.

@GAlexIHU
GAlexIHU requested a review from a team as a code owner November 7, 2026 11:44
@GAlexIHU GAlexIHU added the release-note/feature Release note: Exciting New Features label Nov 7, 2026
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

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.

Changes: Build metadata and ledger annotations

Layer / File(s) Summary
Resolve build identity
pkg/buildinfo/revision.go, cmd/*/version.go, app/config/*, cmd/*/main.go, cmd/jobs/internal/*
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.
Propagate build metadata
Dockerfile, .github/workflows/container-tests.yaml, .github/workflows/release-docker.yaml, app/common/metadata.go, app/common/metadata_test.go, cmd/server/main.go, cmd/server/wire*.go
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.
Verify E2E metadata
e2e/Makefile, e2e/docker-compose.openmeter-local.yaml, e2e/ledger_writer_build_test.go, e2e/README.md
The local E2E build sets expected metadata values. TestLedgerWriterBuild checks the stored commit SHA, server version, and writer-version annotation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: stamping ledger transaction groups with writer build metadata.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

return NewLedgerWithWriterBuild(repo, accountCatalog, accountLocker, routingValidator, WriterBuild{})
}

func NewLedgerWithWriterBuild(repo Repo, accountCatalog ledger.AccountCatalog, accountLocker ledger.AccountLocker, routingValidator ledger.RoutingValidator, writerBuild WriterBuild) *Ledger {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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)

Prompt To Fix With AI
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!

Fix in Claude Code Fix in Codex

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

Review info

Run configuration

Commits

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

Review info

Run configuration

Commits

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.

@GAlexIHU
GAlexIHU merged commit 131a760 into main Nov 9, 2026
37 checks passed
@GAlexIHU
GAlexIHU deleted the codex/ledger-writer-build branch November 9, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants