I'm loving New Relic so far, but I've always found its deployments hard to track, especially because I'm not using GitHub actions for my deployment pipeline.


o make things easier, I created a custom Laravel command that sends deployment information directly to New Relic. The beauty of this command is that I can run it every time I deploy code; it only requires the ability to execute php artisan app:deploy-mark and access to Git to retrieve the version. (Of course, we could swap Git out for something else almost unique, like the current date-time.)


Here's the Command (in Detail):

 $apikey,
                    ])->post($url, [
                        'query' => 'mutation {changeTrackingCreateDeployment(
                            deployment: {
                            version: "' . $dep_rev . '",
                            entityGuid: "' . $app_id . '" }
                            ) {
                                deploymentId
                                entityGuid
                        }}'
                    ]);
        } catch (\Exception $e) {
            $this->error("There was an error: " . $e->getMessage());
            return false;
        }

        if ($result->successful()) {
            $this->info("Newrelic result" . $result->body());
        } else {
            $this->warn("Newrelic result" . $result->body());
        }

        return $result->successful();
    }
}


To make it work, I first added an entry in the services.php config file:

'newrelic' => [
        'user_key' => env('NEWRELIC_USER_KEY', null),
        'app_id' => env('APP_ID_NEWRELIC', null),

]


Next, I added my values inside the .env file like this:

NEWRELIC_USER_KEY=
APP_ID_NEWRELIC=


Now, when I need to track a deployment, I simply add a final step that executes a simple php artisan app:deploy-mark.


This command is flexible enough to work across many different CI/CD pipeline stacks. If you end up using it, please leave a comment and share how.


I’m curious to see the different ways it can be applied.