Treblle for Symfony


  • PHP 7.4+
  • Symfony 4.4+


To install the SDK you will need to be using Composer in your project. 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 project 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.

  project_id: "%env(TREBLLE_PROJECT_ID)%"
  api_key: "%env(TREBLLE_API_KEY)%"
  debug: false
    - password
    - api_key
    - secret
  endpoint_url: "" // optional

Overriding data providers

Treblle SDK allows you to take over control over how the data is collected, processed, and sent to the Trebble 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:

    autowire: true
    autoconfigure: true

    class: GuzzleHttp\Client

    factory: [ Treblle\Symfony\DependencyInjection\TreblleFactory, 'createTreblle' ]
      $client: '@treblle-client'

    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'

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: 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 servic ealias: Treblle\Contract\RequestDataProvider: '@AcmeRequestDataProvider'
  Treblle\Contract\RequestDataProvider: '@App\Utils\AcmeRequestDataProvider'

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