Skip to content

Commit

Permalink
Merge pull request #254 from commercetools/newrelic-integration-update
Browse files Browse the repository at this point in the history
DEVX-430 New Relic integration update
  • Loading branch information
barbara79 authored Nov 4, 2024
2 parents 5873513 + 63a44e2 commit 9b058b3
Show file tree
Hide file tree
Showing 65 changed files with 780 additions and 46 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions examples/symfony-app-datadog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Symfony demo app for Datadog

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

## Requirements

- PHP at least 8.1
- Symfony 6
- Docker
- Registration in Datadog

## Installation

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

## 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 Datadog 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/` folder so they can be used in your application.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ controllers:
path: ../src/Controller/
namespace: App\Controller
type: attribute

index:
path: /
methods: GET
controller: App\Controller\IndexController::index

get_categories:
path: /categories
methods: GET
controller: 'App\Controller\CategoryController::getCategories'
controller: App\Controller\CategoryController::getCategories

get_products:
path: /products
methods: GET
defaults:
_controller: 'App\Controller\ProductController::getProducts'
_controller: App\Controller\ProductController::getProducts
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ services:
expose:
- "9000"

nginx:
nginx-datadog:
build:
context: ./docker/nginx
dockerfile: Dockerfile
dockerfile: Dockerfile.datadog
ports:
- "8080:80"
depends_on:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ FROM nginx
COPY symfony.conf /etc/nginx/conf.d/default.conf

# Update the upstream configuration to point to the correct PHP service
RUN echo "upstream php-upstream { server php-datadog:9000; \
# server php-newrelic:9001; \
}" > /etc/nginx/conf.d/upstream.conf
RUN echo "upstream php-upstream { server php-datadog:9000; }" > /etc/nginx/conf.d/upstream.conf


HEALTHCHECK --interval=30s --timeout=5s \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ DD_APM_ENABLED=true
DD_TRACE_CLI_ENABLED=true
DD_TRACE_ENABLED=true
DD_SITE=datadoghq.com
NEWRELIC_KEY=your new relic key
NEWRELIC_APP_NAME=PHP-SDK
NEW_RELIC_AGENT_VERSION= # Specify the New Relic agent version you want

# APP_NAME=PHP-SDK
###< symfony/framework-bundle ###
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions examples/symfony-app-datadog/src/Controller/IndexController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Controller;

use Psr\Log\LoggerInterface;
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;

public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}

/**
* @Route("/", name="index")
*/
public function index(): Response
{
$this->logger->info('Homepage accessed');
return new Response('Welcome to the PHP SDK Demo App');
}
}
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions examples/symfony-app-newrelic/.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-newrelic/.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-newrelic/.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-newrelic/.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 ###
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

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 Datadog and New Relic.
For now, we configured the docker environment for New Relic.

## Requirements

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

## Installation

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

## Using the Symfony Demo app in a Docker Environment

Expand All @@ -37,6 +37,6 @@ For now, we configured the docker environment for Datadog and New Relic.
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/Datadog UI to see the monitoring of the API calls.
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/` folder so they can be used in your application.
17 changes: 17 additions & 0 deletions examples/symfony-app-newrelic/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-newrelic/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-newrelic/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],
];
Loading

0 comments on commit 9b058b3

Please sign in to comment.