Skip to Content

Treblle Docs

Integrate TreblleSDKsPHPTreblle with Symfony

The official Treblle SDK for JavaScript frameworks including Symfony. Seamlessly integrate Treblle to manage communication with your dashboard, send errors, and secure sensitive data.

Treblle with Symfony

Requirements

  • PHP 7.4+
  • Symfony 4.4+

Installation

To install the SDK you will need to be using Composer  in your api. To install it please see the docs .

composer require treblle/treblle-symfony

Enable the Bundle

Enable it by adding it to the list of registered bundles depending on the Symfony version you’re using.

// config/bundles.php { return [ // ... new Treblle\Symfony\TreblleBundle(), ]; }

Configuration of the SDK

Configure the SDK by adding the following snippet to your api configuration. If you have Symfony 3.4 add it to app/config/config_prod.yml. For Symfony 4 or newer add the value to config/packages/treblle.yaml.

treblle: sdk_token: "%env(TREBLLE_SDK_TOKEN)%" api_key: "%env(TREBLLE_API_KEY)%" debug: false masked: - password - api_key - secret endpoint_url: "https://rocknrolla.treblle.com" // optional

Overriding data providers

Treblle SDK allows you to take over control over how the data is collected, processed, and sent to the Treblle service.

By default, the SDK will take all values from the masked configuration key and combine it with well-known keys such as password or ssn to compile a list of sensitive information. These values will never be sent in a plain text, but rather will be masked.

Default service configuration for Treblle looks like this:

services: _defaults: autowire: true autoconfigure: true treblle-client: class: GuzzleHttp\Client Treblle\Treblle: factory: [Treblle\Symfony\DependencyInjection\TreblleFactory, 'createTreblle'] arguments: $client: '@treblle-client' Treblle\PayloadAnonymizer: factory: [Treblle\Symfony\DependencyInjection\TreblleFactory, 'createAnonymizer'] Treblle\Symfony\DataProvider: ~ Treblle\Symfony\EventSubscriber\TreblleEventSubscriber: ~ Treblle\InMemoryErrorDataProvider: ~ Treblle\PhpHelper: ~ Treblle\PhpLanguageDataProvider: ~ Treblle\SuperglobalsServerDataProvider: ~ Treblle\Contract\ErrorDataProvider: '@Treblle\InMemoryErrorDataProvider' Treblle\Contract\LanguageDataProvider: '@Treblle\PhpLanguageDataProvider' Treblle\Contract\RequestDataProvider: '@Treblle\Symfony\DataProvider' Treblle\Contract\ResponseDataProvider: '@Treblle\Symfony\DataProvider' Treblle\Contract\ServerDataProvider: '@Treblle\SuperglobalsServerDataProvider'

Tip

If you want to replace any component, feel free to provide your own implementation and register it in the DI container. When you alias the interface to point to your implementation instead of the default one, Treblle will use it.

Example: Override Request Data Collection

We want to override how Request data is collected and passed to Treblle

  1. We implement our own service satisfying the Treblle\Contract\RequestDataProvider interface in App\Utils\AcmeRequestDataProvider
  2. We register the service in our own services.yaml:
App\Utils\AcmeRequestDataProvider: ~
  1. We define service alias: Treblle\Contract\RequestDataProvider: '@AcmeRequestDataProvider'
Treblle\Contract\RequestDataProvider: '@App\Utils\AcmeRequestDataProvider'

Now all instances depending on the RequestDataProvider interface will use your service.

Last updated on