Symfony — Lescopr SDK

Integrate the Lescopr SDK into your Symfony application with the LescoprBundle, Monolog handler, and kernel exception subscriber.

Introduction

The Lescopr PHP SDK integrates with Symfony through LescoprBundle, a dedicated Symfony bundle that wires the Monolog handler and kernel exception subscriber into the Symfony DI container.

Once registered, all Monolog log entries and unhandled kernel exceptions are automatically captured and forwarded to your Lescopr dashboard.

The package is available on Packagist and is compatible with Symfony 4.4+ and PHP 7.4+.

Requirements

Erreur de chargement

Installation

Install the package via Composer:

Then register the bundle in config/bundles.php:

Or if you use Symfony Flex, the bundle is registered automatically.

Terminal
bash
composer require lescopr/lescopr-php
config/bundles.php
php
return [
    // ...
    Lescopr\Integrations\Symfony\LescoprBundle::class => ['all' => true],
];

Configuration

Wire the Monolog handler in config/packages/monolog.yaml:

Register services in config/services.yaml:

Add your keys to .env:

Available options:

  • sdk_key — Your Lescopr SDK key (required)
  • api_key — Your Lescopr API key (required)
  • environment — The current environment (production, staging, development)
config/packages/monolog.yaml
yaml
monolog:
  handlers:
    lescopr:
      type:     service
      id:       Lescopr\Integrations\Symfony\LescoprMonologHandler
      channels: ['!event', '!doctrine']
config/services.yaml
yaml
services:
  Lescopr\Core\Lescopr:
    factory: ['Lescopr\Core\Lescopr', 'fromConfig']
    public: true

  Lescopr\Integrations\Symfony\LescoprMonologHandler:
    arguments: ['@Lescopr\Core\Lescopr']

  Lescopr\Integrations\Symfony\EventSubscriber\KernelExceptionSubscriber:
    arguments: ['@Lescopr\Core\Lescopr']
    tags:
      - { name: kernel.event_subscriber }
.env
dotenv
LESCOPR_SDK_KEY=lsk_xxxx
LESCOPR_API_KEY=lak_xxxx
LESCOPR_ENVIRONMENT=production

Usage

Once configured, all Monolog log entries are forwarded automatically to Lescopr:

Kernel exceptions are captured automatically via KernelExceptionSubscriber, registered as a kernel.event_subscriber.

You can also report exceptions manually anywhere in your application:

src/Controller/OrderController.php
php
use Psr\Log\LoggerInterface;

class OrderController extends AbstractController
{
    public function __construct(private LoggerInterface $logger) {}

    public function checkout(): Response
    {
        $this->logger->info('Checkout started', ['user' => $this->getUser()?->getId()]);
        // ...
    }
}
src/Service/PaymentService.php
php
use Lescopr\Core\Lescopr;

class PaymentService
{
    public function __construct(private Lescopr $lescopr) {}

    public function process(Order $order): void
    {
        try {
            $this->gateway->charge($order);
        } catch (\Throwable $e) {
            $this->lescopr->report($e);
            throw $e;
        }
    }
}

Advanced

CLI initialisation

Initialise the SDK from the command line to auto-detect your framework, register the project, and start the daemon:

Diagnose

Run a full diagnostic including PHP environment, config validity, daemon state, and HTTPS connectivity:

Environment variables

  • LESCOPR_SDK_KEY — SDK key (overrides .lescopr.json)
  • LESCOPR_API_KEY — API key
  • LESCOPR_ENVIRONMENT — development or production
  • LESCOPR_DEBUG=true — Enables verbose output to .lescopr.log
Terminal
bash
./vendor/bin/lescopr init --sdk-key YOUR_SDK_KEY
Terminal
bash
./vendor/bin/lescopr diagnose --details --check-server