vortos/vortos-tracing
最新稳定版本:v1.0.0-alpha-76
Composer 安装命令:
composer require vortos/vortos-tracing
包简介
Vortos tracing — OpenTelemetry distributed tracing integration
README 文档
README
The tracing module provides a small framework abstraction with NoOp defaults and OpenTelemetry support for production deployments.
Defaults
TracingAdapter::NoOpis the default and performs no export work.- Development uses
AlwaysOnsampling. - Production uses ratio sampling at
0.1. - Sampling is parent-based and trace-level, so child spans follow the root or remote parent decision.
- Incoming
traceparentheaders are not trusted by default. - HTTP instrumentation avoids query strings.
- Messaging propagation uses W3C trace context headers.
- Baggage is supported for small, non-sensitive, low-cardinality values.
Enable OpenTelemetry
Install the required packages:
composer require open-telemetry/api open-telemetry/sdk open-telemetry/exporter-otlp
Configure OTLP:
use Vortos\Tracing\Config\TracingAdapter; use Vortos\Tracing\Config\TracingSampler; use Vortos\Tracing\DependencyInjection\VortosTracingConfig; return static function (VortosTracingConfig $config): void { $config ->adapter(TracingAdapter::OpenTelemetry) ->service( name: $_ENV['OTEL_SERVICE_NAME'] ?? $_ENV['APP_NAME'] ?? 'checkout-api', version: $_ENV['APP_VERSION'] ?? '', environment: $_ENV['APP_ENV'] ?? 'prod', ) ->otlp( endpoint: $_ENV['OTEL_EXPORTER_OTLP_TRACES_ENDPOINT'] ?? 'http://otel-collector:4318/v1/traces', headers: [], timeoutMs: 2000, ) ->sampler(TracingSampler::Ratio, rate: 0.1) ->trustRemoteContext(false); };
The OpenTelemetry adapter requires the SDK and OTLP exporter. If they are missing, configuration fails instead of silently running without export.
Controller Attributes
use Vortos\Tracing\Attribute\DisableTracing; use Vortos\Tracing\Attribute\TraceWith; #[TraceWith(spanName: 'checkout.place_order', sampleRate: 1.0)] public function checkout(): Response { // ... } #[DisableTracing] public function health(): Response { // ... }
TraceWith customizes the HTTP span name and can override the sample rate for that endpoint. DisableTracing prevents controller-level HTTP span creation.
Baggage
Use baggage only for safe routing context, for example tenant id:
$tracer->setBaggageItem('tenant.id', $tenantId);
Never put PII, secrets, session ids, JWTs, emails, phone numbers, payment data, or high-cardinality values in baggage. Baggage is propagated to downstream services.
统计信息
- 总下载量: 82
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 6
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-25