Skip to content

Commit f0e6db3

Browse files
authored
Slim and psr-15 auto-instrumentation (#81)
* slim and psr15 auto-instrumentation
1 parent 824c0b7 commit f0e6db3

32 files changed

+1669
-19
lines changed

.github/workflows/php.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ jobs:
1515
matrix:
1616
operating-system: [ubuntu-latest]
1717
php-version: ['7.4', '8.0', '8.1']
18-
project: ['Aws', 'Symfony']
19-
# todo exclude some matrix combinations based on php version requirements
20-
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#excluding-matrix-configurations
18+
project: ['Aws', 'Symfony', 'Instrumentation/Slim', 'Instrumentation/Psr15']
19+
exclude:
20+
- project: 'Instrumentation/Slim'
21+
php-version: 7.4
22+
- project: 'Instrumentation/Psr15'
23+
php-version: 7.4
2124

2225
steps:
2326
- uses: actions/checkout@v3
@@ -27,7 +30,7 @@ jobs:
2730
with:
2831
php-version: ${{ matrix.php-version }}
2932
coverage: xdebug
30-
extensions: ast, grpc
33+
extensions: ast, grpc, otel_instrumentation-open-telemetry/opentelemetry-php-instrumentation@main
3134

3235
- name: Validate composer.json and composer.lock
3336
run: composer validate
@@ -79,10 +82,3 @@ jobs:
7982
- name: Code Coverage
8083
working-directory: src/${{ matrix.project }}
8184
run: bash <(curl -s https://codecov.io/bash) -F ${{ matrix.php-version }}
82-
83-
packages:
84-
uses: opentelemetry-php/gh-workflows/.github/workflows/validate-packages.yml@main
85-
needs: php
86-
with:
87-
matrix_extension: '["ast, json, grpc"]'
88-
install_directory: '~/.test/.packages'

.gitsplit.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ splits:
1010
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-aws.git"
1111
- prefix: "src/Symfony"
1212
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-sdk-bundle.git"
13+
- prefix: "src/Instrumentation/Psr15"
14+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-psr15.git"
15+
- prefix: "src/Instrumentation/Slim"
16+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-slim.git"
1317

1418
# List of references to split (defined as regexp)
1519
origins:

.php-cs-fixer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
$finder = PhpCsFixer\Finder::create()
33
->exclude('vendor')
44
->exclude('var/cache')
5-
->exclude('proto')
65
->in(__DIR__);
76

87
$config = new PhpCsFixer\Config();

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ help: ## Show this help
1111
@echo "example: PROJECT=Aws PHP_VERSION=8.1 make <command>"
1212
@printf "\033[33m%s:\033[0m\n" 'Available commands'
1313
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {printf " \033[32m%-18s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
14-
all: update style packages-composer phan psalm phpstan test ## Everything
14+
all: update style validate phan psalm phpstan test ## Everything
15+
build: ## Build image
16+
$(DOCKER_COMPOSE) build --build-arg PHP_VERSION php
1517
install: ## Install dependencies
1618
$(DC_RUN_PHP) env XDEBUG_MODE=off composer install
1719
update: ## Update dependencies
@@ -20,7 +22,7 @@ test: test-unit test-integration ## Run unit and integration tests
2022
test-unit: ## Run unit tests
2123
$(DC_RUN_PHP) env XDEBUG_MODE=coverage vendor/bin/phpunit --testsuite unit --colors=always --coverage-text --testdox --coverage-clover coverage.clover --coverage-html=tests/coverage/html
2224
test-integration: ## Run integration tests
23-
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/phpunit --testsuite integration --coverage-text --testdox --colors=always
25+
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/phpunit --testsuite integration --testdox --colors=always
2426
test-coverage: ## Run unit tests and generate coverage
2527
$(DC_RUN_PHP) env XDEBUG_MODE=coverage vendor/bin/phpunit --testsuite unit --coverage-html=tests/coverage/html
2628
phan: ## Run phan
@@ -31,12 +33,14 @@ psalm-info: ## Run psalm with info
3133
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/psalm --show-info=true --threads=1
3234
phpstan: ## Run phpstan
3335
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/phpstan analyse --memory-limit=256M
34-
packages-composer: ## Validate composer packages
36+
validate: ## Validate composer file
37+
$(DC_RUN_PHP) env XDEBUG_MODE=off composer validate
38+
packages-composer: ## Validate all composer packages
3539
$(DC_RUN) php env XDEBUG_MODE=off vendor/bin/otel packages:composer:validate
3640
bash: ## Bash shell
3741
$(DC_RUN_PHP) bash
3842
style: ## Run php-cs-fixer
3943
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --using-cache=no -vvv
4044
split: ## git-split dry run
41-
docker-compose -f docker/gitsplit/docker-compose.yaml --env-file ./.env up
45+
${DOCKER_COMPOSE} -f docker/gitsplit/docker-compose.yaml --env-file ./.env up
4246
FORCE:

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
"composer/xdebug-handler": "^2.0",
1414
"open-telemetry/dev-tools": "dev-main"
1515
},
16+
"autoload": {
17+
"psr-4": {
18+
"OpenTelemetry\\Contrib\\Aws\\": "src/Aws/src",
19+
"OpenTelemetry\\Contrib\\Symfony\\": "src/Symfony/src",
20+
"OpenTelemetry\\Contrib\\Instrumentation\\Psr15\\": "src/Instrumentation/Psr15/src",
21+
"OpenTelemetry\\Contrib\\Instrumentation\\Slim\\": "src/Instrumentation/Slim/src"
22+
}
23+
},
1624
"config": {
1725
"sort-packages": true,
1826
"allow-plugins": {

docker-compose.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
version: '3.7'
22
services:
33
php:
4-
image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-7.4}
4+
build:
5+
context: ./docker
6+
dockerfile: Dockerfile
7+
args:
8+
- PHP_VERSION
59
volumes:
610
- ./:/usr/src/myapp
711
user: "${PHP_USER}:root"
812
environment:
913
XDEBUG_MODE: ${XDEBUG_MODE:-off}
1014
XDEBUG_CONFIG: ${XDEBUG_CONFIG:-''}
15+
PHP_IDE_CONFIG: ${PHP_IDE_CONFIG:-''}
1116
zipkin:
1217
image: openzipkin/zipkin-slim
1318
ports:

docker/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
ARG PHP_VERSION=7.4
2+
FROM php:${PHP_VERSION}-cli-alpine as php_build
3+
4+
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
5+
6+
RUN chmod +x /usr/local/bin/install-php-extensions; \
7+
apk add --update binutils; \
8+
install-php-extensions \
9+
ast \
10+
xdebug \
11+
zip \
12+
pcntl \
13+
intl \
14+
@composer \
15+
open-telemetry/opentelemetry-php-instrumentation@main \
16+
; \
17+
# strip debug symbols from extensions to reduce size
18+
find /usr/local/lib/php/extensions -name "*.so" -exec strip --strip-debug {} \;;
19+
20+
FROM php_build
21+
22+
WORKDIR /usr/src/myapp
23+
24+
RUN apk add --no-cache bash git; \
25+
find /usr/local/lib/php/extensions -type d -exec chmod +x -R {} \;; \
26+
addgroup -g "1000" -S php; \
27+
adduser --system \
28+
--gecos "" \
29+
--ingroup "php" \
30+
--uid "1000" \
31+
"php";
32+
33+
USER php

src/Aws/.php-cs-fixer.php

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Aws/.php-cs-fixer.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
$finder = PhpCsFixer\Finder::create()
3+
->exclude('vendor')
4+
->exclude('var/cache')
5+
->exclude('proto')
6+
->in(__DIR__);
7+
8+
$config = new PhpCsFixer\Config();
9+
return $config->setRules([
10+
'concat_space' => ['spacing' => 'one'],
11+
'declare_equal_normalize' => ['space' => 'none'],
12+
'is_null' => true,
13+
'modernize_types_casting' => true,
14+
'ordered_imports' => true,
15+
'php_unit_construct' => true,
16+
'single_line_comment_style' => true,
17+
'yoda_style' => false,
18+
'@PSR2' => true,
19+
'array_syntax' => ['syntax' => 'short'],
20+
'blank_line_after_opening_tag' => true,
21+
'blank_line_before_statement' => true,
22+
'cast_spaces' => true,
23+
'declare_strict_types' => true,
24+
'function_typehint_space' => true,
25+
'include' => true,
26+
'lowercase_cast' => true,
27+
'new_with_braces' => true,
28+
'no_extra_blank_lines' => true,
29+
'no_leading_import_slash' => true,
30+
'echo_tag_syntax' => true,
31+
'no_unused_imports' => true,
32+
'no_useless_else' => true,
33+
'no_useless_return' => true,
34+
'phpdoc_order' => true,
35+
'phpdoc_scalar' => true,
36+
'phpdoc_types' => true,
37+
'short_scalar_cast' => true,
38+
'single_blank_line_before_namespace' => true,
39+
'single_quote' => true,
40+
'trailing_comma_in_multiline' => true,
41+
])
42+
->setRiskyAllowed(true)
43+
->setFinder($finder);
44+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
$finder = PhpCsFixer\Finder::create()
3+
->exclude('vendor')
4+
->exclude('var/cache')
5+
->exclude('proto')
6+
->in(__DIR__);
7+
8+
$config = new PhpCsFixer\Config();
9+
return $config->setRules([
10+
'concat_space' => ['spacing' => 'one'],
11+
'declare_equal_normalize' => ['space' => 'none'],
12+
'is_null' => true,
13+
'modernize_types_casting' => true,
14+
'ordered_imports' => true,
15+
'php_unit_construct' => true,
16+
'single_line_comment_style' => true,
17+
'yoda_style' => false,
18+
'@PSR2' => true,
19+
'array_syntax' => ['syntax' => 'short'],
20+
'blank_line_after_opening_tag' => true,
21+
'blank_line_before_statement' => true,
22+
'cast_spaces' => true,
23+
'declare_strict_types' => true,
24+
'function_typehint_space' => true,
25+
'include' => true,
26+
'lowercase_cast' => true,
27+
'new_with_braces' => true,
28+
'no_extra_blank_lines' => true,
29+
'no_leading_import_slash' => true,
30+
'echo_tag_syntax' => true,
31+
'no_unused_imports' => true,
32+
'no_useless_else' => true,
33+
'no_useless_return' => true,
34+
'phpdoc_order' => true,
35+
'phpdoc_scalar' => true,
36+
'phpdoc_types' => true,
37+
'short_scalar_cast' => true,
38+
'single_blank_line_before_namespace' => true,
39+
'single_quote' => true,
40+
'trailing_comma_in_multiline' => true,
41+
])
42+
->setRiskyAllowed(true)
43+
->setFinder($finder);
44+

0 commit comments

Comments
 (0)