Skip to main content

PHP Opentelemetry Instrumentation

Introduction to SigNoz for PHP

SigNoz can help you monitor your PHP applications for application-related metrics like latency, request per second, error rates, etc. It can also monitor infrastructure metrics like CPU utilization and memory usage.

You can set alerts on metrics of your choice to stay on top of any issues arising in your deployed application.

Getting started for PHP with SigNoz

SigNoz uses OpenTelemetry for enabling your application code to generate telemetry data. OpenTelemetry provides a vendor-neutral specification  to instrument your application so that you can export data to any backend of your choice, such as SigNoz.

Let us see how to instrument your application with OpenTelemetry, so that you can visualize the data with SigNoz.

Instrumenting a sample PHP application with OpenTelemetry

Install the following dependencies using composer

  • open-telemetry/sdk
  • open-telemetry/exporter-otlp
  • php-http/guzzle7-adapter
  • guzzlehttp/psr7

Import the required modules

use GuzzleHttp\Client;
use OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory;
use OpenTelemetry\Contrib\Otlp\SpanExporter;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;

Define envs

Optionally, you can skip them in code and pass them via command line process args.

The IP of SigNozwill be localhost if you are running SigNoz on local. If you are not running SigNoz on the local machine, then please use the IP of the machine where SigNoz is installed.


Initialise Exporter and Tracer module

$transport = (new OtlpHttpTransportFactory())->create('http://<IP of SigNoz>:4318/v1/traces', 'application/x-protobuf');

$tracerProvider = new TracerProvider(
new SimpleSpanProcessor(
new SpanExporter($transport)
$tracer = $tracerProvider->getTracer('io.signoz.php.example');

Create and activate root span

$root = $span = $tracer->spanBuilder('root')->startSpan();
$scope = $span->activate();

Start your first span, add attributes and events.

$span = $tracer->spanBuilder('loop-' . $i)->startSpan();

$span->setAttribute('remote_ip', '')
->setAttribute('country', 'USA');

$span->addEvent('found_login' . $i, new Attributes([
'id' => $i,
'username' => 'otuser' . $i,
$span->addEvent('generated_session', new Attributes([
'id' => md5((string) microtime(true)),

End the spans in hierarchical order


Run and Visualize on SigNoz

OTEL_SERVICE_NAME=signoz-php-app php FILENAME.php
SigNoz dashboard showing Trace Detail with tags
Detailed view of the Trace showing attached attributes/tags to the spans.
SigNoz dashboard showing Trace Detail with events
Detailed view of the Trace showing attached events to spans.

Sample PHP application​

We have included a sample PHP application with at GitHub

Feel free to use this repo to test out OpenTelemetry instrumentation and how to send telemetry data to SigNoz.

Frequently Asked Questions

  1. How to find what to use in IP of SigNoz if I have installed SigNoz in Kubernetes cluster?

    Based on where you have installed your application and where you have installed SigNoz, you need to find the right value for this. Please use this grid to find the value you should use for IP of SigNoz

  2. I am sending data from my application to SigNoz, but I don't see any events or graphs in the SigNoz dashboard. What should I do?

    This could be because of one of the following reasons:

    1. Your application is generating telemetry data, but not able to connect with SigNoz installation

      Please use this troubleshooting guide to find if your application is able to access SigNoz installation and send data to it.

    2. Your application is not actually generating telemetry data

      Please check if the application is generating telemetry data first. You can use Console Exporter to just print your telemetry data in console first. Join our Slack Community if you need help on how to export your telemetry data in console

    3. Your SigNoz installation is not running or behind a firewall

      Please double check if the pods in SigNoz installation are running fine. docker ps or kubectl get pods -n platform are your friends for this.