enthusiast / worker-template
Base worker parts
Requires
- php: ^8.4
- ext-pcntl: *
- ext-rdkafka: *
- ext-redis: *
- enqueue/rdkafka: ^0.10.27
- open-telemetry/api: ^1.0
- open-telemetry/sdk: ^1.14
- psr/log: ^2.0 || ^3.0
- yiisoft/yii-console: ^2.4
Requires (Dev)
None
Suggests
- ext-opentelemetry: Required to auto-hook PSR-3 logs onto active span events for Jaeger
Provides
None
Conflicts
None
Replaces
None
README
Sharing common worker parts: instrumentation, queue logic etc.
Shared infra env
OpenBao keys (as ops inject them) are copied onto the app prefix. Call before
config reads $_ENV:
(new \Enthusiast\WorkerTemplate\SharedEnv('API_'))->apply(); (new \Enthusiast\WorkerTemplate\SharedEnv('WORKER_INTEGRATION_'))->apply();
| OpenBao | App (API_ / WORKER_INTEGRATION_ / …) |
|---|---|
KAFKA_BROKERS, KAFKA_SASL_USERNAME, KAFKA_SASL_PASSWORD |
*_KAFKA_BROKERS, *_KAFKA_SASL_* |
REDIS_HOSTS, REDIS_PASSWORD |
*_REDIS_HOSTS, *_REDIS_PASSWORD |
LM_CH_* |
*_CLICKHOUSE_* |
LM_PG_* |
*_POSTGRES_* |
DRAFT_PG_* |
*_DB_DRAFT_* |
PANEL_PG_* |
*_PANEL_POSTGRES_* |
Filled only when the app key is empty. Topics, Redis persistent ids and Svix stay app-local.
The map is SharedEnv::MAP.
Kafka tracing
AbstractBufferedConsumer does not manage spans. Lifecycle is owned by
open-telemetry/opentelemetry-auto-ext-rdkafka:
KafkaConsumer::consume→ start consumer span (+ parent from messagetraceparent)- app processes the message (PSR-3 span-events hook writes to current span)
acknowledge→commit/commitAsync→ end span
Do not call Span::getCurrent()->end() in the consumer loop: it races the commit
hook and leaks context scopes, so later messages inherit the same trace.
PSR-3 → span events (Jaeger-friendly)
Jaeger does not store OTLP Logs / Loki streams. This package can hook every PSR-3
logger call onto the active span as an event (Span::addEvent).
Works alongside open-telemetry/opentelemetry-auto-psr3 (inject / export).
Enable
OTEL_PHP_PSR3_SPAN_EVENTS=true OTEL_PHP_PSR3_SPAN_EVENTS_LEVEL=info
Disable:
OTEL_PHP_DISABLED_INSTRUMENTATIONS=psr3-span-events
Requires ext-opentelemetry. Registered via Composer files autoload
(_register_psr3_span_events.php) — no DI changes in apps.