open-telemetry / sampler-rule-based
OpenTelemetry SDK rule-based sampler
0.0.1
2024-09-12 23:58 UTC
Requires
- php: ^8.1
- open-telemetry/api: dev-main as 1.1.0
- open-telemetry/sdk: dev-main as 1.1.0
- open-telemetry/sdk-configuration: dev-main as 0.99
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- phan/phan: ^5.0
- phpstan/phpstan: ^1.1
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^10 || ^11
- psalm/plugin-phpunit: ^0.18.4
- symfony/config: ^5.4 || ^6.4 || ^7.0
- symfony/yaml: ^6 || ^7
- vimeo/psalm: ^4|^5
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: # ...