From 3a90f8f22977122b6786528770d34524d11adbce Mon Sep 17 00:00:00 2001 From: e_forbes Date: Wed, 24 Sep 2025 13:56:45 +0100 Subject: [PATCH] feat: adds the new fields package to labkit This is intended to help enforce a certain level of consistency across our Go services when it comes to representing information within our logs. This starts with the GitLabUserID as this field has been identified to be particularly troublesome within our current o11y setup. --- .gitlab-ci.yml | 2 +- README.md | 12 ++++++++++++ fields/doc.go | 8 ++++++++ fields/fields.go | 18 ++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 fields/doc.go create mode 100644 fields/fields.go diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6ca46dd..1c8d028 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -55,7 +55,7 @@ variables: - GO_FIPS_VERSION: ["1.23", "1.24", "1.25"] backwards_compat: - image: registry.gitlab.com/gitlab-org/gitlab-build-images/debian-bookworm-golang-1.23-rust-1.73:git-2.45 + image: registry.gitlab.com/gitlab-org/gitlab-build-images/debian-bookworm-golang-1.24-rust-1.73:git-2.45 parallel: matrix: - REPO_AND_DIR: diff --git a/README.md b/README.md index 3cbc025..d82237a 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,18 @@ import ( ) ``` +### Fields + +[![](https://godoc.org/gitlab.com/gitlab-org/labkit/fields?status.svg)](http://godoc.org/gitlab.com/gitlab-org/labkit/fields) + +```go +import ( + "gitlab.com/gitlab-org/labkit/fields" +) + +// fields.GitLabUserID - returns the constant field name you should use to represent this data. +``` + ## Developing LabKit Anyone can contribute! diff --git a/fields/doc.go b/fields/doc.go new file mode 100644 index 0000000..505b2b7 --- /dev/null +++ b/fields/doc.go @@ -0,0 +1,8 @@ +/* +Package fields is intended to be the SSOT for Go applications for all +of the field names used within our observability setup. + +This is intended to help enforce consistency across components when it +comes to field names. +*/ +package fields diff --git a/fields/fields.go b/fields/fields.go new file mode 100644 index 0000000..930a4ee --- /dev/null +++ b/fields/fields.go @@ -0,0 +1,18 @@ +package fields + +const ( + // correlation_id - string + // This field is used to correlate + // the logs emitted by all of our systems. + // This should be present in all log line + // emissions. + CorrelationID = "correlation_id" + + // GitLabUserID - an integer field that + // captures the user's numeric ID for logging purposes. + GitLabUserID = "gl_user_id" + + // GitLabUserName - a string field that + // captures the user's username for logging purposes. + GitLabUserName = "gl_user_name" +) -- GitLab