DEV Community

Cover image for Monitoring a Plack Application with SlapbirdAPM
Rawley Fowler
Rawley Fowler

Posted on

1 1 1

Monitoring a Plack Application with SlapbirdAPM

SlapbirdAPM is a free and open-source application performance monitoring (APM) platform specifically designed for Perl web applications. It provides developers with comprehensive observability tools to monitor and optimize their applications' performance.

SlapbirdAPM is easily installed on your Plack application, here is a minimal example, using a Dancer2 application:

Install with

cpan -I SlapbirdAPM::Agent::Plack
Enter fullscreen mode Exit fullscreen mode
#!/usr/bin/env perl

use Dancer2;
use Plack::Builder;

get '/' => sub {
    'Hello World!';
};

builder {
    enable 'SlapbirdAPM';
    app;
};
Enter fullscreen mode Exit fullscreen mode

Now, you can create an account on SlapbirdAPM, and create your application.

New 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
Enter fullscreen mode Exit fullscreen mode

or, you can pass your key in to the middleware:

builder {
    enable 'SlapbirdAPM', key => <YOUR API KEY>;
    ...
};
Enter fullscreen mode Exit fullscreen mode

Now when you navigate to /, you will see it logged in your Slapbird dashboard!

Dashboard

Individual transaction

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;
};
Enter fullscreen mode Exit fullscreen mode

Now we can use cURL to add data to our database:

curl -X POST -d 'name=bob' http://127.0.0.1:5000/users
Enter fullscreen mode Exit fullscreen mode

Then, if we go back into Slapbird, we can view our timings for our queries:

Image description

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!

Top comments (0)

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!

👋 Kindness is contagious

Dive into this thoughtful piece, beloved in the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A sincere "thank you" can brighten someone's day—leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay