opencodeco / hyperf-opentelemetry

OpenTelemetry instrumentation for Hyperf framework

Repository from Github https://github.comopencodeco/hyperf-opentelemetryRepository from Github https://github.comopencodeco/hyperf-opentelemetry

hyperf-opentelemetry

Status License PHP Hyperf OpenTelemetry

Instrumentation library for Hyperf applications with OpenTelemetry support.

This library enables instrumentation of Hyperf-based applications for exporting metrics, traces, and logs compatible with the OpenTelemetry standard.


✨ Features

  • πŸ“¦ Ready-to-use with Swoole and Coroutine
  • πŸ“Š Custom metrics support via Meter
  • πŸ“ˆ Trace instrumentation for:
    • HTTP requests (Hyperf\HttpServer)
    • Redis
    • Guzzle
    • SQL queries (Hyperf\Database)
  • ♻️ Integration with Swoole ContextStorage

πŸ“¦ Installation

composer require opencodeco/hyperf-opentelemetry

βš™οΈ Configuration

  1. Publish the configuration file
php bin/hyperf.php vendor:publish opencodeco/hyperf-opentelemetry

Edit the file config/autoload/open-telemetry.php to adjust settings (enable/disable features, OTLP endpoints, resource attributes, etc).

  1. Configure environment variables

Example .env:

OTEL_TRACES_ENDPOINT=http://otelcol:4318/v1/traces
OTEL_METRICS_ENDPOINT=http://otelcol:4318/v1/metrics
  1. Add instrumentation middlewares

config/autoload/middlewares.php:

<?php

declare(strict_types=1);

use Hyperf\OpenTelemetry\Middleware\MetricMiddleware;
use Hyperf\OpenTelemetry\Middleware\TraceMiddleware;

return [
    'http' => [
        MetricMiddleware::class,
        TraceMiddleware::class,
    ],
];

πŸ‘¨β€πŸ’» Development

Build the image

make build

Install dependencies

make install

Run tests

make test

🀝 Contributing

Please see CONTRIBUTING for details.

About

OpenTelemetry instrumentation for Hyperf framework

License:MIT License


Languages

Language:PHP 99.8%Language:Makefile 0.1%Language:Dockerfile 0.1%