2017 © Pedro Peláez
 

library opencensus

OpenCensus Trace Client for PHP

image

opencensus/opencensus

OpenCensus Trace Client for PHP

  • Thursday, July 19, 2018
  • by chingor13
  • Repository
  • 32 Watchers
  • 93 Stars
  • 6,521 Installations
  • PHP
  • 4 Dependents
  • 1 Suggesters
  • 17 Forks
  • 10 Open issues
  • 28 Versions
  • 98 % Grown

The README.md

Warning, (*1)

OpenCensus and OpenTracing have merged to form OpenTelemetry, which serves as the next major version of OpenCensus and OpenTracing., (*2)

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, will be archived on July 31st, 2023. We encourage users to migrate to OpenTelemetry by this date., (*3)

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., (*4)

OpenCensus for PHP - A stats collection and distributed tracing framework

Census 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., (*5)

CircleCI Packagist PHP-Version, (*6)

Installation & basic usage

  1. Install the opencensus/opencensus package using composer:, (*7)

    $ composer require opencensus/opencensus:~0.2
    

    IMPORTANT: Please ensure your version is >= 0.2.0. There is a potential security vulnerability in < 0.2.0., (*8)

  2. [Optional]: Install the opencensus extension from PECL:, (*9)

    $ pecl install opencensus-alpha
    

    Enable the extension in your php.ini:, (*10)

    extension=opencensus.so
    
  3. Initialize a tracer for your application:, (*11)

    use OpenCensus\Trace\Tracer;
    use OpenCensus\Trace\Exporter\EchoExporter;
    
    Tracer::start(new EchoExporter());
    

Usage

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

Closure/Callable (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

// 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

Samplers

You can specify different samplers when initializing a tracer. The default sampler is the AlwaysSampleSampler which will attempt to trace all requests., (*13)

The provided samplers are:, (*14)

Class Description
NeverSampleSampler Never trace any requests
AlwaysSampleSampler Trace all requests
MultiSampler Check multiple samplers
QpsSampler Trace X requests per second. Requires a PSR-6 cache implementation
ProbabilitySampler Trace X percent of requests.

If you would like to provide your own sampler, create a class that implements SamplerInterface., (*15)

Exporters

You can choose different exporters to send the collected traces to., (*16)

The provided exporters are:, (*17)

Class Description Dependency
EchoExporter Output the collected spans to stdout
FileExporter Output JSON encoded spans to a file
JaegerExporter Report traces to Jaeger server via Thrift over UDP opencensus/opencensus-exporter-jaeger
LoggerExporter Exporter JSON encoded spans to a PSR-3 logger
NullExporter No-op
OneLineEchoExporter Output the collected spans to stdout with one-line
StackdriverExporter Report traces to Google Cloud Stackdriver Trace opencensus/opencensus-exporter-stackdriver
ZipkinExporter Report collected spans to a Zipkin server opencensus/opencensus-exporter-zipkin

If you would like to provide your own reporter, create a class that implements ExporterInterface., (*18)

Versioning

Packagist, (*19)

This library follows Semantic Versioning., (*20)

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

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., (*22)

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., (*23)

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

Current Status: Alpha, (*25)

Contributing

Contributions to this library are always welcome and highly encouraged., (*26)

See CONTRIBUTING for more information on how to get started., (*27)

Releasing

See RELEASING for more information on releasing new versions., (*28)

License

Apache 2.0 - See LICENSE for more information., (*29)

Disclaimer

This is not an official Google product., (*30)

The Versions

16/05 2018
14/05 2018
23/03 2018
23/03 2018
22/11 2017

dev-example-apps

dev-example-apps

OpenCensus Trace Client for PHP

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Jeff Ching

23/10 2017

dev-ext_release

dev-ext_release

OpenCensus Trace Client for PHP

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Jeff Ching

13/09 2017

dev-sampler-documentation

dev-sampler-documentation

OpenCensus Trace Client for PHP

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Jeff Ching

25/08 2017

dev-binary-propagation

dev-binary-propagation

OpenCensus Trace Client for PHP

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Jeff Ching