You Can Track Code Deployments in New Relic With Laravel Commands: Here's How

Written by danielpetrica | Published 2025/11/20
Tech Story Tags: code-deployments | laravel | laravel-commands | laravel-tips-and-tricks | new-relic | track-code-demployments | coding-tips | programming-tips

TLDRLearn how to configure and integrate this command into your CI/CD pipeline for seamless New Relic deployment tracking.via the TL;DR App

To make my life a lot easier, I prepared a custom Laravel command that sends to New Relic the new deployment information. The beauty of this command comes from the ability to run it whenever I deploy my code, as it only requires the ability to run a '''php artisan app:deploy-mark''' and the availability of git to retrieve the version (eventually, we could change it to something almost unique as the current date-time).

Here's the entire file of the command:

 $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 added a first entry in the services.php config file:

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

]


Then, I simply add 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 - executing a simple `ph artisan app:deploy-mark.`


This command is flexible enough to be used in many different CI/CD pipeline stacks, so if you end up using it, please leave a comment with your usage.


I'm curious to see how it can be used.


Written by danielpetrica | Web Developer Working with Laravel, Vue.js and MySQL Will probably post about tech, programming, no-code and low-code
Published by HackerNoon on 2025/11/20