open-telemetry / opentelemetry-auto-ext-rdkafka
OpenTelemetry auto-instrumentation for ext-rdkafka Kafka Client
Installs: 6 144
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- composer-runtime-api: ^2.0
- ext-opentelemetry: *
- ext-rdkafka: *
- open-telemetry/api: ^1.0
- open-telemetry/sem-conv: ^1.24
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- mockery/mockery: ^1.5
- open-telemetry/sdk: ^1.0
- phan/phan: ^5.0
- phpstan/phpstan: ^1.1
- phpstan/phpstan-mockery: ^1.1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.18.4
- vimeo/psalm: ^5.0
README
This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib.
OpenTelemetry ext-rdkafka auto-instrumentation
Please read https://opentelemetry.io/docs/instrumentation/php/automatic/ for instructions on how to install and configure the extension and SDK.
Overview
Auto-instrumentation hooks are registered via composer. There will be a new span created for each message that is consumed. The goal of this instrumentation is to allow distributed traces to happen across Kafka in PHP. This means that the following should happen:
- A span should be created for each message that is consumed
- The span should be created with the correct parent context- should the inbound message contain a traceparent header
- The span should be ended when the message offset is
committed
- Any messages produced should have the traceparent header injected into the message headers
This is done by hooking into three methods:
\RdKafka\KafkaConsumer::consume
- For span creation and context propagation on inbound messages.\RdKafka\ProducerTopic::producev
- For injecting the traceparent header into the message headers of produced messages.- Note there is an old method called
produce
. This does not support headers, and thus there was no point hooking into this
- Note there is an old method called
\RdKafka\KafkaConsumer::commit
/\RdKafka\KafkaConsumer::commitAsync
- For ending the span when the message offset is committed.
Versions
- Tested on PHP 8.2 and 8.3 with success
Configuration
The extension can be disabled via runtime configuration:
OTEL_PHP_DISABLED_INSTRUMENTATIONS=ext-rdkafka