Verified Commit 88672a66 authored by Elliot Forbes's avatar Elliot Forbes 2️⃣ Committed by GitLab
Browse files

Merge branch 'labkit-spec/update-fields' into 'master'

feat: update field constants (labkit-spec v1.0)

See merge request !259

Merged-by: Elliot Forbes's avatarElliot Forbes <eforbes@gitlab.com>
Approved-by: Bob Van Landuyt's avatarBob Van Landuyt <bob@gitlab.com>
Reviewed-by: default avatarGitLab Duo <gitlab-duo@gitlab.com>
parents db7db3fa 368dd2a6
Loading
Loading
Loading
Loading
Loading
+56 −65
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.
  #
  # 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
  #   ...
  #
  # Labkit (Go): https://gitlab.com/gitlab-org/labkit/-/tree/master/fields?ref_type=heads
# Code generated by labkit-spec. DO NOT EDIT.
#
  # For Engineers Looking to add fields:
  #
  # These fields are derived from the Go Labkit variant. Please ensure that you've made the
  # respective changes in that repository prior to including the fields in this package.
  #
  # Please see the handbook page for more information
  # https://handbook.gitlab.com/handbook/engineering/architecture/design-documents/observability_field_standardisation/
# Source: schema/fields.yaml (version 1.0)

module Labkit
  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.
    # Unique identifier for correlating requests across services. Should be
    # present in all log line emissions.
    CORRELATION_ID = "correlation_id"

    # GitLabUserID - an integer field that
    # captures the user's numeric ID for logging purposes.
    # GitLab user numeric ID.
    GL_USER_ID = "gl_user_id"

    # GitLabUserName - a string field that
    # captures the user's username for logging purposes.
    # GitLab username.
    GL_USER_NAME = "gl_user_name"

    # ErrorType - a string field that should contain the error type or classification
    # (e.g., "NoMethodError", "ValidationError").
    # Duo Workflow definition identifier (e.g. "analytics_agent/v1"). Identifies
    # which Duo Workflow agent originated a request, enabling per-agent
    # filtering in Kibana and Grafana.
    DUO_WORKFLOW_DEFINITION = "duo_workflow_definition"

    # Error type or classification (e.g. "NoMethodError", "ValidationError").
    ERROR_TYPE = "error_type"

    # ErrorMessage - a string field that should contain the detailed error message
    # (e.g., "undefined method `boom!' for nil").
    # Detailed error message (e.g. "undefined method 'boom!' for nil").
    ERROR_MESSAGE = "error_message"

    # HTTPStatusCode - an integer field that
    # captures the HTTP status code of requests for logging purposes.
    # HTTP response status code.
    HTTP_STATUS_CODE = "status"

    # HTTPMethod - a string field that captures the HTTP method
    # (e.g., "GET", "POST") of a request for logging purposes.
    # HTTP method (e.g. "GET", "POST").
    HTTP_METHOD = "method"

    # HTTPURL - a string field that captures the URL of an HTTP request
    # (scheme, host, and path only - query strings should be omitted
    # to avoid logging sensitive data) for logging purposes.
    # (e.g. "https://example.com/foo") Query strings and fragments (anchors)
    # must be omitted to avoid logging sensitive information such as tokens
    # or passwords that may appear in query parameters.
    # URL of an HTTP request containing only scheme, host, and path (e.g.
    # "https://example.com/foo"). Query strings and fragments must be omitted to
    # avoid logging sensitive information.
    HTTP_URL = "url"

    # DurationS - a float field that captures the duration of any operation
    # in seconds for logging purposes. It is not limited to HTTP requests and
    # can be used for any timed operation (e.g. database queries, background
    # jobs, external API calls).
    # Duration of any operation in seconds. Not limited to HTTP requests; can be
    # used for database queries, background jobs, external API calls. Uses
    # float64 for sub-second precision (e.g. 0.032 for 32ms).
    DURATION_S = "duration_s"

    # RemoteIP - a string field that captures the remote IP
    # address of a request for logging purposes.
    # Remote IP address of a request.
    REMOTE_IP = "remote_ip"

    # TCPAddress - a string field that captures the TCP address a service or
    # component is listening on, in "host:port" format
    # (e.g. "0.0.0.0:8080" or "127.0.0.1:9090").
    # TCP address a service is listening on, in "host:port" format (e.g.
    # "0.0.0.0:8080").
    TCP_ADDRESS = "tcp_address"

    # New fields being added to this section should have
    # the appropriate doc comments added above. These
    # should clearly indicate what the intended use of the
    # field is and should be replicated across the labkit
    # variations.
    # Request URI including path and query string with sensitive parameters
    # masked (e.g. "?password=[FILTERED]").
    HTTP_URI = "uri"

    # HTTP Host header of a request (e.g. "api.gitlab.com").
    HTTP_HOST = "host"

    # HTTP protocol version (e.g. "HTTP/1.1", "HTTP/2.0").
    HTTP_PROTO = "proto"

    # Raw remote socket address in "host:port" format (e.g. "10.0.0.1:54321").
    # Use remote_ip when only the IP is needed.
    REMOTE_ADDR = "remote_addr"

    # HTTP Referer header with sensitive query parameters masked.
    HTTP_REFERRER = "referrer"

    # HTTP User-Agent header.
    HTTP_USER_AGENT = "user_agent"

    # Number of bytes written to the HTTP response body.
    WRITTEN_BYTES = "written_bytes"

    # Content-Type of an HTTP response (e.g. "application/json").
    CONTENT_TYPE = "content_type"

    # Time to first byte of an HTTP response in seconds. Measures duration from
    # request receipt to first response byte written.
    TTFB_S = "ttfb_s"

    # Get the constant name for a field value
    # @param field_value [String] The field value (e.g., "gl_user_id")
@@ -107,7 +98,7 @@ module Labkit

      MAPPINGS = {
        Fields::GL_USER_ID => %w[user_id userid],
        Fields::HTTP_STATUS_CODE => %w[status_code extra.status status_text]
        Fields::HTTP_STATUS_CODE => %w[status_code extra.status status_text],
      }.freeze

      class << self