Skip to content

New Relic CommerceTools Integration PHP. Uses CommerceTools PHP SDK and New Relic PHP Agent

License

Notifications You must be signed in to change notification settings

newrelic-experimental/newrelic-commercetools-integration-php

New Relic Open Source experimental project banner.

New Relic CommerceTools Integration PHP

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.

Requirements

  • PHP at least 8.1
  • Symfony 6
  • Docker
  • New Relic license key
  • CommerceTools client credentials (id and secret)

Installation

  1. Clone/Download the repository.
  2. Navigate to the path root directory.
  3. 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
  1. 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.

Architecture

Containers

The app consists of 3 containers:

  • nginx - nginx web server
  • php - php-fpm container with the Symfony app
  • test - container with the test script

Endpoints

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: app_diagram

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.

Monitoring

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

Test script (optional for local testing)

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.

Using the Symfony Demo app in a Docker Environment

Configuring the Demo App

  1. Open the Terminal
  2. Run composer dump-env prod
  3. Run composer install or composer update

Preparing the Docker environment

  1. Always in the Root of the project
  2. For apple silicon hosted builds uncomment platform: linux/amd64 in the docker-compose.yml file
  3. Run docker compose up
  4. Wait until the environment is running

Navigate the application (or use the test script mentioned above)

  1. Navigate to http://localhost:8080/products, http://localhost:8080/categories, http://localhost:8080/inventory or http://localhost:8080/orders
  2. The result would be an array objects containing results from CommerceTools API.
  3. 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.
  4. Go in the New Relic UI to see the monitoring of the API calls.

Screen shots from New Relic UI

Screenshot 2023-10-05 at 15 06 56 Screenshot 2023-10-05 at 15 08 01 Screenshot 2023-10-05 at 15 08 44 Screenshot 2023-10-05 at 15 09 07 Screenshot 2023-10-05 at 15 09 37 Screenshot 2023-10-05 at 15 10 21 Screenshot 2023-10-05 at 15 11 48 Screenshot 2023-10-05 at 15 12 34

Support

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.

Contributing

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.

License

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.]

About

New Relic CommerceTools Integration PHP. Uses CommerceTools PHP SDK and New Relic PHP Agent

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published