open-telemetry/sampler-rule-based

OpenTelemetry SDK rule-based sampler

0.0.1 2024-09-12 23:58 UTC

This package is auto-updated.

Last update: 2024-11-13 01:26:43 UTC


README

Provides additional samplers that are not part of the official specification.

Installation

composer require open-telemetry/sampler-rule-based

RuleBasedSampler

Allows sampling based on a list of rule sets. The first matching rule set will decide the sampling result.

$sampler = new RuleBasedSampler(
    [
        new RuleSet(
            [
                new SpanKindRule(Kind::Server),
                new AttributeRule('url.path', '~^/health$~'),
            ],
            new AlwaysOffSampler(),
        ),
    ],
    new AlwaysOnSampler(),
);

Configuration

Example: drop spans for the /health endpoint
contrib_rule_based:
    rule_sets:
    -   rules:
        -   span_kind: { kind: SERVER }
        -   attribute: { key: url.path, pattern: ~^/health$~ }
        delegate:
            always_off: {}
    fallback: # ...
Example: sample spans with at least one sampled link
contrib_rule_based:
    rule_sets:
    -   rules: [ link: { sampled: true } ]
        delegate:
            always_on: {}
    fallback: # ...
Example: modeling parent based sampler as rule based sampler
rule_based:
    rule_sets:
    -   rules: [ parent: { sampled: true, remote: true } ]
        delegate: # remote_parent_sampled
    -   rules: [ parent: { sampled: false, remote: true } ]
        delegate: # remote_parent_not_sampled
    -   rules: [ parent: { sampled: true, remote: false } ]
        delegate: # local_parent_sampled
    -   rules: [ parent: { sampled: false, remote: false } ]
        delegate: # local_parent_not_sampled
    fallback: # root

AlwaysRecordingSampler

Records all spans to allow the usage of span processors that generate metrics from spans.

$sampler = new AlwaysRecordingSampler(
    new ParentBasedSampler(new AlwaysOnSampler()),
);

Configuration

always_recording:
    sampler: # ...