PHPackages                             nadi-pro/nadi-php - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. nadi-pro/nadi-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nadi-pro/nadi-php
=================

A PHP SDK for Nadi (http://nadi.pro)

2.1.2(3mo ago)05982MITPHPPHP ^8.1 || ^8.2 || ^8.3 || ^8.4

Since Oct 4Pushed 3mo agoCompare

[ Source](https://github.com/nadi-pro/nadi-php)[ Packagist](https://packagist.org/packages/nadi-pro/nadi-php)[ RSS](/packages/nadi-pro-nadi-php/feed)WikiDiscussions 2.0 Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (21)Used By (2)

Nadi PHP Client
===============

[](#nadi-php-client)

[![Latest Version](https://camo.githubusercontent.com/5fbff599fb373856f2dda482e0b8b7c01641d80cbb524e2f20ed615611fa68dc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6e6164692d70726f2f6e6164692d7068703f7374796c653d666c61742d737175617265)](https://github.com/nadi-pro/nadi-php/releases) [![License](https://camo.githubusercontent.com/1836d0898ae5c5743f6520c76da66b5ed6317cbdcf904c0baad8274a84ad4ae3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e6164692d70726f2f6e6164692d7068703f7374796c653d666c61742d737175617265)](LICENSE) [![CI](https://camo.githubusercontent.com/15eb4849c3d616471122437c5c01a353ae95cc3873bfd2d966ac6d32d72180b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e6164692d70726f2f6e6164692d7068702f72756e2d74657374732e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/nadi-pro/nadi-php/actions) [![Packagist Version](https://camo.githubusercontent.com/d272808ab38bcea5c57a35f878328d9582c94772c3b37fd784639861e547359f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6164692d70726f2f6e6164692d7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nadi-pro/nadi-php) [![Packagist Downloads](https://camo.githubusercontent.com/5ae7a29e47b88a39cad9d7af5cbe13dee38eff59e329e2a58e501bc427f7a40a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6164692d70726f2f6e6164692d7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nadi-pro/nadi-php) [![PHP Version](https://camo.githubusercontent.com/e429e3f3f01fdf8de2c0103b9142d6912f729ca8019e3a54be2a201feecbcc19/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6e6164692d70726f2f6e6164692d7068702f7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nadi-pro/nadi-php)

A PHP SDK for application crash/error monitoring with built-in OpenTelemetry support for industry-standard observability.

Documentation
-------------

[](#documentation)

Full documentation is available in the [docs/](docs/README.md) directory:

- [Architecture](docs/01-architecture/README.md) - System design and patterns
- [Development](docs/02-development/README.md) - Developer guides and testing
- [Usage](docs/03-usage/README.md) - Practical integration guides
- [API Reference](docs/04-api/README.md) - Class and interface documentation

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Composer

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

[](#installation)

```
composer require nadi-pro/nadi-php
```

Features
--------

[](#features)

- 🔭 **OpenTelemetry Integration**: Built-in support for OTel semantic conventions
- 📊 **Rich Metrics**: Comprehensive system, runtime, network, and custom metrics
- 🎯 **Smart Sampling**: Multiple sampling strategies including fixed-rate, interval-based, peak-load, and dynamic
- 🚀 **Multiple Transporters**: HTTP API, Local Logging, and OpenTelemetry exporters
- 🔄 **Trace Correlation**: Automatic trace context capture for distributed tracing
- 📦 **Shipper Binary Manager**: Auto-download and manage the Nadi Shipper binary

OpenTelemetry Support
---------------------

[](#opentelemetry-support)

Nadi PHP SDK now includes first-class support for OpenTelemetry (OTel), enabling seamless integration with modern observability platforms like Jaeger, Prometheus, Grafana, Datadog, and New Relic.

### OpenTelemetry Transporter

[](#opentelemetry-transporter)

Configure Nadi to export telemetry data using the OpenTelemetry Protocol (OTLP):

```
use Nadi\Transporter\OpenTelemetry;
use Nadi\Data\Entry;
use Nadi\Data\Type;

// Configure OpenTelemetry transporter
$transporter = new OpenTelemetry();
$transporter->configure([
    'endpoint' => 'http://localhost:4318',  // OTLP endpoint
    'service_name' => 'my-php-app',
    'service_version' => '1.0.0',
]);

// Create an entry
$entry = Entry::make(Type::EXCEPTION, [
    'class' => 'RuntimeException',
    'message' => 'An error occurred',
    'file' => __FILE__,
    'line' => __LINE__,
]);

// Store and send
$transporter->store($entry->toArray());
$transporter->send();
```

### OpenTelemetry Semantic Conventions

[](#opentelemetry-semantic-conventions)

All metrics now follow OTel semantic conventions for consistency and interoperability:

#### System Metrics

[](#system-metrics)

```
use Nadi\Metric\System;

$system = new System();
$metrics = $system->toArray();

// Returns OTel-compliant metrics:
// - system.cpu.load_average.1m
// - system.cpu.load_average.5m
// - system.cpu.load_average.15m
// - system.cpu.logical_count
// - system.memory.usage
// - system.memory.limit
// - system.memory.peak
// - system.filesystem.usage
// - system.filesystem.available
// - system.filesystem.total
```

#### Runtime Metrics

[](#runtime-metrics)

```
use Nadi\Metric\Runtime;

$runtime = new Runtime();
$metrics = $runtime->toArray();

// Returns:
// - process.runtime.name: 'php'
// - process.runtime.version: '8.3.0'
// - process.runtime.description: 'PHP 8.3.0'
// - process.pid: 12345
```

#### Operating System Metrics

[](#operating-system-metrics)

```
use Nadi\Metric\OperatingSystem;

$os = new OperatingSystem();
$metrics = $os->toArray();

// Returns:
// - os.type: 'darwin'
// - os.description: 'Darwin 23.0.0'
// - os.name: 'Darwin'
// - os.version: '23.0.0'
// - host.name: 'macbook-pro.local'
// - host.arch: 'x86_64'
```

#### Network Metrics

[](#network-metrics)

```
use Nadi\Metric\Network;

$network = new Network();
$metrics = $network->toArray();

// Returns:
// - host.name: 'server-01'
// - host.id: 'unique-machine-id'
```

### Trace Context Correlation

[](#trace-context-correlation)

Nadi automatically captures OpenTelemetry trace context for distributed tracing:

```
use Nadi\Data\Entry;
use Nadi\Data\Type;

// Entry automatically captures active OTel span context
$entry = Entry::make(Type::EXCEPTION, [
    'class' => 'DatabaseException',
    'message' => 'Connection failed',
]);

// Or set manually
$entry->setTraceId('4bf92f3577b34da6a3ce929d0e0e4736');
$entry->setSpanId('00f067aa0ba902b7');

// Trace IDs are included in exported data
$data = $entry->toArray();
// Contains: trace_id, span_id
```

### Connecting to Observability Backends

[](#connecting-to-observability-backends)

#### Jaeger

[](#jaeger)

```
$transporter->configure([
    'endpoint' => 'http://jaeger:4318',
    'service_name' => 'my-app',
]);
```

#### Grafana Tempo

[](#grafana-tempo)

```
$transporter->configure([
    'endpoint' => 'http://tempo:4318',
    'service_name' => 'my-app',
]);
```

#### Local Development (Jaeger All-in-One)

[](#local-development-jaeger-all-in-one)

```
# Run Jaeger
docker run -d --name jaeger \
  -p 4318:4318 \
  -p 16686:16686 \
  jaegertracing/all-in-one:latest

# Access UI at http://localhost:16686
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

**Note:** OpenTelemetry tests may show connection warnings if Jaeger is not running locally. These are expected and the tests will still pass. To run tests with a live OTLP endpoint, start Jaeger first:

```
# Start Jaeger for testing
docker run -d --name jaeger -p 4318:4318 -p 16686:16686 jaegertracing/all-in-one:latest

# Run tests
composer test

# Stop Jaeger
docker stop jaeger && docker rm jaeger
```

Adding New Metric
-----------------

[](#adding-new-metric)

You can add a new metric as you see fit to your application / framework.

Do take note, all metrics will be converted to associative array.

In order to create your own metrics, you need to extend the class `Nadi\Metric\Base` and implement your metrics details in `metrics()` method which always returns an array. You may need to define as a dot notation in your metric.

However, Nadi will convert to the associative array.

Following is an example for capture Http request for Laravel framework.

```
