Add application setting for CI telemetry sampling rate

What does this MR do and why?

Adds a new ci_job_telemetry_sampling_rate application setting (float, 0.0–1.0, default 0.0) that controls what fraction of pipelines in feature-flag-enabled projects have CI job telemetry instrumentation.

The setting is stored in the ci_cd_settings JSONB column on application_settings (no schema migration needed), following the same pattern as ci_telemetry_otel_endpoint from !230213 (merged).

The sampling decision is deterministic per root pipeline ID using a SHA256 hash, so all jobs in the same pipeline hierarchy get the same result (no partial traces). features.tracing is included in the job payload only when all three conditions are met:

  1. The ci_job_telemetry feature flag is enabled for the project
  2. The ci_telemetry_otel_endpoint setting is configured
  3. The pipeline is sampled according to this setting

When the rate is 0.0 (default), no pipelines are sampled — telemetry is effectively disabled even if the feature flag is on. When 1.0, all pipelines in enabled projects are sampled.

Closes #593834 (closed)

Changes

  • JSONB column: Adds ci_job_telemetry_sampling_rate to ci_cd_settings_definition (no DB migration)
  • Model: Numericality validation (0.0–1.0)
  • Build model: Adds pipeline_sampled_for_telemetry? check using deterministic SHA256 hash of root pipeline ID
  • API: Exposes setting in application settings entity and accepts it as an optional API parameter
  • API settings filter: Gated behind the ci_job_telemetry_settings experiment feature flag (same flag as ci_telemetry_otel_endpoint)

No UI/Frontend Changes are in the scope of this MR

References

Screenshots or screen recordings

N/A — backend-only change, no UI modifications.

How to set up and validate locally

  1. Enable the feature flags:

    Feature.enable(:ci_job_telemetry)
    Feature.enable(:ci_job_telemetry_settings)
  2. Configure the OTEL endpoint and sampling rate:

    ApplicationSetting.current.update!(
      ci_telemetry_otel_endpoint: 'https://otel-collector.example.com/v1/traces',
      ci_job_telemetry_sampling_rate: 0.5
    )
  3. Verify the setting is persisted:

    ApplicationSetting.current.ci_job_telemetry_sampling_rate
    # => 0.5
  4. Verify validation rejects out-of-range values:

    setting = ApplicationSetting.current
    setting.ci_job_telemetry_sampling_rate = 1.5
    setting.valid?
    # => false
    setting.errors[:ci_job_telemetry_sampling_rate]
    # => ["must be less than or equal to 1.0"]
  5. Set rate to 0.0 — verify features.tracing is absent from job request responses. Set to 1.0 — verify it's present.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

  • Tests added for all new/changed functionality
  • Rubocop passes with no offenses
  • OpenAPI docs regenerated
Edited by Narendran

Merge request reports

Loading