PHPackages                             open-telemetry/sampler-rule-based - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. open-telemetry/sampler-rule-based

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

open-telemetry/sampler-rule-based
=================================

OpenTelemetry SDK rule-based sampler

0.2.0(3mo ago)04.9k↓77.4%Apache-2.0PHPPHP ^8.1

Since Sep 13Pushed 3w ago3 watchersCompare

[ Source](https://github.com/opentelemetry-php/contrib-sampler-rulebased)[ Packagist](https://packagist.org/packages/open-telemetry/sampler-rule-based)[ RSS](/packages/open-telemetry-sampler-rule-based/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (4)Dependencies (24)Versions (5)Used By (0)

RuleBasedSampler
================

[](#rulebasedsampler)

Allows sampling based on a list of rule sets.

Installation
------------

[](#installation)

```
composer require open-telemetry/sampler-rule-based
```

Usage
-----

[](#usage)

Provide a list of `RuleSet` instances and a fallback sampler to the `RuleBasedSampler` constructor. Each rule set contains a list of rules and a delegate sampler to execute if the rule matches. The rules are evaluated in the order they are defined. The first matching rule set will decide the sampling result.

If no rules match, then the fallback sampler is used.

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

Configuration
-------------

[](#configuration)

The RuleBased sampler can be configured through [Declarative Configuration](https://opentelemetry.io/docs/specs/otel/configuration/#declarative-configuration), using the key `php_rule_based` under `tracer_provider.sampler.sampler`:

```
file_format: "0.4"

tracer_provider:
  sampler:
    php_rule_based:
      rule_sets:
        # ...
      fallback:
        # ...
```

### Examples

[](#examples)

Drop spans for the /health endpoint:

```
php_rule_based:
    rule_sets:
    -   rules:
        -   span_kind: { kind: SERVER }
        -   attribute: { key: url.path, pattern: ~^/health$~ }
        delegate:
            always_off: {}
    fallback: # ...
```

Sample spans with at least one sampled link:

```
php_rule_based:
    rule_sets:
    -   rules: [ link: { sampled: true } ]
        delegate:
            always_on: {}
    fallback: # ...
```

Modeling parent-based sampler as rule-based sampler:

```
php_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
```

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance88

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~185 days

Total

4

Last Release

102d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4978962?v=4)[Brett McBride](/maintainers/brettmc)[@brettmc](https://github.com/brettmc)

![](https://avatars.githubusercontent.com/u/4099109?v=4)[Bob Strecansky](/maintainers/bobstrecansky)[@bobstrecansky](https://github.com/bobstrecansky)

---

Top Contributors

[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (4 commits)")[![brettmc](https://avatars.githubusercontent.com/u/4978962?v=4)](https://github.com/brettmc "brettmc (2 commits)")[![bobstrecansky](https://avatars.githubusercontent.com/u/4099109?v=4)](https://github.com/bobstrecansky "bobstrecansky (1 commits)")[![ChrisLightfootWild](https://avatars.githubusercontent.com/u/106102472?v=4)](https://github.com/ChrisLightfootWild "ChrisLightfootWild (1 commits)")[![intuibase](https://avatars.githubusercontent.com/u/9551626?v=4)](https://github.com/intuibase "intuibase (1 commits)")[![satdeveloping](https://avatars.githubusercontent.com/u/80039573?v=4)](https://github.com/satdeveloping "satdeveloping (1 commits)")

---

Tags

sdktracingopentelemetryotelsampler

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/open-telemetry-sampler-rule-based/health.svg)

```
[![Health](https://phpackages.com/badges/open-telemetry-sampler-rule-based/health.svg)](https://phpackages.com/packages/open-telemetry-sampler-rule-based)
```

###  Alternatives

[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2328.5M343](/packages/open-telemetry-sdk)[keepsuit/laravel-opentelemetry

OpenTelemetry integration for laravel

167558.4k1](/packages/keepsuit-laravel-opentelemetry)[open-telemetry/opentelemetry-auto-laravel

OpenTelemetry auto-instrumentation for Laravel

592.7M9](/packages/open-telemetry-opentelemetry-auto-laravel)[open-telemetry/opentelemetry-auto-symfony

OpenTelemetry auto-instrumentation for Symfony

561.6M3](/packages/open-telemetry-opentelemetry-auto-symfony)[traceway/opentelemetry-symfony

Pure-PHP OpenTelemetry instrumentation for Symfony — automatic HTTP, Console, HttpClient, Messenger, Doctrine DBAL, Cache, Twig tracing and Monolog log-trace correlation with response propagation, a lightweight Tracing helper, route templates, and semantic conventions. No C extension required (ext-protobuf recommended for production).

7812.6k](/packages/traceway-opentelemetry-symfony)[friendsofopentelemetry/opentelemetry-bundle

Traces, metrics, and logs instrumentation within your Symfony application

6511.2k](/packages/friendsofopentelemetry-opentelemetry-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
