Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaguerre committed Jan 11, 2025
1 parent a255dc2 commit 2dcbfe2
Show file tree
Hide file tree
Showing 136 changed files with 2,666 additions and 632 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example/ export-ignore
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"require-dev": {
"doctrine/dbal": "^3.0",
"friends-of-phpspec/phpspec-expect": "^4.0",
"open-telemetry/transport-grpc": "^1.0",
"open-telemetry/gen-otlp-protobuf": "^1.0",
"open-telemetry/transport-grpc": "^1.0",
"php-http/httplug": "^2.3",
"phpspec/phpspec": "^7.5",
"phpstan/phpstan": "^1.4",
"symfony/framework-bundle": "*",
"symfony/framework-bundle": "^7.1",
"symfony/http-client": "*",
"symfony/messenger": "*",
"symfony/monolog-bundle": "^3.7",
Expand Down Expand Up @@ -69,4 +69,4 @@
"dev-main": "1.0.x-dev"
}
}
}
}
36 changes: 36 additions & 0 deletions example/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
# https://symfony.com/doc/current/configuration/secrets.html
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=
###< symfony/framework-bundle ###

###> symfony/messenger ###
# Choose one of the transports below
MESSENGER_TRANSPORT_DSN=amqp://guest:guest@rabbitmq:5672/%2f/messages
# MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
###< symfony/messenger ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
DATABASE_URL="postgresql://app:!ChangeMe!@postgresql:5432/app?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###
11 changes: 11 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
symfony.lock
composer.lock
###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
21 changes: 21 additions & 0 deletions example/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (!is_dir(dirname(__DIR__).'/vendor')) {
throw new LogicException('Dependencies are missing. Try running "composer install".');
}

if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

return new Application($kernel);
};
92 changes: 92 additions & 0 deletions example/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"type": "project",
"license": "proprietary",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/dbal": "^3",
"doctrine/doctrine-bundle": "^2.13",
"doctrine/doctrine-fixtures-bundle": "^4.0",
"doctrine/orm": "^3.3",
"open-telemetry/exporter-otlp": "^1.2",
"phpdocumentor/reflection-docblock": "^5.6",
"phpstan/phpdoc-parser": "^2.0",
"symfony/amqp-messenger": "7.3.*",
"symfony/console": "7.3.*",
"symfony/dotenv": "7.3.*",
"symfony/flex": "^2",
"symfony/framework-bundle": "7.3.*",
"symfony/http-client": "*",
"symfony/messenger": "7.3.*",
"symfony/monolog-bundle": "^3.10",
"symfony/property-access": "7.3.*",
"symfony/property-info": "7.3.*",
"symfony/runtime": "7.3.*",
"symfony/serializer": "7.3.*",
"symfony/yaml": "7.3.*",
"worldia/instrumentation-bundle": "^1.0@dev"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"symfony/flex": true,
"symfony/runtime": true,
"tbachert/spi": false
},
"bump-after-update": true,
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php73": "*",
"symfony/polyfill-php74": "*",
"symfony/polyfill-php80": "*",
"symfony/polyfill-php81": "*",
"symfony/polyfill-php82": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "7.3.*"
}
},
"repositories": [
{
"type": "path",
"url": "../",
"options": {
"symlink": true
}
}
]
}
9 changes: 9 additions & 0 deletions example/config/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Instrumentation\InstrumentationBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
];
14 changes: 14 additions & 0 deletions example/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
doctrine:
dbal:
url: "%env(resolve:DATABASE_URL)%"
use_savepoints: true
orm:
identity_generation_preferences:
Doctrine\DBAL\Platforms\PostgreSQLPlatform: identity
mappings:
App:
type: attribute
is_bundle: false
dir: "%kernel.project_dir%/src/Doctrine/Entity"
prefix: 'App\Doctrine\Entity'
alias: App
12 changes: 12 additions & 0 deletions example/config/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# see https://symfony.com/doc/current/reference/configuration/framework.html
framework:
secret: "%env(APP_SECRET)%"

