Commit eac9c21f authored by Elliot Forbes's avatar Elliot Forbes 2️⃣
Browse files

Defines a Fields module within labkit

This is a pattern I'd like to see us eventually adopt across the
company where common field names are represented in the Labkit
libraries prior to their use within the code.

This will ultimately help reduce the likelihood of mismatches between
systems and should help improve the investigative efforts of our
engineers.
parent 5a3ab934
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ module Labkit
  autoload :Logging, "labkit/logging"
  autoload :Metrics, "labkit/metrics"
  autoload :Middleware, "labkit/middleware"
  autoload :Fields, "labkit/fields"

  # Publishers to publish notifications whenever a HTTP reqeust is made.
  # A broadcasted notification's payload in topic "request.external_http" includes:

lib/labkit/fields.rb

0 → 100644
+41 −0
Original line number Diff line number Diff line
# frozen_string_literal: true

module Labkit
  ##
  # Fields is intended to be a SSOT for all of the common field names that
  # we emit via any observability we add to our systems.
  #
  # These fields should span multiple services. This is
  #
  # The goal of this package is to reduce the likelihood for typos or
  # subtly different naming conventions. This will help to ensure we
  # are able to marry up logs between different systems as a request
  # is being processed.
  #
  # Usage:
  #   require 'labkit/fields'
  #   ...
  #   data[Labkit::Fields::GL_USER_ID] = user.id
  #   ...
  #
  module Fields
    # 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.
    CORRELATION_ID = "correlation_id"

    # We'll need to add the rest of the top
    # level fields here:
    # [endpoint_id, duration_s, status_code]

    # gl_user_id - integer
    GL_USER_ID = "gl_user_id"

    # gl_user_name - string
    GL_USER_NAME = "gl_user_name"
  end
end