PHPackages                             opencensus/opencensus - 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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. opencensus/opencensus

AbandonedArchivedLibrary[Debugging &amp; Profiling](/categories/debugging)

opencensus/opencensus
=====================

OpenCensus Trace Client for PHP

v0.7.0(4y ago)1991.6M↑15.7%78[30 issues](https://github.com/census-instrumentation/opencensus-php/issues)[15 PRs](https://github.com/census-instrumentation/opencensus-php/pulls)10Apache-2.0PHPPHP &gt;=7.1

Since Nov 15Pushed 2y ago22 watchersCompare

[ Source](https://github.com/census-instrumentation/opencensus-php)[ Packagist](https://packagist.org/packages/opencensus/opencensus)[ RSS](/packages/opencensus-opencensus/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (26)Used By (10)

> **Warning**
>
> OpenCensus and OpenTracing have merged to form [OpenTelemetry](https://opentelemetry.io), which serves as the next major version of OpenCensus and OpenTracing.
>
> OpenTelemetry has now reached feature parity with OpenCensus, with tracing and metrics SDKs available in .NET, Golang, Java, NodeJS, and Python. **All OpenCensus Github repositories, except [census-instrumentation/opencensus-python](https://github.com/census-instrumentation/opencensus-python), will be archived on July 31st, 2023**. We encourage users to migrate to OpenTelemetry by this date.
>
> To help you gradually migrate your instrumentation to OpenTelemetry, bridges are available in Java, Go, Python, and JS. [**Read the full blog post to learn more**](https://opentelemetry.io/blog/2023/sunsetting-opencensus/).

OpenCensus for PHP - A stats collection and distributed tracing framework
=========================================================================

[](#opencensus-for-php---a-stats-collection-and-distributed-tracing-framework)

> [Census](https://github.com/census-instrumentation) for PHP. Census provides a framework to measure a server's resource usage and collect performance stats. This repository contains PHP related utilities and supporting software needed by Census.

[![CircleCI](https://camo.githubusercontent.com/35bb2f61826429ff7e88e20492e3bf93446210323c01acc46d7f5f2e2ed26970/68747470733a2f2f636972636c6563692e636f6d2f67682f63656e7375732d696e737472756d656e746174696f6e2f6f70656e63656e7375732d7068702e7376673f7374796c653d737667)](https://circleci.com/gh/census-instrumentation/opencensus-php)[![Packagist](https://camo.githubusercontent.com/59c777e12c394bcb451e66ed0d59dc6573bd6418502b56934e22271bcfd049f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f70656e63656e7375732f6f70656e63656e7375732e737667)](https://packagist.org/packages/opencensus/opencensus)[![PHP-Version](https://camo.githubusercontent.com/e8d5ec76f43d2d428012cea5eba73d42968b57051288b1122fb9e0945af4a1f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6f70656e63656e7375732f6f70656e63656e7375732e737667)](https://camo.githubusercontent.com/e8d5ec76f43d2d428012cea5eba73d42968b57051288b1122fb9e0945af4a1f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6f70656e63656e7375732f6f70656e63656e7375732e737667)

- [API Documentation](https://opencensus.io/api/php/api/master/)
- [Integration Documentation](https://opencensus.io/api/php)

Installation &amp; basic usage
------------------------------

[](#installation--basic-usage)

1. Install the `opencensus/opencensus` package using [composer](https://getcomposer.org/):

    ```
    $ composer require opencensus/opencensus:~0.2
    ```

    **IMPORTANT: Please ensure your version is &gt;= 0.2.0**. There is a potential security vulnerability in &lt; 0.2.0.
2. \[Optional\]: Install the `opencensus` extension from [PECL](https://pecl.php.net/):

    ```
    $ pecl install opencensus-alpha
    ```

    Enable the extension in your `php.ini`:

    ```
    extension=opencensus.so
    ```
3. Initialize a tracer for your application:

    ```
    use OpenCensus\Trace\Tracer;
    use OpenCensus\Trace\Exporter\EchoExporter;

    Tracer::start(new EchoExporter());
    ```

Usage
-----

[](#usage)

To add tracing to a block of code, you can use the closure/callable form or explicitly open and close spans yourself.

### Closure/Callable (preferred)

[](#closurecallable-preferred)

```
$pi = Tracer::inSpan(['name' => 'expensive-operation'], function() {
    // some expensive operation
    return calculatePi(1000);
});

$pi = Tracer::inSpan(['name' => 'expensive-operation'], 'calculatePi', [1000]);
```

### Explicit Span Management

[](#explicit-span-management)

```
// Creates a detached span
$span = Tracer::startSpan(['name' => 'expensive-operation']);

// Opens a scope that attaches the span to the current context
$scope = Tracer::withSpan($span);
try {
    $pi = calculatePi(1000);
} finally {
    // Closes the scope (ends the span)
    $scope->close();
}
```

Customization
-------------

[](#customization)

### Samplers

[](#samplers)

You can specify different samplers when initializing a tracer. The default sampler is the `AlwaysSampleSampler` which will attempt to trace all requests.

The provided samplers are:

ClassDescription[NeverSampleSampler](https://opencensus.io/api/php/api/master/OpenCensus/Trace/Sampler/NeverSampleSampler.html)Never trace any requests[AlwaysSampleSampler](https://opencensus.io/api/php/api/master/OpenCensus/Trace/Sampler/NeverSampleSampler.html)Trace all requests[MultiSampler](https://opencensus.io/api/php/api/master/OpenCensus/Trace/Sampler/MultiSampler.html)Check multiple samplers[QpsSampler](https://opencensus.io/api/php/api/master/OpenCensus/Trace/Sampler/NeverSampleSampler.html)Trace X requests per second. Requires a PSR-6 cache implementation[ProbabilitySampler](https://opencensus.io/api/php/api/master/OpenCensus/Trace/Sampler/NeverSampleSampler.html)Trace X percent of requests.If you would like to provide your own sampler, create a class that implements `SamplerInterface`.

### Exporters

[](#exporters)

You can choose different exporters to send the collected traces to.

The provided exporters are:

ClassDescriptionDependency[EchoExporter](https://opencensus.io/api/php/api/master/OpenCensus/Trace/Exporter/EchoExporter.html)Output the collected spans to stdout[FileExporter](https://opencensus.io/api/php/api/master/OpenCensus/Trace/Exporter/FileExporter.html)Output JSON encoded spans to a file[JaegerExporter](https://github.com/census-ecosystem/opencensus-php-exporter-jaeger)Report traces to Jaeger server via Thrift over UDP[opencensus/opencensus-exporter-jaeger](https://packagist.org/packages/opencensus/opencensus-exporter-jaeger)[LoggerExporter](https://opencensus.io/api/php/api/master/OpenCensus/Trace/Exporter/LoggerExporter.html)Exporter JSON encoded spans to a PSR-3 logger[NullExporter](https://opencensus.io/api/php/api/master/OpenCensus/Trace/Exporter/NullExporter.html)No-op[OneLineEchoExporter](https://opencensus.io/api/php/api/master/OpenCensus/Trace/Exporter/OneLineEchoExporter.html)Output the collected spans to stdout with one-line[StackdriverExporter](https://github.com/census-ecosystem/opencensus-php-exporter-stackdriver)Report traces to Google Cloud Stackdriver Trace[opencensus/opencensus-exporter-stackdriver](https://packagist.org/packages/opencensus/opencensus-exporter-stackdriver)[ZipkinExporter](https://github.com/census-ecosystem/opencensus-php-exporter-zipkin)Report collected spans to a Zipkin server[opencensus/opencensus-exporter-zipkin](https://packagist.org/packages/opencensus/opencensus-exporter-zipkin)If you would like to provide your own reporter, create a class that implements `ExporterInterface`.

Versioning
----------

[](#versioning)

[![Packagist](https://camo.githubusercontent.com/59c777e12c394bcb451e66ed0d59dc6573bd6418502b56934e22271bcfd049f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f70656e63656e7375732f6f70656e63656e7375732e737667)](https://packagist.org/packages/opencensus/opencensus)

This library follows [Semantic Versioning](http://semver.org/).

Please note it is currently under active development. Any release versioned 0.x.y is subject to backwards incompatible changes at any time.

**GA**: Libraries defined at a GA quality level are stable, and will not introduce backwards-incompatible changes in any minor or patch releases. We will address issues and requests with the highest priority.

**Beta**: Libraries defined at a Beta quality level are expected to be mostly stable and we're working towards their release candidate. We will address issues and requests with a higher priority.

**Alpha**: Libraries defined at an Alpha quality level are still a work-in-progress and are more likely to get backwards-incompatible updates.

**Current Status:** Alpha

Contributing
------------

[](#contributing)

Contributions to this library are always welcome and highly encouraged.

See [CONTRIBUTING](CONTRIBUTING.md) for more information on how to get started.

Releasing
---------

[](#releasing)

See [RELEASING](RELEASING.md) for more information on releasing new versions.

License
-------

[](#license)

Apache 2.0 - See [LICENSE](LICENSE) for more information.

Disclaimer
----------

[](#disclaimer)

This is not an official Google product.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity57

Moderate usage in the ecosystem

Community38

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.5% of commits — single point of failure

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 ~76 days

Recently: every ~282 days

Total

18

Last Release

1813d ago

PHP version history (3 changes)v0.0.4PHP &gt;=5.5

v0.5.0PHP &gt;=5.6

v0.6.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8713415b20b4be4cec8f8b22741e3cd05f76eee9e38de1de5bf32727349b7c5?d=identicon)[bshaffer](/maintainers/bshaffer)

![](https://www.gravatar.com/avatar/0e558232679d4011d41ef3fa24b6a1607a5ff07001d8e1d9b33e61c7aac38f1b?d=identicon)[chingor13](/maintainers/chingor13)

---

Top Contributors

[![chingor13](https://avatars.githubusercontent.com/u/32483?v=4)](https://github.com/chingor13 "chingor13 (116 commits)")[![bpot](https://avatars.githubusercontent.com/u/8415?v=4)](https://github.com/bpot "bpot (4 commits)")[![jcchavezs](https://avatars.githubusercontent.com/u/3075074?v=4)](https://github.com/jcchavezs "jcchavezs (3 commits)")[![MrMage](https://avatars.githubusercontent.com/u/117466?v=4)](https://github.com/MrMage "MrMage (3 commits)")[![hectorj](https://avatars.githubusercontent.com/u/2427959?v=4)](https://github.com/hectorj "hectorj (2 commits)")[![Stantheman](https://avatars.githubusercontent.com/u/394611?v=4)](https://github.com/Stantheman "Stantheman (2 commits)")[![basvanbeek](https://avatars.githubusercontent.com/u/7205296?v=4)](https://github.com/basvanbeek "basvanbeek (2 commits)")[![draffensperger](https://avatars.githubusercontent.com/u/2855507?v=4)](https://github.com/draffensperger "draffensperger (1 commits)")[![albertojgomez](https://avatars.githubusercontent.com/u/6017906?v=4)](https://github.com/albertojgomez "albertojgomez (1 commits)")[![bshaffer](https://avatars.githubusercontent.com/u/103941?v=4)](https://github.com/bshaffer "bshaffer (1 commits)")[![castaneai](https://avatars.githubusercontent.com/u/562795?v=4)](https://github.com/castaneai "castaneai (1 commits)")[![aabmass](https://avatars.githubusercontent.com/u/1510004?v=4)](https://github.com/aabmass "aabmass (1 commits)")[![ericnorris](https://avatars.githubusercontent.com/u/1906605?v=4)](https://github.com/ericnorris "ericnorris (1 commits)")[![klibbbs](https://avatars.githubusercontent.com/u/3475490?v=4)](https://github.com/klibbbs "klibbbs (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/opencensus-opencensus/health.svg)

```
[![Health](https://phpackages.com/badges/opencensus-opencensus/health.svg)](https://phpackages.com/packages/opencensus-opencensus)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k348.9M2.5k](/packages/symfony-cache)[php-debugbar/php-debugbar

Debug bar in the browser for php application

4.4k21.3M40](/packages/php-debugbar-php-debugbar)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[magento/community-edition

Magento 2 (Open Source)

12.1k52.1k10](/packages/magento-community-edition)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

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