prism-php/opentelemetry

OpenTelemetry telemetry driver for Prism PHP applications.

Fund package maintenance!
sixlive

dev-main 2025-05-24 17:17 UTC

This package is auto-updated.

Last update: 2025-05-24 17:17:18 UTC


README

Total Downloads Latest Stable Version License

Prism OpenTelemetry

OpenTelemetry telemetry driver for Prism PHP applications. This package provides distributed tracing capabilities using OpenTelemetry standards.

Installation

Install the package via Composer:

composer require prism-php/opentelemetry

Configuration

Publish the configuration file:

php artisan vendor:publish --tag="prism-opentelemetry-config"

Add these environment variables to your .env file:

# Enable OpenTelemetry tracing
OPENTELEMETRY_ENABLED=true

# OpenTelemetry collector endpoint
OPENTELEMETRY_ENDPOINT=http://localhost:4318/v1/traces

Prism Integration

Configure Prism to use the OpenTelemetry driver by updating your config/prism.php:

'telemetry' => [
    'enabled' => env('PRISM_TELEMETRY_ENABLED', false),
    'driver' => \Prism\OpenTelemetry\OpenTelemetryDriver::class,
    // ... other telemetry settings
],

Or set it via environment variables:

PRISM_TELEMETRY_ENABLED=true
PRISM_TELEMETRY_DRIVER=\Prism\OpenTelemetry\OpenTelemetryDriver::class

OpenTelemetry Collector Setup

To receive traces, you'll need an OpenTelemetry collector. Here's a basic Docker Compose setup:

version: '3.8'
services:
  otel-collector:
    image: otel/opentelemetry-collector:latest
    command: ["--config=/etc/otel-collector-config.yaml"]
    volumes:
      - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
    ports:
      - "4317:4317"   # OTLP gRPC receiver
      - "4318:4318"   # OTLP HTTP receiver
    depends_on:
      - jaeger

  jaeger:
    image: jaegertracing/all-in-one:latest
    ports:
      - "16686:16686"
    environment:
      - COLLECTOR_OTLP_ENABLED=true

Example collector configuration (otel-collector-config.yaml):

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318

processors:
  batch:

exporters:
  jaeger:
    endpoint: jaeger:14250
    tls:
      insecure: true

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [jaeger]

Testing

composer test

Code Style

composer format

Static Analysis

composer types

License

The MIT License (MIT). Please see License File for more information.