PHPackages                             laratel/opentelemetry - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. laratel/opentelemetry

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

laratel/opentelemetry
=====================

A Laravel package for OpenTelemetry tracing, metrics, and logging integration.

v1.5(6mo ago)13241MITPHPPHP &gt;=8.0

Since Feb 24Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/i-sazzad/laravel-opentelemetry)[ Packagist](https://packagist.org/packages/laratel/opentelemetry)[ RSS](/packages/laratel-opentelemetry/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (5)Versions (8)Used By (0)

OpenTelemetry Laravel Package
=============================

[](#opentelemetry-laravel-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/dd6b52cb50903a34613352b20a52e97112c67752453d8b9a1c298f90205184b9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61726174656c2f6f70656e74656c656d657472792e7376673f7374796c653d666c617426636f6c6f723d626c7565)](https://packagist.org/packages/laratel/opentelemetry)[![Total Downloads](https://camo.githubusercontent.com/53d8e283de4098d56a79d0a58c7167be1d4f72117c33d656ce04db897cf0aaa6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61726174656c2f6f70656e74656c656d657472792e7376673f7374796c653d666c617426636f6c6f723d677265656e)](https://packagist.org/packages/laratel/opentelemetry)

**OpenTelemetry Laravel** is a Laravel package that integrates OpenTelemetry for automatic HTTP request tracing, query tracing, metrics collection, and enhanced logging with contextual trace information.

---

Features
--------

[](#features)

- Automatic HTTP request tracing.
- Automatic database query tracing with detailed SQL metrics.
- Metrics collection for HTTP requests, database queries, and system performance.
- Enhanced logging with contextual trace information.
- Middleware support for seamless integration.
- Customizable configuration.

---

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

[](#requirements)

- PHP &gt;= 8.0
- Laravel &gt;= 9.x
- Dependencies:
    - `open-telemetry/exporter-otlp` ^1.1
    - `open-telemetry/sdk` ^1.1
    - `open-telemetry/transport-grpc` ^1.1

---

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

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require laratel/opentelemetry
```

⚠️ If you encounter the following error:

```
open-telemetry/transport-grpc 1.1.3 requires ext-grpc * -> it is missing from your system.

```

It means the **gRPC PHP extension** is not installed or enabled. You can fix this by:

- Enabling the `grpc` extension in your `php.ini` file:

    ```
    extension=grpc

    ```

    For example: `C:\xampp\php\php.ini` on Windows.
- Restart your web server (Apache, Nginx) or PHP-FPM service after making changes.
- Alternatively, to bypass this requirement during development, use:

    ```
    composer require laratel/opentelemetry --ignore-platform-req=ext-grpc
    ```

---

### 2. Register the Service Provider

[](#2-register-the-service-provider)

Add the service provider to the `providers` array in `config/app.php` (this step is optional if your package uses auto-discovery):

```
'providers' => [
    // Other Service Providers...
    Laratel\Opentelemetry\Providers\OpenTelemetryServiceProvider::class,
],
```

---

### 3. Publish the Configuration File

[](#3-publish-the-configuration-file)

Publish the configuration file to your application:

```
php artisan vendor:publish --provider="Laratel\Opentelemetry\Providers\OpenTelemetryServiceProvider"
```

This will create a configuration file at `config/opentelemetry.php`. Update the settings as needed, such as the OTLP endpoint, excluded routes, and logging configuration.

---

Configuration
-------------

[](#configuration)

### OpenTelemetry Configuration

[](#opentelemetry-configuration)

The `config/opentelemetry.php` file allows you to configure:

- **OTLP Endpoint**: Specify the OTLP collector endpoint for sending telemetry data.
- **Excluded Routes**: Define routes to exclude from tracing or metrics collection.
- **Excluded Queries**: Specify database queries that should not be traced.

---

### Log Channel Configuration

[](#log-channel-configuration)

Add the following configuration to `config/logging.php` for enhanced OpenTelemetry logging:

```
'otel' => [
    'driver' => 'custom',
    'via' => Laratel\Opentelemetry\Logger\OtelLoggerFactory::class,
    'level' => 'debug',
],
```

---

Usage
-----

[](#usage)

Environment Variables
---------------------

[](#environment-variables)

To configure OpenTelemetry via environment variables, include the following in your `.env` file:

```
OTEL_SERVICE_NAME=your_service_name
OTEL_TRACES_SAMPLER=always_on
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
OTEL_EXPORTER_OTLP_ENDPOINT=http://your_otel_collector_endpoint:port
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=production,service.namespace=service_namespace,service.version=1.0,service.instance.id=instance_id
```

---

### Middleware

[](#middleware)

The package provides two middleware for automatic tracing and metrics collection:

1. **`opentelemetry.metrics`**: Collects HTTP and system metrics.
2. **`opentelemetry.trace`**: Captures tracing information for HTTP requests and database queries.

#### Register Middleware in Kernel

[](#register-middleware-in-kernel)

To apply middleware globally, add them to the `$middleware` array in `app/Http/Kernel.php`:

```
protected $middleware = [
    \Laratel\Opentelemetry\Middleware\OpenTelemetryMetricsMiddleware::class,
    \Laratel\Opentelemetry\Middleware\OpenTelemetryTraceMiddleware::class,
];
```

#### Register Middleware Aliases

[](#register-middleware-aliases)

Alternatively, register middleware aliases in the `Kernel` class:

```
protected $routeMiddleware = [
    'opentelemetry.metrics' => \Laratel\Opentelemetry\Middleware\OpenTelemetryMetricsMiddleware::class,
    'opentelemetry.trace' => \Laratel\Opentelemetry\Middleware\OpenTelemetryTraceMiddleware::class,
];
```

#### Use Middleware in Routes

[](#use-middleware-in-routes)

Once aliases are registered, use them in your routes:

```
Route::middleware(['opentelemetry.metrics', 'opentelemetry.trace'])->group(function () {
    Route::get('api/example', function () {
        return response()->json(['message' => 'Tracing and metrics enabled']);
    });
});
```

---

### Logging

[](#logging)

Use the `otel` log channel for enhanced logging with trace context:

```
use Illuminate\Support\Facades\Log;

Log::channel('otel')->info('Test log for OpenTelemetry collector', ['user' => 'example']);
```

Logs will include trace information and be sent to the configured OpenTelemetry collector.

---

### Automatic Query Tracing

[](#automatic-query-tracing)

The package automatically traces database queries. Traces include:

- SQL statements
- Bindings
- Execution times

You can customize which queries to exclude using the `config/opentelemetry.php` file.

---

### Custom Instrumentation

[](#custom-instrumentation)

#### Custom Traces

[](#custom-traces)

Use the `TraceService` to create custom traces:

```
use Laratel\Opentelemetry\Services\TraceService;

$traceService = new TraceService();
$tracer = $traceService->getCustomTracer();

$span = $tracer->spanBuilder('custom-operation')->startSpan();
$span->setAttribute('custom.attribute', 'value');
// Perform some operation
$span->end();
```

---

Exported Metrics
----------------

[](#exported-metrics)

#### HTTP Metrics

[](#http-metrics)

- laratel\_http\_request\_total
- laratel\_http\_status\_code\_total
- laratel\_http\_failed\_requests\_total
- laratel\_http\_request\_latency\_seconds
- laratel\_http\_request\_size\_bytes
- laratel\_http\_response\_size\_bytes
- laratel\_http\_requests\_in\_progress

#### System Metrics

[](#system-metrics)

- laratel\_system\_cpu\_time\_seconds\_total
- laratel\_system\_memory\_usage\_bytes
- laratel\_system\_disk\_total\_bytes
- laratel\_system\_disk\_free\_bytes
- laratel\_system\_disk\_usage\_bytes
- laratel\_application\_uptime\_seconds

#### Network Metrics

[](#network-metrics)

- laratel\_system\_network\_io\_bytes\_total
- laratel\_system\_network\_dropped\_total
- laratel\_system\_network\_errors\_total
- laratel\_network\_inbound\_bytes
- laratel\_network\_outbound\_bytes
- laratel\_active\_network\_connections

#### Database Metrics

[](#database-metrics)

- laratel\_db\_query\_total
- laratel\_db\_query\_latency\_seconds
- laratel\_db\_error\_total

#### Cache Metrics

[](#cache-metrics)

- laratel\_cache\_hit\_total
- laratel\_cache\_miss\_total
- laratel\_cache\_store\_total
- laratel\_cache\_delete\_total

#### Error Metrics

[](#error-metrics)

- laratel\_error\_total

---

Repository for Related Tools and Configurations
-----------------------------------------------

[](#repository-for-related-tools-and-configurations)

Find a complete repository containing Docker Compose file, configuration files for OpenTelemetry Collector, Prometheus, Tempo, Loki, Promtail and Grafana [here](https://github.com/i-sazzad/otel).

---

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

[](#contributing)

Contributions are welcome! Please fork the repository, create a feature branch, and submit a pull request.

---

License
-------

[](#license)

This package is open-source software licensed under the [MIT license](LICENSE).

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance66

Regular maintenance activity

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~48 days

Recently: every ~60 days

Total

6

Last Release

207d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6317a501de643e5fe69806ae46da55b51088300ced52f4e0563c13a485d445bc?d=identicon)[i\_sazzad](/maintainers/i_sazzad)

---

Top Contributors

[![i-sazzad](https://avatars.githubusercontent.com/u/16065339?v=4)](https://github.com/i-sazzad "i-sazzad (40 commits)")

---

Tags

laravellogmetricsopentelemetrytracephpmiddlewarelaravelloggingdebuggingMetricstracingopentelemetrygRPCotlptelemetryobservabilityerror-trackingdistributed-tracingopen-sourceperformance-monitoringevent-driven architecturelaravel-opentelemetryerror logsapplication performancelaratelreal-time monitoringmonitoring toolsrequest tracingAPI monitoringmetrics exporterperformance profilingcloud observabilityscalable monitoringvisualizing performancetelemetry SDKopentelemetry exporterPHP telemetry integrationopen-source observabilitybackend monitoringmicroservices monitoringservice monitoring

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[keepsuit/laravel-opentelemetry

OpenTelemetry integration for laravel

142347.8k](/packages/keepsuit-laravel-opentelemetry)[friendsofopentelemetry/opentelemetry-bundle

Traces, metrics, and logs instrumentation within your Symfony application

638.6k](/packages/friendsofopentelemetry-opentelemetry-bundle)

PHPackages © 2026

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