silpo-tech/trace-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

silpo-tech/trace-bundle

Composer 安装命令:

composer require silpo-tech/trace-bundle

包简介

Trace bundle for Symfony

README 文档

README

CI codecov License: MIT

A Symfony bundle for distributed tracing and request correlation across microservices.

Features

  • Request ID Generation: Automatically generates unique trace IDs for incoming requests
  • Request ID Propagation: Forwards trace IDs to outgoing HTTP requests via Guzzle middleware
  • Logging Integration: Adds trace IDs to Monolog log entries
  • Console Support: Generates trace IDs for console commands
  • Sentry Integration: Enriches Sentry transactions with trace information
  • Message Bus Support: Correlates messages with trace IDs (requires silpo-tech/message-bus-bundle)

Installation

composer require silpo-tech/trace-bundle

Configuration

Add the bundle to your config/bundles.php:

return [
    // ...
    TraceBundle\TraceBundle::class => ['all' => true],
];

Bundle Configuration

Create config/packages/trace.yaml:

trace:
    id_header_name: 'X-Request-Id'        # Header name for trace ID (default)
    id_log_extra_name: 'requestId'        # Log field name for trace ID (default)
    autoconfigure_handlers: true          # Auto-configure Guzzle handlers (default)

Usage

HTTP Requests

The bundle automatically:

  1. Extracts trace ID from incoming request headers (X-Request-Id by default)
  2. Generates a new UUID if no trace ID is present
  3. Adds the trace ID to response headers
  4. Propagates trace ID to outgoing HTTP requests via Guzzle middleware

Logging

Trace IDs are automatically added to all log entries:

$logger->info('Processing user request'); 
// Log will include: {"message": "Processing user request", "extra": {"requestId": "uuid-here"}}

Console Commands

For console commands, a trace ID is automatically generated and available throughout the command execution.

Manual Access

You can access the current trace ID programmatically:

use TraceBundle\Storage\TraceIdStorageInterface;

class YourService
{
    public function __construct(
        private TraceIdStorageInterface $traceIdStorage
    ) {}
    
    public function someMethod(): void
    {
        $traceId = $this->traceIdStorage->get();
        // Use trace ID as needed
    }
}

Integration

Sentry

When sentry/sentry is installed, the bundle automatically enriches Sentry transactions with trace information.

Message Bus

When silpo-tech/message-bus-bundle is installed, trace IDs are automatically propagated through message bus operations.

Requirements

  • PHP ≥8.3
  • Symfony ≥6.4|^7.0

Dependencies

Required

  • symfony/http-kernel
  • symfony/dependency-injection
  • symfony/config
  • ramsey/uuid
  • monolog/monolog
  • guzzlehttp/guzzle
  • symfony/yaml

Optional

  • sentry/sentry - For Sentry integration
  • silpo-tech/message-bus-bundle - For message bus correlation

Testing

composer install
vendor/bin/phpunit

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

This is a proprietary package. Please contact the maintainers for contribution guidelines.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固