샘플링 (Sampling)
들어오는 트레이스 텔레메트리 데이터에 head 또는 tail 샘플링을 적용하고 싶을 때 쓰는 프로세서입니다. 함께 살펴보겠습니다.
출처: 문서
본문
sampling 프로세서는 여러 트레이스 샘플링 전략과 백엔드를 지원하는 확장 가능한 아키텍처를 사용합니다. 들어오는 트레이스 텔레메트리 데이터에 head나 tail 샘플링을 적용할 수 있게 해 줍니다.
{% hint style="info" %} 프로세서를 지원하는 것은 YAML 구성 파일뿐입니다. {% endhint %}
Configuration parameters
이 프로세서는 다음 구성 파라미터를 사용합니다:
| Key | Description | Default |
|---|---|---|
conditions |
An array of objects where each object specifies a different condition for tail sampling. The possible items in each object vary by conditions.type. |
none |
debug |
Enables debug mode, which prints the trace and its spans. | false |
sampling_settings |
Contains key/value pairs for different sampling settings. These settings vary by type. |
none |
type |
The type of sampling to perform. Possible values: probabilistic (head sampling) or tail (tail sampling). |
none |
Head sampling
Head sampling은 트레이스를 유지할지 여부를 수집의 가장 초기에 결정합니다. 루트 스팬이 생성되지만 실제 요청이 완료되기 전의 시점이죠.

Head sampling은 다음 sampling_settings 구성 파라미터를 사용합니다:
| Key | Description |
|---|---|
sampling_percentage |
Sets the probability of sampling trace. Must be a value between 0 and 100. For example, 40 samples 40% of traces randomly. |
이 예시는 head sampling을 사용해 전체 수집 트레이스와 스팬 중 더 작은 비율을 처리합니다. OpenTelemetry 프로토콜(OTLP)을 사용해 OpenTelemetry에서 정의된 포트로 수집하도록 파이프라인을 설정하는 방식으로 이를 달성합니다. processor 섹션은 head sampling용 트레이스와 지정된 출력 플러그인으로 전달할 트레이스 및 스팬의 비율을 정의합니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
service:
flush: 1
log_level: info
hot_reload: on
pipeline:
inputs:
- name: opentelemetry
port: 4318
processors:
traces:
# Head sampling of traces (percentage)
- name: sampling
type: probabilistic
sampling_settings:
sampling_percentage: 40
outputs:
- name: stdout
match: "*"
{% endtab %} {% endtabs %}
이 head sampling 구성을 사용하면 샘플링된 전체 트레이스 중 무작위로 40%가 표준 출력으로 전송됩니다.
Tail sampling
Tail sampling은 트레이스와 스팬 수집에 대해 더 선택적이고 세밀한 제어를 제공합니다. 샘플링 결정을 내릴 때 전체 트레이스를 평가하고, 결정에 참고하기 위해 트레이스의 메타데이터와 상태를 검사할 수 있어요.

