This Demo is to show how PHP CommerceTools SDK can be used in a PHP (Symfony) application (in a Docker environment) with NewRelic monitoring enabled.
- PHP at least 8.1
- Symfony 6
- Docker
- New Relic license key
- CommerceTools client credentials (id and secret)
- Clone/Download the repository.
- Navigate to the path
root
directory. - Register the client credentials in environment variables
.env
file
APP_CTP_CLIENT_ID= your CTP_CLIENT_ID
APP_CTP_CLIENT_SECRET= your CTP_CLIENT_SECRET
APP_CTP_PROJECT_KEY= your CTP_PROJECT_KEY
APP_CTP_REGION=your CTP_CLOUD_REGION
- Along with New Relic license key in the same file
.env
file
NEWRELIC_KEY=your New Relic license key
NEWRELIC_APP_NAME=newrelic-commercetools-php-integration
See the env.example
file for reference.
The app consists of 3 containers:
nginx
- nginx web serverphp
- php-fpm container with the Symfony apptest
- container with the test script
The app has 6 endpoints:
/
- healthcheck endpoint/products
- endpoint to get products from CommerceTools/categories
- endpoint to get categories from CommerceTools/inventroy
- endpoint to get inventory from CommerceTools/orders
- endpoint to get orders from CommerceTools
The application's architecture simplified diagram is shown below:
New Relic monitoring is enabled for the php
container. The nginx
container is not monitored. The test
container is used to run the test script.
New Relinc PHP Agent is installed in the php
container. The agent is configured in the newrelic.ini
file located in the docker/php
directory.
New Relic hooks up to CommerceTools SDK via Guzzle HTTP client which is used internally by the SDK and monitored by the New Relic agent by default.
New Relic will monitor the following:
- All application performance metrics
- PHP application errors
- PHP application transactions
- Calls to CommerceTools API (external services) via the PHP SDK (Guzzle HTTP client)
- and more
Uncomment the following lines in the docker-compose.yml
file to run the test script in a separate container
# test:
# build:
# context: .
# dockerfile: docker/test/Dockerfile
# command: ["./test_script.sh"]
# depends_on:
# nginx:
# condition: service_healthy
This will run the test_script.sh
script in the test
container. The script will make a request to the various endpoint in order to visualise the New Relic monitoring.
- Open the Terminal
- Run
composer dump-env prod
- Run
composer install
orcomposer update
- Always in the Root of the project
- For apple silicon hosted builds uncomment
platform: linux/amd64
in thedocker-compose.yml
file - Run
docker compose up
- Wait until the environment is running
- Navigate to http://localhost:8080/products, http://localhost:8080/categories, http://localhost:8080/inventory or http://localhost:8080/orders
- The result would be an array objects containing results from CommerceTools API.
- If it's not please 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.
- Go in the New Relic UI to see the monitoring of the API calls.
New Relic hosts and moderates an online forum where customers can interact with New Relic employees as well as other customers to get help and share best practices.
We encourage your contributions to improve [project name]! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at opensource@newrelic.com.
A note about vulnerabilities
As noted in our security policy, New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.
If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through HackerOne.
New Relic CommerceTools Integration PHP is licensed under the Apache 2.0 License.
[If applicable: The [project name] also uses source code from third-party libraries. You can find full details on which libraries are used and the terms under which they are licensed in the third-party notices document.]