# Installation

### Requirements

* PHP >= 8.1
* Symfony ^6.0 | ^7.0 | ^8.0

### Install

Type the command below in your terminal to install the latest version of the bundle:

```
composer require inspector-apm/inspector-symfony
```

### Configure the Ingestion Key

Create the `inspector.yaml` configuration file in your `config/packages` directory, and put the `ingestion_key` field inside:

```yaml
inspector:
    ingestion_key: '%env(INSPECTOR_INGESTION_KEY)%'
```

Add the new variable in your production env file:

```bash
INSPECTOR_INGESTION_KEY=xxxxxxxxxxxxxxxxxxx
```

You can obtain the `ingestion_key` creating a new project in your [Inspector](https://app.inspector.dev) dashboard.

{% hint style="info" %}
To learn more about environment variables configuration you can check the [Symfony documentation](https://symfony.com/doc/current/configuration.html#overriding-environment-values-via-env-local).
{% endhint %}

### Test & Deploy

Execute the Symfony command below to check if your app is properly configured and can send data to inspector:

```bash
php bin/console inspector:test
```

Go to [`https://app.inspector.dev/`](https://app.inspector.dev) to explore your data.

Inspector will monitor many components by default:

* HTTP requests
* Console commands
* SQL queries
* Twig views rendering
* Messenger Background Processes

But you have several configuration parameters to customize its behavior. Learn more in the next section.

## Access the Inspector instance

Inspector instance is binded in the Symfony service container. In your controller, you can type-hint an argument with the Inspector's class name to get a concrete Inspector instance.

```php
namespace App\Controller;

use Inspector\Inspector;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;

class ProductController
{
    /**
     * @Route("/invoice")
     */
    public function generateInvoice(Inspector $inspector, Request $request): Response
    {
        $pdf = $inspector->addSegment(function () {
            return $this->createPDF();
        }, 'file', 'Create Invoice PDF');

        return $pdf;
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.inspector.dev/guides/symfony/installation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
