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:
- The
ci_job_telemetryfeature flag is enabled for the project - The
ci_telemetry_otel_endpointsetting is configured - 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_ratetoci_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_settingsexperiment feature flag (same flag asci_telemetry_otel_endpoint)
No UI/Frontend Changes are in the scope of this MR
References
- Parent epic: &20945 (CI Job Telemetry - CI Platform)
- Adjacent work item: #591941 (closed) (OTEL Collector endpoint setting — !230213 (merged))
- Architecture doc: Sampling strategy
Screenshots or screen recordings
N/A — backend-only change, no UI modifications.
How to set up and validate locally
-
Enable the feature flags:
Feature.enable(:ci_job_telemetry) Feature.enable(:ci_job_telemetry_settings) -
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 ) -
Verify the setting is persisted:
ApplicationSetting.current.ci_job_telemetry_sampling_rate # => 0.5 -
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"] -
Set rate to 0.0 — verify
features.tracingis 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