messenger:
transports:
async: "%env(MESSENGER_TRANSPORT_DSN)%"
sync: "sync://"

routing:
'App\Messenger\SyncMessage': sync
'App\Messenger\AsyncMessage': async
11 changes: 11 additions & 0 deletions example/config/packages/instrumentation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
instrumentation:
tracing:
doctrine:
instrumentation: true
propagation: true
log_queries: true
metrics:
request:
enabled: true
message:
enabled: true
10 changes: 10 additions & 0 deletions example/config/routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
controllers:
resource:
path: ../src/Controller/
namespace: App\Controller
type: attribute

when@dev:
_errors:
resource: "@FrameworkBundle/Resources/config/routing/errors.xml"
prefix: /_error
14 changes: 14 additions & 0 deletions example/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
_defaults:
autowire: true
autoconfigure: true

App\:
resource: "../src/"
exclude:
- "../src/DependencyInjection/"
- "../src/Doctrine/Entity/"
- "../src/Kernel.php"

Instrumentation\Tracing\Bridge\TraceUrlGeneratorInterface:
class: App\Otel\GrafanaTraceUrlGenerator
37 changes: 37 additions & 0 deletions example/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
include:
- ./docker/telemetry/docker-compose.yaml

services:
caddy:
build:
context: docker/caddy
environment:
- OTEL_SERVICE_NAME=test-app
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
ports:
- "80:80"
volumes:
- ./docker/caddy/Caddyfile:/etc/caddy/Caddyfile
- .:/app/example

php:
build:
context: docker/php
environment:
- OTEL_SERVICE_NAME=test-app
- OTEL_PHP_DETECTORS=none
- OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=Delta
- OTEL_EXPORTER_OTLP_PROTOCOL=http/json
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318
volumes:
- ..:/app

rabbitmq:
image: rabbitmq:alpine

postgresql:
image: postgres:alpine
environment:
POSTGRES_DB: ${POSTGRES_DB:-app}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!}
POSTGRES_USER: ${POSTGRES_USER:-app}
31 changes: 31 additions & 0 deletions example/docker/caddy/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
cache {
default_cache_control no-store
}
}
:80, :443 {
root * /app/example/public

log_append span_name {http.response.header.x-span-name}
log {
output net tcp/otel-collector:54525 {
soft_start
}

format transform `\{"timestamp":"{ts}","service":"{$OTEL_SERVICE_NAME}","scope_name":"caddy","logger":"{logger}","severity":"{level}","msg":"{msg}","service.instance.id":"{system.hostname}","http.response.status_code":"{status}","http.request.method":"{request>method}","url.full":"{request>uri}","http.response.size":"{size}","user_agent.original":"{request>headers>User-Agent>[0]}","network.peer.address":"{request>headers>X-Forwarded-For>[0]:request>remote_ip}","network.protocol.name":"{request>proto}","referer":"{request>headers>Referer>[0]}","latency":"{duration}","cache_hit":"{cacheHit}","span_name":"{span_name}","trace_id":"{traceID}"\}` {
time_format unix_nano
}
}

cache
tracing
update_span_name "x-span-name"

php_fastcgi php:9000 {
trusted_proxies private_ranges
capture_stderr
}

file_server
encode gzip
}
12 changes: 12 additions & 0 deletions example/docker/caddy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM caddy:2.8-builder AS builder

RUN set -e; xcaddy build \
--with github.com/caddyserver/transform-encoder \
--with github.com/cdaguerre/caddy-otel-span-name@fa3a491654ca13ae0cc9ddf86bdff009ec22a0a1 \
--with github.com/caddyserver/cache-handler@v0.15.0 \
;

FROM caddy:2.8 AS caddy

COPY --from=builder /usr/bin/caddy /usr/bin/caddy
COPY ./Caddyfile /etc/caddy/Caddyfile
7 changes: 7 additions & 0 deletions example/docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM php:8.4-fpm-alpine

ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN install-php-extensions @composer amqp pdo_pgsql

WORKDIR /app/example
Loading

0 comments on commit 2dcbfe2

Please sign in to comment.