DEV Community

Cover image for SlapBirdAPM with Mojolicious
Tib
Tib

Posted on • Edited on

2 1

SlapBirdAPM with Mojolicious

This is my quick walk-through exploration of SlapBirdAPM with my Perl web framework of choice (Mojolicious of course!)

Setup Mojolicious Web App

Install Mojolicious:

$ cpanm Mojolicious
--> Working on Mojolicious
Fetching http://www.cpan.org/authors/id/S/SR/SRI/Mojolicious-9.38.tar.gz ... OK
Configuring Mojolicious-9.38 ... OK
Building and testing Mojolicious-9.38 ... OK
Successfully installed Mojolicious-9.38 (upgraded from 9.32)
1 distribution installed
Enter fullscreen mode Exit fullscreen mode

Generate project:

$ mkdir webapp
$ cd webapp
$ mojo generate lite-app bird
  [exist] /home/tib/Code/webapp
  [write] /home/tib/Code/webapp/bird
  [chmod] /home/tib/Code/webapp/bird 744
Enter fullscreen mode Exit fullscreen mode

Test:

$ morbo bird
Web application available at http://127.0.0.1:3000
Enter fullscreen mode Exit fullscreen mode

And check in your browser http://127.0.0.1:3000/

Create SlapBirdAPM account

Go visit SlapBirdAPM:
Image description

Login with GitHub:
Image description

Create new app:
Image description

And get your API Key:
Image description

Install SlapBirdAPM in Web App

First install Mojolicious plugin:

$ cpanm SlapbirdAPM::Agent::Mojo
--> Working on SlapbirdAPM::Agent::Mojo
Fetching http://www.cpan.org/authors/id/R/RA/RAWLEYFOW/SlapbirdAPM-Agent-Mojo-0.005.tar.gz ... OK
Configuring SlapbirdAPM-Agent-Mojo-0.005 ... OK
==> Found dependencies: Const::Fast, System::Info
--> Working on Const::Fast
Fetching http://www.cpan.org/authors/id/L/LE/LEONT/Const-Fast-0.014.tar.gz ... OK
Configuring Const-Fast-0.014 ... OK
Building and testing Const-Fast-0.014 ... OK
Successfully installed Const-Fast-0.014
--> Working on System::Info
Fetching http://www.cpan.org/authors/id/H/HM/HMBRAND/System-Info-0.065.tgz ... OK
Configuring System-Info-0.065 ... OK
Building and testing System-Info-0.065 ... OK
Successfully installed System-Info-0.065
Building and testing SlapbirdAPM-Agent-Mojo-0.005 ... OK
Successfully installed SlapbirdAPM-Agent-Mojo-0.005
3 distributions installed
Enter fullscreen mode Exit fullscreen mode

And add plugin SlapbirdAPM; to your web app.

Our full application now looks like this:

#!/usr/bin/env perl
use Mojolicious::Lite -signatures;

plugin 'SlapbirdAPM';

get '/' => sub ($c) {
  $c->render(template => 'index');
};

app->start;
__DATA__

@@ index.html.ep
% layout 'default';
% title 'Welcome';
<h1>Welcome to the Mojolicious real-time web framework!</h1>

@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
  <head><title><%= title %></title></head>
  <body><%= content %></body>
</html>
Enter fullscreen mode Exit fullscreen mode

Test!

Let's restart the application with the plugin and an API Key:

$ export SLAPBIRDAPM_API_KEY=01ABCDEFGHIJKLMNOPKtest-app && morbo bird
Web application available at http://127.0.0.1:3000
[2024-08-27 11:33:27.51107] [8402] [info] Slapbird configured and active on this application.
Enter fullscreen mode Exit fullscreen mode

Use your favorite browser to browse http://127.0.0.1:3000 or curl http://127.0.0.1:3000.

Your activity will immediately reflect in your SlapBirdAPM portal
Image description

We're done! 😀

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay