承接 eerzho/opentelemetry-auto-class-laravel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

eerzho/opentelemetry-auto-class-laravel

最新稳定版本:v0.1.3

Composer 安装命令:

composer require eerzho/opentelemetry-auto-class-laravel

包简介

Laravel integration for automatic OpenTelemetry tracing via the #[Traceable] attribute

README 文档

README

Version Downloads PHP License

Laravel integration for automatic OpenTelemetry tracing of PHP methods via the #[Traceable] attribute. All classes with the attribute in configured namespaces are instrumented automatically using the ext-opentelemetry hook API.

This is a read-only sub-split. Please open issues and pull requests in the monorepo.

Installation

composer require eerzho/opentelemetry-auto-class-laravel

Optionally, publish the configuration to customize scanned namespaces (default is App\):

php artisan vendor:publish --tag=traceable-config
// config/traceable.php
return [
    'namespaces' => [
        'App\\Services\\',
        'App\\Jobs\\',
        'Domain\\',
    ],
];

Requirements:

Usage

Basic

Add #[Traceable] to a class in the configured namespaces — all public methods will be traced automatically:

namespace App\Services;

use OpenTelemetry\Contrib\Instrumentation\Class\Attribute\Traceable;

#[Traceable]
class OrderService
{
    public function create(array $items): void
    {
        // span "App\Services\OrderService::create" is created automatically
    }

    public function cancel(int $orderId): void
    {
        // span "App\Services\OrderService::cancel" is created automatically
    }
}

Make sure to run composer dump-autoload -o so that all classes appear in the class map.

For full details on how spans are created, argument serialization, and limitations, see opentelemetry-auto-class.

Exclude methods

Use the exclude parameter to skip specific methods from tracing:

namespace App\Services;

use OpenTelemetry\Contrib\Instrumentation\Class\Attribute\Traceable;

#[Traceable(exclude: ['healthCheck', 'getVersion'])]
class PaymentService
{
    public function charge(int $amount, string $currency): void
    {
        // traced
    }

    public function healthCheck(): bool
    {
        // NOT traced
        return true;
    }

    public function getVersion(): string
    {
        // NOT traced
        return '1.0.0';
    }
}

Exclude arguments

By default, all method arguments are captured as span attributes. Use #[Arguments(exclude: [...])] on a method to hide sensitive parameters:

namespace App\Services;

use OpenTelemetry\Contrib\Instrumentation\Class\Attribute\Arguments;
use OpenTelemetry\Contrib\Instrumentation\Class\Attribute\Traceable;

#[Traceable]
class AuthService
{
    #[Arguments(exclude: ['password', 'token'])]
    public function login(string $email, string $password, string $token): void
    {
        // span captures "email" attribute only
        // "password" and "token" are excluded
    }

    public function logout(int $userId): void
    {
        // span captures "userId" attribute (no exclusions)
    }
}

How it works

  1. On boot, the service provider reads namespaces from config/traceable.php
  2. Discovers all classes in those namespaces via Composer's ClassLoader::getClassMap()
  3. Scans discovered classes for #[Traceable] attribute
  4. Registers ext-opentelemetry hooks for matched methods

Disabling instrumentation

To disable tracing at runtime, use the standard OpenTelemetry environment variable:

OTEL_PHP_DISABLED_INSTRUMENTATIONS=class

License

MIT

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固