Skip to content

Commit c6c4b3c

Browse files
authored
ext-rdkafka instrumentation (#284)
Instrumentation for RdKafka for context propagation
1 parent 0f48d83 commit c6c4b3c

File tree

19 files changed

+1047
-2
lines changed

19 files changed

+1047
-2
lines changed

.github/workflows/php.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
'Aws',
2424
'Context/Swoole',
2525
'Instrumentation/ExtAmqp',
26+
'Instrumentation/ExtRdKafka',
2627
'Instrumentation/Guzzle',
2728
'Instrumentation/HttpAsyncClient',
2829
'Instrumentation/Slim',
@@ -94,6 +95,12 @@ jobs:
9495
php-version: 8.0
9596
- project: 'Instrumentation/ExtAmqp'
9697
php-version: 8.1
98+
- project: 'Instrumentation/ExtRdKafka'
99+
php-version: 7.4
100+
- project: 'Instrumentation/ExtRdKafka'
101+
php-version: 8.0
102+
- project: 'Instrumentation/ExtRdKafka'
103+
php-version: 8.1
97104
- project: 'Instrumentation/OpenAIPHP'
98105
php-version: 7.4
99106
- project: 'Instrumentation/OpenAIPHP'
@@ -112,7 +119,7 @@ jobs:
112119
with:
113120
php-version: ${{ matrix.php-version }}
114121
coverage: xdebug
115-
extensions: ast, amqp, grpc, opentelemetry
122+
extensions: ast, amqp, grpc, opentelemetry, rdkafka
116123

117124
- name: Validate composer.json and composer.lock
118125
run: composer validate
@@ -167,6 +174,11 @@ jobs:
167174
run: |
168175
docker compose up rabbitmq -d --wait
169176
177+
- name: Start Kafka
178+
if: ${{ matrix.project == 'Instrumentation/ExtRdKafka' }}
179+
run: |
180+
KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:29092,PLAINTEXT_HOST://localhost:9092 docker compose up kafka -d --wait
181+
170182
- name: Run PHPUnit
171183
working-directory: src/${{ matrix.project }}
172184
run: vendor/bin/phpunit

.gitsplit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ splits:
1616
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-codeigniter.git"
1717
- prefix: "src/Instrumentation/ExtAmqp"
1818
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-ext-amqp.git"
19+
- prefix: "src/Instrumentation/ExtRdKafka"
20+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-ext-rdkafka.git"
1921
- prefix: "src/Instrumentation/Guzzle"
2022
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-guzzle.git"
2123
- prefix: "src/Instrumentation/HttpAsyncClient"

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"OpenTelemetry\\Contrib\\Aws\\": "src/Aws/src",
1919
"OpenTelemetry\\Contrib\\Context\\Swoole\\": "src/Context/Swoole/src",
2020
"OpenTelemetry\\Contrib\\Instrumentation\\ExtAmqp\\": "src/Instrumentation/ExtAmqp/src",
21+
"OpenTelemetry\\Contrib\\Instrumentation\\ExtRdKafka\\": "src/Instrumentation/ExtRdKafka/src",
2122
"OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\": "src/Instrumentation/Laravel/src",
2223
"OpenTelemetry\\Contrib\\Instrumentation\\HttpAsyncClient\\": "src/Instrumentation/HttpAsyncClient/src",
2324
"OpenTelemetry\\Contrib\\Instrumentation\\IO\\": "src/Instrumentation/IO/src",
@@ -39,6 +40,7 @@
3940
},
4041
"files": [
4142
"src/Instrumentation/ExtAmqp/_register.php",
43+
"src/Instrumentation/ExtRdKafka/_register.php",
4244
"src/Instrumentation/HttpAsyncClient/_register.php",
4345
"src/Instrumentation/IO/_register.php",
4446
"src/Instrumentation/Laravel/_register.php",

docker-compose.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
XDEBUG_CONFIG: ${XDEBUG_CONFIG:-''}
1414
PHP_IDE_CONFIG: ${PHP_IDE_CONFIG:-''}
1515
RABBIT_HOST: ${RABBIT_HOST:-rabbitmq}
16+
KAFKA_HOST: ${KAFKA_HOST:-kafka}
1617

1718
zipkin:
1819
image: openzipkin/zipkin-slim
@@ -42,3 +43,22 @@ services:
4243
retries: 3
4344
ports:
4445
- "5672:5672/tcp"
46+
kafka:
47+
image: confluentinc/cp-kafka:7.2.1
48+
hostname: kafka
49+
ports:
50+
- "9092:9092/tcp"
51+
environment:
52+
KAFKA_PROCESS_ROLES: 'broker,controller'
53+
KAFKA_NODE_ID: 1
54+
KAFKA_ADVERTISED_LISTENERS: ${KAFKA_ADVERTISED_LISTENERS:-PLAINTEXT://kafka:29092,PLAINTEXT_HOST://kafka:9092}
55+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
56+
KAFKA_LISTENERS: 'PLAINTEXT://kafka:29092,CONTROLLER://kafka:29093,PLAINTEXT_HOST://0.0.0.0:9092'
57+
KAFKA_CONTROLLER_LISTENER_NAMES: 'CONTROLLER'
58+
KAFKA_CONTROLLER_QUORUM_VOTERS: '1@kafka:29093'
59+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
60+
command: "bash -c '/tmp/update_run.sh && /etc/confluent/docker/run'"
61+
volumes:
62+
- ./docker/kafka/update_run.sh:/tmp/update_run.sh
63+
64+

docker/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ USER root
66
RUN install-php-extensions \
77
opentelemetry \
88
mongodb \
9-
amqp
9+
amqp \
10+
rdkafka
1011

1112
USER php

docker/kafka/update_run.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This script is required to run kafka cluster (without zookeeper)
2+
#!/bin/sh
3+
4+
# Docker workaround: Remove check for KAFKA_ZOOKEEPER_CONNECT parameter
5+
sed -i '/KAFKA_ZOOKEEPER_CONNECT/d' /etc/confluent/docker/configure
6+
7+
# Docker workaround: Ignore cub zk-ready
8+
sed -i 's/cub zk-ready/echo ignore zk-ready/' /etc/confluent/docker/ensure
9+
10+
# KRaft required step: Format the storage directory with a new cluster ID
11+
echo "kafka-storage format --ignore-formatted -t $(kafka-storage random-uuid) -c /etc/kafka/kafka.properties" >> /etc/confluent/docker/ensure
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* text=auto
2+
3+
*.md diff=markdown
4+
*.php diff=php
5+
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/.phan export-ignore
9+
/.php-cs-fixer.php export-ignore
10+
/phpstan.neon.dist export-ignore
11+
/phpunit.xml.dist export-ignore
12+
/psalm.xml.dist export-ignore
13+
/tests export-ignore
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/

0 commit comments

Comments
 (0)