Skip to content

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.

Implement Nwidart\Actuator\Info\InfoContributor and return an array:

app/Info/FeatureFlagsInfoContributor.php
<?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:

config/actuator.php
'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']].

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.

Delete the entry. For example, to hide the operating system and the process:

config/actuator.php
'contributors' => [
'app' => AppInfoContributor::class,
'git' => GitInfoContributor::class,
'php' => PhpInfoContributor::class,
'os' => OsInfoContributor::class,
'process' => ProcessInfoContributor::class,
],

GitInfoContributor reads base_path('.git'). Pass directory to read another one:

config/actuator.php
'git' => [GitInfoContributor::class, ['directory' => '/srv/release/.git']],

Everyone who can reach info sees its content. Return versions and identifiers, never secrets. Protect the endpoint as described in secure the endpoints.