How to Track Code deployments in New Relic with Laravel Commands

Written by danielpetrica | Published 2025/09/09
Tech Story Tags:

TLDRTracking deployments in New Relic can be tricky if you’re not using GitHub Actions. To solve this, the author created a custom Laravel artisan command that sends deployment data—like version or timestamp—straight to New Relic. By configuring your services.php and .env files with your API key and app ID, you can mark every deployment with a single php artisan app:deploy-mark step. This lightweight approach works seamlessly across different CI/CD stacks, offering developers an easy, flexible way to keep deployment tracking in sync with New Relic.via the TL;DR App

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.


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/09/09