Customise the info endpoint
The info endpoint is the merge of its contributors. Each key of info.contributors becomes a
top-level key of the JSON. Expose the endpoint first, see
expose endpoints.
Add a section
Section titled “Add a section”Implement Nwidart\Actuator\Info\InfoContributor and return an array:
<?php
namespace App\Info;
use App\Features\FeatureFlags;use Nwidart\Actuator\Info\InfoContributor;
final class FeatureFlagsInfoContributor implements InfoContributor{ public function __construct(private FeatureFlags $flags) {}
public function contribute(): array { return ['enabled' => $this->flags->enabled()]; }}Register it under the key you want in the JSON:
'info' => [ 'middleware' => [],
'contributors' => [ 'app' => AppInfoContributor::class, // ... 'features' => App\Info\FeatureFlagsInfoContributor::class, ],],{ "app": { "name": "Laravel", "environment": "production" }, "features": { "enabled": ["new-checkout", "dark-mode"] }}The container builds the contributor, so constructor dependencies are injected. Like indicators, a
contributor entry can pass constructor arguments: [Contributor::class, ['name' => 'value']].
Omit a section conditionally
Section titled “Omit a section conditionally”Return an empty array, and the key is left out of the response. The built-in git contributor does
this when the application has no .git directory.
Remove a built-in section
Section titled “Remove a built-in section”Delete the entry. For example, to hide the operating system and the process:
'contributors' => [ 'app' => AppInfoContributor::class, 'git' => GitInfoContributor::class, 'php' => PhpInfoContributor::class, 'os' => OsInfoContributor::class, 'process' => ProcessInfoContributor::class,],Read git data from another directory
Section titled “Read git data from another directory”GitInfoContributor reads base_path('.git'). Pass directory to read another one:
'git' => [GitInfoContributor::class, ['directory' => '/srv/release/.git']],Keep the response safe
Section titled “Keep the response safe”Everyone who can reach info sees its content. Return versions and identifiers, never secrets.
Protect the endpoint as described in secure the endpoints.