# Tail-sampling policies for the shop namespace. Tail sampling must run in a
# single collector instance that sees every span of a trace, which is why this
# pipeline has no other processors between the receiver and the sampler.
processors:
  tail_sampling:
    decision_wait: 30s
    num_traces: 100000
    expected_new_traces_per_sec: 2000
    policies:
      - name: keep-all-errors
        type: status_code
        status_code:
          status_codes: [ERROR]

      - name: keep-slow-checkouts
        type: latency
        latency:
          threshold_ms: 1000

      - name: keep-flagged-customers
        type: string_attribute
        string_attribute:
          key: enduser.id
          values: [cust-000418, cust-000502]
          enabled_regex_matching: false

      - name: drop-health-checks
        type: string_attribute
        string_attribute:
          key: url.path
          values: ['^/healthz$', '^/readyz$']
          enabled_regex_matching: true
          invert_match: true

      - name: probabilistic-remainder
        type: probabilistic
        probabilistic:
          sampling_percentage: 5

      - name: composite-rate-limited
        type: composite
        composite:
          max_total_spans_per_second: 500
          policy_order: [keep-all-errors, keep-slow-checkouts, probabilistic-remainder]
          composite_sub_policy:
            - name: keep-all-errors
              type: status_code
              status_code:
                status_codes: [ERROR]
            - name: keep-slow-checkouts
              type: latency
              latency:
                threshold_ms: 1000
            - name: probabilistic-remainder
              type: probabilistic
              probabilistic:
                sampling_percentage: 5

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [tail_sampling, batch]
      exporters: [otlphttp/traces]
