Verified Commit 55a90e9c authored by Hercules Merscher's avatar Hercules Merscher 🌴
Browse files

fix: Sets OTel's default sampler to probabilistic (0.1%)

parent 3d81966c
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -84,6 +84,8 @@ The following connection string formats and query parameters are supported:

### Sampling

**Default Behavior:** When no sampler is specified, probabilistic sampling is used with a **0.1% sample rate** (1 in 1000 traces).

- **`sampler`** - Sampling strategy (`probabilistic` or `const`)
  - `probabilistic` - Sample a percentage of traces (default: 0.1%)
  - `const` - Sample all traces (when `sampler_param=1`) or none (when `sampler_param=0`)
@@ -416,6 +418,9 @@ The tracing module includes built-in sanitization:
Use sampling to control overhead:

```bash
# Default: 0.1% sampling (no sampler specified)
export GITLAB_TRACING="otlp://localhost:4318"

# Trace 1% of requests
export GITLAB_TRACING="otlp://localhost:4318?sampler=probabilistic&sampler_param=0.01"

+3 −0
Original line number Diff line number Diff line
@@ -6,6 +6,9 @@ module Labkit
    # distributed tracing system within the process, given the
    # tracing connection string
    class Factory
      # When the probabilistic sampler is used, by default 0.1% of requests will be traced
      DEFAULT_PROBABILISTIC_RATE = 0.001

      # @param service_name [String] The service name for the tracer
      # @param connection_string [String] The connection string (e.g., "otlp://localhost:4318")
      # @yield [config] Optional configuration block for OpenTelemetry SDK customization (OTLP only)
+1 −4
Original line number Diff line number Diff line
@@ -10,9 +10,6 @@ module Labkit
  module Tracing
    # JaegerFactory will configure Jaeger distributed tracing
    class JaegerFactory
      # When the probabilistic sampler is used, by default 0.1% of requests will be traced
      DEFAULT_PROBABILISTIC_RATE = 0.001

      # The default port for the Jaeger agent UDP listener
      DEFAULT_UDP_PORT = 6831

@@ -73,7 +70,7 @@ module Labkit
      def self.get_sampler(sampler_type, sampler_param)
        case sampler_type
        when "probabilistic"
          sampler_rate = sampler_param ? sampler_param.to_f : DEFAULT_PROBABILISTIC_RATE
          sampler_rate = sampler_param ? sampler_param.to_f : Factory::DEFAULT_PROBABILISTIC_RATE
          Jaeger::Samplers::Probabilistic.new(rate: sampler_rate)
        when "const"
          const_value = sampler_param == "1"
+2 −5
Original line number Diff line number Diff line
@@ -14,9 +14,6 @@ module Labkit
    class OpenTelemetryFactory
      OTLP_SCHEME = "otlp"

      # When the probabilistic sampler is used, by default 0.1% of requests will be traced
      DEFAULT_PROBABILISTIC_RATE = 0.001

      # The default endpoint for OTLP HTTP exporter
      DEFAULT_HTTP_ENDPOINT = "http://localhost:4318/v1/traces"

@@ -174,7 +171,7 @@ module Labkit
        def get_sampler(sampler_type, sampler_param)
          case sampler_type
          when "probabilistic"
            sampler_rate = sampler_param ? sampler_param.to_f : DEFAULT_PROBABILISTIC_RATE
            sampler_rate = sampler_param ? sampler_param.to_f : Factory::DEFAULT_PROBABILISTIC_RATE
            OpenTelemetry::SDK::Trace::Samplers::TraceIdRatioBased.new(sampler_rate)
          when "const"
            if sampler_param == "1"
@@ -183,7 +180,7 @@ module Labkit
              OpenTelemetry::SDK::Trace::Samplers::ALWAYS_OFF
            end
          else
            OpenTelemetry::SDK::Trace::Samplers::ALWAYS_ON
            OpenTelemetry::SDK::Trace::Samplers::TraceIdRatioBased.new(Factory::DEFAULT_PROBABILISTIC_RATE)
          end
        end

+2 −2
Original line number Diff line number Diff line
@@ -326,9 +326,9 @@ describe Labkit::Tracing::OpenTelemetryFactory do
  end

  describe ".get_sampler" do
    it "returns ALWAYS_ON for unknown sampler type" do
    it "returns probabilistic sampler with default rate for unknown sampler type" do
      sampler = described_class.send(:get_sampler, "unknown", nil)
      expect(sampler).to eq(OpenTelemetry::SDK::Trace::Samplers::ALWAYS_ON)
      expect(sampler).to be_a(OpenTelemetry::SDK::Trace::Samplers::TraceIdRatioBased)
    end

    it "returns ALWAYS_ON for const sampler with param 1" do