Tail sampling은 다음 sampling_settings 구성 파라미터를 사용합니다:
| Key | Description | Default |
|---|---|---|
decision_wait |
Specifies how long to buffer spans before making a sampling decision, allowing full trace evaluation. | 30s |
legacy_reconcile |
Uses the legacy tail-sampling reconciliation path instead of the optimized reconciler. Keep this disabled unless you need behavior parity while comparing results with older deployments. | false |
max_traces |
Specifies the maximum number of traces that can be held in memory. When the limit is reached, the oldest trace is deleted. | none |
Conditions
Tail sampling은 다양한 조건을 지원합니다. 이 조건들은 트레이스가 지정된 기준을 충족하는지 결정합니다.
다음 조건을 사용할 수 있습니다:
Latency
이 조건은 스팬 지속 시간을 기준으로 트레이스를 샘플링합니다. 짧은 트레이스를 캡처하려면 threshold_ms_low를, 긴 트레이스에는 threshold_ms_high를 사용합니다.
latency 조건은 다음 conditions 구성 파라미터를 사용합니다:
| Key | Description | Default |
|---|---|---|
threshold_ms_high |
Specifies the upper latency threshold. Traces with a duration greater than or equal to this value will be sampled. | 0 |
threshold_ms_low |
Specifies the lower latency threshold. Traces with a duration less than or equal to this value will be sampled. | 0 |
type |
Sets the condition type. For the latency condition, this value must be latency. |
none |
다음 예시는 결정을 내리기 전에 5초를 기다립니다. 그런 다음 지연 시간을 기준으로 트레이스를 샘플링하여 200ms 이하의 짧은 트레이스와 3000ms 이상의 긴 트레이스를 캡처합니다. 200ms와 3000ms 사이의 트레이스는 다른 조건이 적용되지 않는 한 샘플링되지 않습니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
service:
flush: 1
log_level: info
hot_reload: on
pipeline:
inputs:
- name: opentelemetry
port: 4318
processors:
traces:
# Tail sampling of traces (latency)
- name: sampling
type: tail
sampling_settings:
decision_wait: 5s
conditions:
- type: latency
threshold_ms_low: 200
threshold_ms_high: 3000
outputs:
- name: stdout
match: "*"
{% endtab %} {% endtabs %}
Span count
이 조건은 구성 가능한 범위에 정의된 특정 스팬 개수를 가진 트레이스를 샘플링합니다. 트레이스가 샘플링되기 위해 가질 수 있는 스팬 수를 지정하려면 min_spans과 max_spans를 사용합니다.
span count 조건은 다음 conditions 구성 파라미터를 사용합니다:
| Key | Description | Default |
|---|---|---|
max_spans |
Specifies the maximum number of spans a trace can have to be sampled. | none |
min_spans |
Specifies the minimum number of spans a trace must have to be sampled. | none |
type |
Sets the condition type. For the span count condition, this value must be span_count. |
none |
다음 예시 구성은 결정을 내리기 전에 5초를 기다립니다. 그런 다음 최소 3개에서 최대 5개 이하의 스팬을 가진 트레이스를 샘플링합니다. 3개 미만이거나 5개 초과의 스팬을 가진 트레이스는 다른 조건이 적용되지 않는 한 샘플링되지 않습니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
service:
flush: 1
log_level: info
hot_reload: on
pipeline:
inputs:
- name: opentelemetry
port: 4318
processors:
traces:
# Tail sampling of traces (span_count)
- name: sampling
type: tail
sampling_settings:
decision_wait: 5s
conditions:
- type: span_count
min_spans: 3
max_spans: 5
outputs:
- name: stdout
match: "*"
{% endtab %} {% endtabs %}
Status code
이 조건은 스팬 상태 코드(OK, ERROR, UNSET)를 기준으로 트레이스를 샘플링합니다.
status code 조건은 다음 conditions 구성 파라미터를 사용합니다:
| Key | Description | Default |
|---|---|---|
status_codes |
Defines an array of span status codes (OK, ERROR, UNSET) to filter traces. Traces are sampled if any span matches a listed status code. For example, status_codes: [ERROR, UNSET] captures traces with errors or unset statuses. |
none |
type |
Sets the condition type. For the status code condition, this value must be status_code. |
none |
다음 예시 구성은 ERROR 상태 코드를 가진 스팬만 샘플링합니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
service:
flush: 1
log_level: info
hot_reload: on
pipeline:
inputs:
- name: opentelemetry
port: 4318
processors:
traces:
# Tail sampling of traces (status_code)
- name: sampling
type: tail
sampling_settings:
decision_wait: 5s
conditions:
- type: status_code
status_codes: [ERROR]
outputs:
- name: stdout
match: "*"
{% endtab %} {% endtabs %}
String attribute
이 조건은 특정 스팬 또는 리소스 속성을 기반으로 트레이스를 샘플링할 수 있게 해 줍니다. 키-값 필터(예: http.method=POST)를 정의해 관련 트레이스를 선택적으로 캡처할 수 있어요.
string attribute 조건은 다음 conditions 구성 파라미터를 사용합니다:
| Key | Description | Default |
|---|---|---|
key |
Specifies the span or resource attribute to match (for example, "service.name"). |
none |
match_type |
Defines how attributes are compared: strict ensures exact value matching (and is case-sensitive), exists checks if the attribute is present regardless of its value, and regex uses regular expression pattern matching. |
strict |
type |
Sets the condition type. For the string attribute condition, this value must be string_attribute. |
none |
values |
Defines an array of accepted values for the attribute. A trace is sampled if any span contains a matching key-value pair: ["payment-processing"] |
none |
다음 예시 구성은 결정을 내리기 전에 2초를 기다립니다. 그런 다음 문자열 매칭 키-값 쌍을 기준으로 트레이스를 샘플링합니다:
http.method가 정확히GET인 트레이스service.name속성이 있는 트레이스(값은 아무거나)http.url이https://api.로 시작하거나/health로 끝나는 트레이스error.message에 timeout, connection failed, 또는 rate limit 패턴이 포함된 트레이스
{% tabs %} {% tab title="fluent-bit.yaml" %}
service:
flush: 1
log_level: info
hot_reload: on
pipeline:
inputs:
- name: opentelemetry
port: 4318
processors:
traces:
# Tail sampling of traces (string_attribute)
- name: sampling
type: tail
sampling_settings:
decision_wait: 2s
conditions:
# Exact matching
- type: string_attribute
match_type: strict
key: "http.method"
values: ["GET"]
# Check if attribute exists
- type: string_attribute
match_type: exists
key: "service.name"
# Regex pattern matching
- type: string_attribute
match_type: regex
key: "http.url"
values: ["^https://api\\..*", ".*\\/health$"]
# Multiple regex patterns for error conditions
- type: string_attribute
match_type: regex
key: "error.message"
values: ["timeout.*", "connection.*failed", ".*rate.?limit.*"]
outputs:
- name: stdout
match: "*"
{% endtab %} {% endtabs %}
Numeric attribute
이 조건은 정의된 키의 숫자 속성 값을 기준으로 트레이스를 샘플링하며, 사용자가 최소/최대 임계값을 구성할 수 있습니다.
numeric attribute 조건은 다음 conditions 구성 파라미터를 사용합니다:
| Key | Description | Default |
|---|---|---|
key |
Specifies the span or resource attribute to match (for example, "service.name"). |
none |
match_type |
This defines how attribute values are evaluated: strict matches exact values, exists checks if the attribute is present, regardless of its value. |
strict |
max_value |
The maximum inclusive value for the numeric attribute. Traces with values less than or equal to the max_value are sampled. |
none |
min_value |
The minimum inclusive value for the numeric attribute. Traces with values greater than or equal to the min_value are sampled. |
none |
type |
Sets the condition type. For the numeric attribute condition, this value must be numeric_attribute. |
none |
다음 예시 구성은 http.status code 키에 대해 400과 504 사이(포함)의 숫자 값을 가진 스팬만 샘플링합니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
service:
flush: 1
log_level: info
hot_reload: on
pipeline:
inputs:
- name: opentelemetry
port: 4318
processors:
traces:
# Tail sampling of traces (status_code)
- name: sampling
type: tail
sampling_settings:
decision_wait: 5s
conditions:
- type: numeric_attribute
key: "http.status_code"
min_value: 400
max_value: 504
outputs:
- name: stdout
match: "*"
{% endtab %} {% endtabs %}
Boolean attribute
이 조건은 정의된 키의 부울 속성 값을 기준으로 트레이스를 샘플링합니다. 오류 표시기나 디버그 모드 같은 플래그를 기반으로 트레이스를 선택할 수 있게 해 줍니다.
Boolean attribute 조건은 다음 conditions 구성 파라미터를 사용합니다:
| Key | Description | Default |
|---|---|---|
key |
Specifies the span or resource attribute to match (for example, "service.name"). |
none |
type |
Sets the condition type. For the Boolean attribute condition, this value must be boolean_attribute. |
none |
value |
Expected boolean value: true or false |
none |
다음 예시 구성은 결정을 내리기 전에 2초를 기다립니다. 그런 다음 user.logged 키가 false로 설정된 트레이스를 샘플링합니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
service:
flush: 1
log_level: info
hot_reload: on
pipeline:
inputs:
- name: opentelemetry
port: 4318
processors:
traces:
# Tail sampling of traces (boolean_attribute)
- name: sampling
type: tail
sampling_settings:
decision_wait: 2s
conditions:
- type: boolean_attribute
key: "user.logged"
value: false
outputs:
- name: stdout
match: "*"
{% endtab %} {% endtabs %}
Trace state
이 조건은 W3C trace_state 필드에 저장된 메타데이터를 기준으로 트레이스를 샘플링합니다.
trace state 조건은 다음 conditions 구성 파라미터를 사용합니다:
| Key | Description | Default |
|---|---|---|
type |
Sets the condition type. For the trace state condition, this value must be trace_state. |
none |
values |
Defines a list of key, value pairs to match against the trace_state. A trace is sampled if any of the specified values exist in the trace_state field. Matching follows OR logic, meaning at least one value must be present for sampling to occur. |
none |
예시 구성:
{% tabs %} {% tab title="fluent-bit.yaml" %}
service:
flush: 1
log_level: info
hot_reload: on
pipeline:
inputs:
- name: opentelemetry
port: 4318
processors:
traces:
# Tail sampling of traces (trace_state)
- name: sampling
type: tail
sampling_settings:
decision_wait: 2s
conditions:
- type: trace_state
values: [debug=false, priority=high]
outputs:
- name: stdout
match: "*"
{% endtab %} {% endtabs %}
추가 처리에 대한 자세한 내용은 content modifier 프로세서 문서를 읽어보세요.