Shubhamlmp / opentelemetry-php

The OpenTelemetry PHP Library

Home Page:https://opentelemetry.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OpenTelemetry php library

CI Build codecov

This is the monorepo for the main components of OpenTelemetry PHP. The main library is distributed as a complete package: open-telemetry/opentelemetry as well as each component as a separate package. These packages are:


This repository also hosts and distributes generated client code used by individual components as separate packages. These packages are:

For now the generated code packages are meant to be only used by library components internally.


The OpenTelemetry PHP Contrib repository hosts contributions that are not part of the core distribution or components of the library. Typically, these contributions are vendor specific receivers/exporters and/or components that are only useful to a relatively small number of users.

Additional packages, demos and tools are hosted or distributed in the OpenTelemetry PHP organization.


Current Project Status

Current Version

This project currently lives in a alpha status. Our current release is not production ready; it has been created in order to receive feedback from the community.
As long as this project is in alpha status, things may and probably will break once in a while.
We aim to provide backward compatibility (without any guarantee) even for alpha releases, however the library will raise notices indicating breaking changes and what to do about them.
If you don't want these notices to appear or change the error message level, you can do so by calling:

OpenTelemetry\SDK\Common\Dev\Compatibility\Util::setErrorLevel(0)

to turn messages off completely, or (for example)

OpenTelemetry\SDK\Common\Dev\Compatibility\Util::setErrorLevel(E_USER_DEPRECATED)

to trigger only deprecation notices. Valid error levels are 0 (none), E_USER_DEPRECATED, E_USER_NOTICE, E_USER_WARNING and E_USER_ERROR
However (as long as in alpha) it is safer to pin a dependency on the library to a specific version and/or make the adjustments mentioned in the provided messages, since doing otherwise may break things completely for you in the future!


We attempt to keep the OpenTelemetry Specification Matrix up to date in order to show which features are available and which have not yet been implemented.

If you find an inconsistency in the data in the matrix vs. the data in this repository, please let us know in our slack channel and we'll get it rectified.


Communication

Most of our communication is done on CNCF Slack in the channel otel-php. To sign up, create a CNCF Slack account here

Our meetings are held weekly on zoom on Wednesdays at 10:30am PST / 1:30pm EST.
A Google calendar invite with the included zoom link can be found here

Our open issues can all be found in the GitHub issues tab. Feel free to reach out on Slack if you have any additional questions about these issues; we are always happy to talk through implementation details.

Requirements

The library and all separate packages requires a PHP version of 7.4.x, 8.0.x or 8.1.x

Dependencies


REQUIRED DEPENDENCIES

1) Install PSR17/18 implementations

The SDK and Contrib packages have a dependency on both a HTTP Factories (PSR17) and a php-http/async-client implementation. You can find appropriate composer packages implementing given standards on packagist.org. Follow this link to find a PSR17 (HTTP factories) implementation, and this link to find a php-http/async-client implementation.


OPTIONAL DEPENDENCIES

1) Install PHP ext-grpc

The PHP gRPC extension is only needed, if you want to use the OTLP GRPC Exporter from the Contrib package.

Three ways to install the gRPC extension are described below. Keep in mind, that whatever way to install the extension you choose, the compilation can take up to 10-15 minutes. (As an alternative you can search for a pre-compiled extension binary for your OS and PHP version, or you might be lucky and the package manager of your OS provides a package for the extension)

  • Installation with pecl installer (which should come with your PHP installation):
[sudo] pecl install grpc
  • Installation with pickle installer (which you can find here):
[sudo] pickle install grpc
  • Manually compiling the extension, which is not really complicated either, but you should know what you are doing, so we won't cover it here.

Notice: The artifact of the gRPC extension can be as large as 100mb (!!!), Some 'hacks' to reduce that size, are mentioned in this thread. Use at your own risk.

2) Install PHP ext-mbstring

The library's components will load the symfony/polyfill-mbstring package, but for better performance you should install the PHP mbstring extension. You can use the same install methods as described for the gRPC extension above, however most OS` package managers provide a package for the extension.

