Loading
feat(v2/app): add build metadata vars with automatic logger enrichment
What this MR does
Adds three exported, ldflag-injectable package-level variables (Version, Commit, Date) to the gitlab.com/gitlab-org/labkit/v2/app package, and enriches the structured logger in NewWithConfig with those values automatically.
Services that link with:
-X 'gitlab.com/gitlab-org/labkit/v2/app.Version=<version>'
-X 'gitlab.com/gitlab-org/labkit/v2/app.Commit=<commit>'
-X 'gitlab.com/gitlab-org/labkit/v2/app.Date=<date>'will get version, commit, and date fields on every log line with no per-service boilerplate.
Without ldflags (local/dev builds) the defaults are "dev", "unknown", "unknown".
Why
Every Go service at GitLab currently duplicates the same var version/commit/date block and logger.With(...) enrichment in main.go. This moves that concern into LabKit so it is consistent across all consumers and cannot be accidentally omitted.
Files changed
| File | Change |
|---|---|
v2/app/buildinfo.go |
New — exported Version, Commit, Date vars |
v2/app/buildinfo_test.go |
New — tests for defaults and overridability |
v2/app/app.go |
NewWithConfig now calls logger.With(...) after constructing the logger |
v2/app/app_test.go |
TestNewWithConfigEnrichesLogger asserts all three fields appear in JSON output |
How to test
cd v2 && go test ./app/... -v— all tests should pass- Build any consumer binary with the new ldflags and observe
version/commit/datein every log line
Checklist
- Tests added and passing
- Backward compatible (additive only — no API changes)
-
New()→NewWithConfig(ctx, nil)path also enriched (delegates) -
NewForTestingintentionally bypassed (test isolation)