Skip to content

Commit 4f5ff3e

Browse files
authored
PostgreSQL instrumentation (#415)
* PostgreSQL instrumentation * Instrumentation of asynchronous commands * Large object instrumentation * PostgreSQL instrumentation test * PgSqlTracker tests * Fixed static analysis issues * Added readme
1 parent 40eea2b commit 4f5ff3e

20 files changed

+2318
-2
lines changed

.github/workflows/php.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
'Instrumentation/MySqli',
4242
'Instrumentation/OpenAIPHP',
4343
'Instrumentation/PDO',
44+
'Instrumentation/PostgreSql',
4445
# Sort PSRs numerically.
4546
'Instrumentation/Psr3',
4647
'Instrumentation/Psr6',
@@ -78,6 +79,8 @@ jobs:
7879
php-version: 8.1
7980
- project: 'Instrumentation/PDO'
8081
php-version: 8.1
82+
- project: 'Instrumentation/PostgreSql'
83+
php-version: 8.1
8184
steps:
8285
- uses: actions/checkout@v4
8386

@@ -86,7 +89,7 @@ jobs:
8689
with:
8790
php-version: ${{ matrix.php-version }}
8891
coverage: xdebug
89-
extensions: ast, amqp, grpc, opentelemetry, rdkafka, mysqli
92+
extensions: ast, amqp, grpc, opentelemetry, rdkafka, mysqli, pgsql
9093

9194
- name: Validate composer.json and composer.lock
9295
run: composer validate
@@ -151,6 +154,11 @@ jobs:
151154
run: |
152155
docker compose up mysql -d --wait
153156
157+
- name: Start PostgreSql
158+
if: ${{ matrix.project == 'Instrumentation/PostgreSql' }}
159+
run: |
160+
docker compose up postgresql -d --wait
161+
154162
- name: Run PHPUnit
155163
working-directory: src/${{ matrix.project }}
156164
run: vendor/bin/phpunit

.gitsplit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ splits:
4444
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-openai.git"
4545
- prefix: "src/Instrumentation/PDO"
4646
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-pdo.git"
47+
- prefix: "src/Instrumentation/PostgreSql"
48+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-postgresql.git"
4749
- prefix: "src/Instrumentation/Psr3"
4850
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-psr3.git"
4951
- prefix: "src/Instrumentation/Psr6"

docker-compose.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ services:
1818
MONGODB_HOST: ${MONGODB_HOST:-mongodb}
1919
MONGODB_PORT: ${MONGODB_PORT:-27017}
2020
MYSQL_HOST: ${MYSQL_HOST:-mysql}
21+
POSTGRESQL_HOST: ${POSTGRESQL_HOST:-postgresql}
2122

2223
zipkin:
2324
image: openzipkin/zipkin-slim
@@ -88,3 +89,20 @@ services:
8889
retries: 3
8990
volumes:
9091
- ./docker/mysql/init.sql:/docker-entrypoint-initdb.d/init.sql
92+
93+
postgresql:
94+
image: postgres:17.5
95+
hostname: postgresql
96+
ports:
97+
- "5432:5432/tcp"
98+
environment:
99+
POSTGRES_DB: otel_db
100+
POSTGRES_USER: otel_user
101+
POSTGRES_PASSWORD: otel_passwd
102+
healthcheck:
103+
test: ["CMD-SHELL", "PGPASSWORD=otel_passwd psql -U otel_user -d otel_db -h 127.0.0.1 -c 'SELECT 1'"]
104+
interval: 30s
105+
timeout: 90s
106+
retries: 3
107+
volumes:
108+
- ./docker/postgresql/init.sql:/docker-entrypoint-initdb.d/init.sql

docker/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ RUN install-php-extensions \
88
mongodb \
99
amqp \
1010
rdkafka \
11-
mysqli
11+
mysqli \
12+
pgsql
1213

1314
USER php

docker/postgresql/init.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
CREATE DATABASE otel_db2;
3+
4+
\connect otel_db2;
5+
6+
CREATE USER otel_user2 WITH PASSWORD 'otel_passwd';
7+
8+
GRANT ALL PRIVILEGES ON DATABASE otel_db2 TO otel_user2;
9+
10+
\connect otel_db;
11+
12+
CREATE TABLE users (
13+
id SERIAL PRIMARY KEY,
14+
name VARCHAR(255) NOT NULL,
15+
email VARCHAR(255) UNIQUE NOT NULL,
16+
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
17+
);
18+
19+
INSERT INTO users (name, email) VALUES
20+
('John Doe', 'john.doe@example.com'),
21+
('Jane Smith', 'jane.smith@example.com'),
22+
('Bob Johnson', 'bob.johnson@example.com');
23+
24+
CREATE TABLE products (
25+
id SERIAL PRIMARY KEY,
26+
name VARCHAR(255) NOT NULL,
27+
price NUMERIC(10, 2) NOT NULL,
28+
stock INT NOT NULL DEFAULT 0
29+
);
30+
31+
INSERT INTO products (name, price, stock) VALUES
32+
('Laptop', 999.99, 10),
33+
('Smartphone', 499.99, 25),
34+
('Headphones', 49.99, 50);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
* text=auto
2+
3+
*.md diff=markdown
4+
*.php diff=php
5+
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/.php-cs-fixer.php export-ignore
9+
/phpstan.neon.dist export-ignore
10+
/phpunit.xml.dist export-ignore
11+
/psalm.xml.dist export-ignore
12+
/tests export-ignore
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

0 commit comments

Comments
 (0)