3) Install PHP ext-zlib

In order to use compression in HTTP requests you should install the PHP zlib extension. You can use the same install methods as described for the gRPC extension above, however most OS` package managers provide a package for the extension.

4) Install PHP ext-ffi

Experimental support for using fibers in PHP 8.1 for Context storage requires the ffi extension, and can be enabled by setting the OTEL_PHP_FIBERS_ENABLED environment variable to a truthy value (1, true, on).

Using fibers with non-CLI SAPIs may require preloading of bindings. One way to achieve this is setting ffi.preload to src/Context/fiber/zend_observer_fiber.h and setting opcache.preload to vendor/autoload.php.

5) Install PHP ext-protobuf

The PHP protobuf extension is optional when using either the OTLPHttp or OTLPGrpc exporters from the Contrib package.

The protobuf extension makes both exporters more performant. Note that protobuf 3.20.0+ is required for php 8.1 support


Installation

The recommended way to install the library's packages is through Composer:

Install Composer using the installation instructions and add

 "minimum-stability": "dev"

To your project's composer.json file, as this library has not reached a stable release status yet.

Getting Started with OpenTelemetry

To install the complete library with all packages you can run:

$ composer require open-telemetry/opentelemetry

This is perfect for trying out our examples or demos.

Using OpenTelemetry in an Application

Your application should only depend on Interfaces provided by the API package:

$ composer require open-telemetry/api

In the best case you will use Dependency Inversion and write an adapter to not depend on the API directly.

Make sure your application works with a dependency on the API only, however to make really use of the library you want to install the SDK package and probably the Contrib package as well:

$ composer require open-telemetry/sdk

or

$ composer require open-telemetry/sdk open-telemetry/sdk-contrib

Make sure any SDK or Contrib code is set up by your configuration, bootstrap, dependency injection, etc.

Using OpenTelemetry to instrument a Library

Your library should only depend on Interfaces provided by the API package:

$ composer require open-telemetry/api

For development and testing purposes you also want to install SDK and Contrib packages:

$ composer require --dev open-telemetry/sdk open-telemetry/sdk-contrib

User Quickstarts

Framework integrations

Examples

Trace

You can use the examples/AlwaysOnZipkinExample.php file to test out the reference implementation we have for zipkin. This example performs a sample trace with a grouping of 5 spans and POSTs the result to a local zipkin instance.

You can also use the examples/AlwaysOnJaegerExample.php file to test out the reference implementation we have for Jaeger. This example performs a sample trace with a grouping of 5 spans and POSTs the result to a local Jaeger instance.

If you'd like a no-fuss way to test this out with docker and docker-compose, you can perform the following simple steps:

  1. Install the necessary dependencies by running make install.
  2. Execute the example trace using make trace examples.

Exported spans can be seen in zipkin at http://127.0.0.1:9411

Exported spans can also be seen in jaeger at http://127.0.0.1:16686

Metrics

You can use the examples/prometheus/PrometheusMetricsExample.php file to test out the reference implementation we have. This example will create a counter that will be scraped by local Prometheus instance.

The easy way to test the example out with docker and docker-compose is:

  1. Run make metrics-prometheus-example. Make sure that local ports 8080, 6379 and 9090 are available.

  2. Open local Prometheus instance: http://localhost:9090

  3. Go to Graph section, type "opentelemetry_prometheus_counter" in the search field or select it in the dropdown menu. You will see the counter value. Every other time you run make metrics-prometheus-example will increment the counter but remember that Prometheus scrapes values once in 10 seconds.

  4. In order to stop docker containers for this example just run make stop-prometheus

Versioning

Versioning rationale can be found in the Versioning Documentation

Development

See our Development README

About

The OpenTelemetry PHP Library

https://opentelemetry.io

License:Apache License 2.0


Languages

Language:PHP 98.5%Language:Makefile 0.6%Language:Shell 0.5%Language:Jinja 0.2%Language:Dockerfile 0.2%Language:C 0.0%