PHPackages                             moesif/moesif-symfony - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. moesif/moesif-symfony

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

moesif/moesif-symfony
=====================

Bundle for Moesif Symphony integration

v1.0.0(2y ago)04Apache-2.0PHPPHP &gt;=7.2.5CI failing

Since Mar 19Pushed 1y ago4 watchersCompare

[ Source](https://github.com/Moesif/moesif-symfony)[ Packagist](https://packagist.org/packages/moesif/moesif-symfony)[ RSS](/packages/moesif-moesif-symfony/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

Moesif Symfony SDK Documentation
================================

[](#moesif-symfony-sdk-documentation)

by [Moesif](https://moesif.com), the [API analytics](https://www.moesif.com/features/api-analytics) and [API monetization](https://www.moesif.com/solutions/metered-api-billing) platform.

[Moesif's official SDK for PHP Symfony](https://github.com/Moesif/moesif-symfony) allows you to automatically capture API traffic and send to the [Moesif API Analytics](https://www.moesif.com/docs/api-analytics/) platform.

> If you're new to Moesif, see [our Getting Started](https://www.moesif.com/docs/) resources to quickly get up and running.

Supported Symfony Versions
--------------------------

[](#supported-symfony-versions)

The SDK currently supports all Symfony 5.x versions.

Prerequisites
-------------

[](#prerequisites)

Before using this SDK, make sure you have the following:

- [An active Moesif account](https://moesif.com/wrap)
- [A Moesif Application ID](#get-your-moesif-application-id)

### Get Your Moesif Application ID

[](#get-your-moesif-application-id)

After you log into [Moesif Portal](https://www.moesif.com/wrap), you can get your Moesif Application ID during the onboarding steps. You can always access the Application ID any time by following these steps from Moesif Portal after logging in:

1. Select the account icon to bring up the settings menu.
2. Select **Installation** or **API Keys**.
3. Copy your Moesif Application ID from the **Collector Application ID** field.

[![Accessing the settings menu in Moesif Portal](images/app_id.png)](images/app_id.png)

Install the SDK
---------------

[](#install-the-sdk)

Moesif Symfony SDK is available through [Composer](https://getcomposer.org/), the dependency manager for PHP. After you have Composer installed, execute the following command:

```
$ composer require moesif/moesif-symfony
```

Otherwise, manually add `moesif/moesif-symfony` to your [`composer.json` file](https://getcomposer.org/doc/01-basic-usage.md#composer-json-project-setup).

Enable the SDK
--------------

[](#enable-the-sdk)

Follow these steps to enable the SDK:

1. In your project's `config/packages` directory, add a `moesif.yaml` file. This file holds your configuration options.
2. The configuration file requires you to at least [specify your Moesif Application ID](#get-your-moesif-application-id). The following shows an example:

    ```
    moesif:
      moesif_application_id: 'YOUR_MOESIF_APPLICATION_ID.'
      debug: false
      options:
        max_queue_size: 50
        max_batch_size: 25
      hooks_class: 'App\Configuration\MyMoesifHooks'
    ```

For more configuration options, see [YAML Configuration Options](#configuration-options).

Configure the SDK
-----------------

[](#configure-the-sdk)

See the available [configuration options](#configuration-options) to learn how to configure the SDK for your use case.

Troubleshoot
------------

[](#troubleshoot)

For a general troubleshooting guide that can help you solve common problems, see [Server Troubleshooting Guide](https://www.moesif.com/docs/troubleshooting/server-troubleshooting-guide/).

Other troubleshooting supports:

- [FAQ](https://www.moesif.com/docs/faq/)
- [Moesif support email](mailto:support@moesif.com)

Configuration Options
---------------------

[](#configuration-options)

The following sections describe the available configuration options that you can define in `moesif.yaml`.

### `applicationId` (Required)

[](#applicationid-required)

   Data type     `String`  A string that identifies your application.. ### `debug`

[](#debug)

   Data type     `bool`  Set to `true` to print debug messages into the debug and error logs. This can help you troubleshoot integration issues.

### `options`

[](#options)

   Data type     `Object`  If set, contains various options to configure the SDK beyond the defaults.

In this object, you can set the following options:

#### `max_queue_size`

[](#max_queue_size)

   Data type   Default     `Integer`   `15`  If set, overrides the default `max_queue_size` before sending data to Moesif.

#### `max_batch_size`

[](#max_batch_size)

   Data type   Default     `Integer`   `10`  If set, overrides the default `max_batch_size` that is sent over to Moesif.

#### `hooks_class`

[](#hooks_class)

   Data type     `String`  If set, this must be [your implementation of `MoesifHooksInterface`](#user-hook-class-options).

### User Hook Class Options

[](#user-hook-class-options)

You can override and customize certain functionalities within the plugin with hooks. For example, create a file `MyMoesifHooks.php` and implement the `MoesifHooksInterface`:

```
use Moesif\MoesifBundle\Interfaces\MoesifHooksInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class MyMoesifHooks implements MoesifHooksInterface {
   // your implementation of every method follows.
}
```

See [the Example Implementation](#example-implementation) for an example.

Make sure to set the [`hooks_class`](#hooks_class) configuration option to the path of your implementation file.

The methods you need to implement for `MoesifHooksInterface` are the following:

#### `identifyUserId`

[](#identifyuserid)

   Data type   Parameters   Return type     Function   `($request, $response)`   `String`  Optional.

This function takes the `$request` and `$response` arguments and returns a string for a user ID. This enables Moesif to attribute API requests to individual unique users so you can understand who calls your API. You can use this simultaneously with [`identifyCompanyId`](#identifycompanyid) to track both individual customers and also the companies they are part of.

#### `identifyCompanyId`

[](#identifycompanyid)

   Data type   Parameters   Return type     Function   `($request, $response)`   `String`  Optional.

This function takes the `$request` and `$response` arguments and returns a string for a company ID. If you have a B2B business, this method enables Moesif to attribute API requests to specific companies or organizations so you can understand which accounts call your API. You can use this simultaneously with [`identifyUserId`](#identifyuserid) to track both individual customers and the companies they are part of.

#### `identifySessionToken`

[](#identifysessiontoken)

   Data type   Parameters   Return type     Function   `($request, $response)`   `String`  Optional.

A function that takes the `$request` and `$response` arguments and returns a string for session or auth token. Moesif automatically creates sessions by processing your API data, but you can override this through the `identifySessionId` method if you're not happy with the results.

#### `maskRequestHeaders`

[](#maskrequestheaders)

   Data type   Parameters   Return type     Function   `($headers)`   `$headers`  Optional.

A function that takes the `$headers` argument for a request. The argument is an associative array. The method returns an associative array with your sensitive request headers removed or masked.

#### `maskRequestBody`

[](#maskrequestbody)

   Data type   Parameters   Return type     Function   `($body)`   `$body`  Optional.

A function that takes the `$body` argument for request body. The argument an associative array representation of JSON. The method returns an associative array with any request body information removed.

#### `maskResponseHeaders`

[](#maskresponseheaders)

   Data type   Parameters   Return type     Function   `($headers)`   `$headers`  Optional.

Same as [`maskRequestHeaders`](#maskrequestheaders), but for HTTP responses.

#### `maskResponseBody`

[](#maskresponsebody)

   Data type   Parameters   Return type     Function   `($body)`   `$body`  Optional.

Same as [`maskResponseBody`](#maskrequestbody), but for HTTP responses.

#### `getMetadata`

[](#getmetadata)

   Data type   Parameters   Return type     Function   `($request, $response)`   `Associative Array`  Optional.

A function that takes the `$request` and `$response` arguments and returns `$metadata`. `$metadata` is an associative array representation of JSON.

#### `skip`

[](#skip)

   Data type   Parameters   Return type     Function   `($request, $response)`   `bool`  Optional.

A function that takes the `$request` and `$response` arguments. Returns `true` if you want to skip the event. Skipping an event means Moesif doesn't log the event.

#### Example Implementation

[](#example-implementation)

The following example shows what the `MyMoesifHooks.php` file may look like with a `MoesifHooksInterface` implementation:

```
