Skip to content

Commit

Permalink
Merge pull request #271 from commercetools/opentelemetry-integration
Browse files Browse the repository at this point in the history
DEVX-477 some fixes and new APM integration with open telemetry
  • Loading branch information
barbara79 authored Dec 9, 2024
2 parents 65512f0 + 21216b2 commit cf27a99
Show file tree
Hide file tree
Showing 40 changed files with 2,042 additions and 8 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The SDK consists of the following projects:
* `lib/commercetools-history/src`: Contains all generated models and request builders to communicate with the [Change History API](https://docs.commercetools.com/api/history/change-history).

In addition, the SDK has the following directories:
* `examples/symfony-app` : it shows how the PHP SDK can be used in a Symfony application for a Docker environment with NewRelic monitoring enabled.
* `examples/` : One Dockerized Symfony app per APM (New Relic, Datadog, Dynatrace, OpenTelemetry) to demo PHP SDK usage.
* `test/integration` : Integration Tests for the SDK. A good way for anyone using the PHP SDK to understand it further.
* `test/unit` : Unit Tests for
* `lib/commercetools-api-tests` : generated unit test for each class for the api folder
Expand Down Expand Up @@ -957,7 +957,17 @@ To migrate from the 1.x to the 2.x, there is a guideline below:

## Observability

To monitor and observe the SDK, see the official documentation [Observability](https://docs.commercetools.com/sdk/observability), there is a [Demo application](https://github.com/commercetools/commercetools-sdk-php-v2/tree/master/examples/symfony-app) which shows how to monitor the PHP SDK with New Relic and Datadog.
To monitor and observe the SDK, see the official documentation [Observability](https://docs.commercetools.com/sdk/observability), there is a [Demo application](https://github.com/commercetools/commercetools-sdk-php-v2/tree/master/examples/) which shows how to monitor the PHP SDK with New Relic, Datadog, Dynatrace and Open Telemetry.

To monitor and observe the SDK, refer to the official documentation on [Observability](https://docs.commercetools.com/sdk/observability).

The [Demo application](https://github.com/commercetools/commercetools-sdk-php-v2/tree/master/examples/) demonstrates how to monitor the PHP SDK with the following APMs:

- [New Relic](https://github.com/commercetools/commercetools-sdk-php-v2/tree/master/examples/symfony-app-newrelic)
- [Datadog](https://github.com/commercetools/commercetools-sdk-php-v2/tree/master/examples/symfony-app-datadog)
- [Dynatrace](https://github.com/commercetools/commercetools-sdk-php-v2/tree/master/examples/symfony-app-dynatrace)
- [OpenTelemetry](https://github.com/commercetools/commercetools-sdk-php-v2/tree/master/examples/symfony-app-opentelemetry) (configured to work with New Relic for distributed tracing)
Each APM integration is implemented through configuration and can be easily enabled using the provided instructions in the demo app for each platform.

## Documentation

Expand Down
2 changes: 1 addition & 1 deletion examples/symfony-app-datadog/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ services:
image: datadog/agent:latest
environment:
- DD_API_KEY=${DD_API_KEY}
- DD_SITE=datadoghq.com
- DD_SITE=${DD_SITE}
- DD_APM_ENABLED=true
ports:
- "127.0.0.1:8126:8126/tcp"
Expand Down
2 changes: 1 addition & 1 deletion examples/symfony-app-datadog/docker/php/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ DD_API_KEY=your datadog api key
DD_APM_ENABLED=true
DD_TRACE_CLI_ENABLED=true
DD_TRACE_ENABLED=true
DD_SITE=datadoghq.com
DD_SITE=datadoghq.XXX your datadog site

# APP_NAME=PHP-SDK
###< symfony/framework-bundle ###
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

//added just because New Relic<->Symfony needed it
class IndexController extends AbstractController
{
private $logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Specify the appropriate platform for x86_64
FROM php:8.2-fpm

# Install necessary packages and PHP extensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

//added just because New Relic<->Symfony needed it
class IndexController extends AbstractController
{
private $logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

//added just because New Relic<->Symfony needed it
class IndexController extends AbstractController
{
private $logger;
Expand Down
30 changes: 30 additions & 0 deletions examples/symfony-app-opentelemetry/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/*.log
**/*.md
**/*.php~
**/*.dist.php
**/*.dist
**/*.cache
**/._*
**/.dockerignore
**/.DS_Store
**/.git/
**/.gitattributes
**/.gitignore
**/.gitmodules
**/docker-compose.*.yaml
**/docker-compose.*.yml
**/docker-compose.yaml
**/docker-compose.yml
**/Dockerfile
**/Thumbs.db
.github/
docs/
public/bundles/
tests/
var/
vendor/
.editorconfig
.env.*.local
docker/php/.env.sample
.env.local.php
.env.test
72 changes: 72 additions & 0 deletions examples/symfony-app-opentelemetry/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
# Change these settings to your own preference
indent_style = space
indent_size = 4

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{js,html,ts,tsx}]
indent_style = space
indent_size = 2

[*.json]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[*.php]
indent_style = space
indent_size = 4

[*.sh]
indent_style = tab
indent_size = 4

[*.xml{,.dist}]
indent_style = space
indent_size = 4

[*.{yaml,yml}]
indent_style = space
indent_size = 4
trim_trailing_whitespace = false

[.github/workflows/*.yml]
indent_style = space
indent_size = 2

[.gitmodules]
indent_style = tab
indent_size = 4

[.php_cs{,.dist}]
indent_style = space
indent_size = 4

[.travis.yml]
indent_style = space
indent_size = 2

[composer.json]
indent_style = space
indent_size = 4

[docker-compose{,.*}.{yaml,yml}]
indent_style = space
indent_size = 2

[Dockerfile]
indent_style = tab
indent_size = 4
16 changes: 16 additions & 0 deletions examples/symfony-app-opentelemetry/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
* text=auto eol=lf

*.conf text eol=lf
*.html text eol=lf
*.ini text eol=lf
*.js text eol=lf
*.json text eol=lf
*.md text eol=lf
*.php text eol=lf
*.sh text eol=lf
*.yaml text eol=lf
*.yml text eol=lf
bin/console text eol=lf

*.ico binary
*.png binary
10 changes: 10 additions & 0 deletions examples/symfony-app-opentelemetry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

###> symfony/framework-bundle ###
/docker/php/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
42 changes: 42 additions & 0 deletions examples/symfony-app-opentelemetry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Symfony demo app for Open Telemetry

This Demo is to show how PHP SDK can be used in a Symfony application for a Docker environment with monitoring tools enabled.

For now, we configured the docker environment for Open Telemetry.

## Requirements

- PHP at least 8.1
- Symfony 6
- Docker
- Registration in New Relic UI

## Installation

1. Clone/Download the example folder.
2. Navigate to the path `symfony-app-opentelemetry/`.

## Using the Symfony Demo app in a Docker Environment

### Configuring the Demo App

1. Open the Terminal
2. Run `composer install` or `composer update`
3. Copy the [.env.sample](docker/php/.env.sample) file to the root folder renaming it to `.env`. So in the root folder run `cp docker/php/.env.sample .env`.
4. Fill the `.env` file with the missing data.
5. Run `composer dump-env prod`

### Preparing the Docker environment

1. Always in the Root of the project
2. Run `docker compose up`
3. Wait until the environment is running

### Navigate the application

1. Navigate to [http://localhost:8080/products](http://localhost:8080/products) or [http://localhost:8080/categories](http://localhost:8080/categories)
2. The result would be an array objects containing products or categories.
3. If it's not make sure that in Merchant Center in the project key selected (see the environment variable for the client credentials in the point 3 of the Installation section), there would be some data for products and categories.
4. Go in the New Relic UI to see the monitoring of the API calls.

The docker configuration files will be found in the `docker/php` folder and the `docker-compose.yml` in the `symfony-app-opentelemetry/` folder so they can be used in your application.
17 changes: 17 additions & 0 deletions examples/symfony-app-opentelemetry/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php

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

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);
};
67 changes: 67 additions & 0 deletions examples/symfony-app-opentelemetry/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"commercetools/commercetools-sdk": "^9.1",
"symfony/console": "6.2.*",
"symfony/dotenv": "6.2.*",
"symfony/flex": "^2",
"symfony/framework-bundle": "6.2.*",
"symfony/runtime": "6.2.*",
"symfony/yaml": "6.2.*"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"symfony/flex": true,
"symfony/runtime": 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": "*"
},
"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": "6.2.*",
"docker": true
}
}
}
5 changes: 5 additions & 0 deletions examples/symfony-app-opentelemetry/config/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
];
19 changes: 19 additions & 0 deletions examples/symfony-app-opentelemetry/config/packages/cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
framework:
cache:
# Unique name of your app: used to compute stable namespaces for cache keys.
#prefix_seed: your_vendor_name/app_name

# The "app" cache stores to the filesystem by default.
# The data in this cache should persist between deploys.
# Other options include:

# Redis
#app: cache.adapter.redis
#default_redis_provider: redis://localhost

# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
#app: cache.adapter.apcu

# Namespaced pools use the above "app" backend by default
#pools:
#my.dedicated.cache: null
25 changes: 25 additions & 0 deletions examples/symfony-app-opentelemetry/config/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# see https://symfony.com/doc/current/reference/configuration/framework.html
framework:
secret: '%env(APP_SECRET)%'
#csrf_protection: true
http_method_override: false
handle_all_throwables: true

# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
session:
handler_id: null
cookie_secure: auto
cookie_samesite: lax
storage_factory_id: session.storage.factory.native

#esi: true
#fragments: true
php_errors:
log: true

when@test:
framework:
test: true
session:
storage_factory_id: session.storage.factory.mock_file
Loading

0 comments on commit cf27a99

Please sign in to comment.