SlapbirdAPM, a Free and Open-Source Observability Tool for Perl Web Applications

SlapbirdAPM is a free-software observability platform tailor made for Perl web-applications. [ It is also a Perl web-application :^) ] It has first class support for Plack, Mojo, Dancer2, and CGI. Slapbird provides developers with comprehensive observability tools to monitor and optimize their applications’ performance.
In this article I will explain how to setup a Plack application with Slapbird. If you want to use another supported framework, please read our Getting Started documentation, or reach out to me on the Perl Foundations Slack channel!
SlapbirdAPM is easily installed on your Plack application, here is a minimal example, using a Dancer2 application that runs under Plack:
Install with
cpan -I SlapbirdAPM::Agent::Plack
#!/usr/bin/env perl
use Dancer2;
use Plack::Builder;
get '/' => sub {
'Hello World!';
};
builder {
enable 'SlapbirdAPM';
app;
};
Now, you can create an account on SlapbirdAPM, and create your application.
Then, simply copy the API key output and, add it to your application via the SLAPBIRDAPM_API_KEY
environment variable. For example:
SLAPBIRDAPM_API_KEY=<API-KEY> plackup app.pl
or, you can pass your key in to the middleware:
builder {
enable 'SlapbirdAPM', key => <YOUR API KEY>;
...
};
Now when you navigate to /
, you will see it logged in your SlapbirdAPM dashboard!
Then, clicking into one of the transactions, you’ll get some more information:
SlapbirdAPM also supports DBI, meaning you can trace your queries, let’s edit our application to include a few DBI queries:
#!/usr/bin/env perl
use Dancer2;
use DBI;
use Plack::Builder;
my $dbh = DBI->connect( 'dbi:SQLite:dbname=database.db', '', '' );
$dbh->do('create table if not exists users (id integer primary key, name varchar)');
get '/' => sub {
send_as html => 'Hello World!';
};
get '/users/:id' => sub {
my $user_id = route_parameters->get('id');
my ($user) =
$dbh->selectall_array(
'select * from users where id = ?',
{ Slice => {} }, $user_id );
send_as JSON => $user;
};
post '/users' => sub {
my $user_name = body_parameters->get('name');
my ($user) =
$dbh->selectall_array(
'insert into users(name) values ( ? ) returning id, name',
{ Slice => {} }, $user_name );
send_as JSON => $user;
};
builder {
enable 'SlapbirdAPM';
app;
};
Now we can use cURL to add data to our database:
curl -X POST -d 'name=bob' http://127.0.0.1:5000/users
Then, if we go back into Slapbird, we can view our timings for our queries:
This just breaks the surface of what is possible using SlapbirdAPM. You can also, generate reports, perform health-checks, and get notified if your application is creating too many 5XX responses.
Thanks for reading!
Tags
Rawley Fowler
Rawley Fowler is the founder and chief-technomancer of Mollusc Software Solutions Inc. A 100% Perl company, supporting Perl projects in Western Canada.
Browse their articles
Feedback
Something wrong with this article? Help us out by opening an issue or pull request on GitHub