codemonth.dk

One project every month - making stuff better ...

When others then null - Push those errors somewhere

There are so many sites out there, that specializes in certain areas, and do it really good.

One of those sites is Airbrake.io, that can correlate your application errors into one dashboard, for easy reporting. It also integrates with GitHub so you can track errors related to your releases.

So I have decided to write an integration (using their offcial api) that enables us to report exceptions directly into the Airbrake dashboard.

Depending on which plan you select, you will be able to create different projects (applications), and group errors accordingly. For this demo purpose, I have created a free account and in that you only have the option for one project.

First you need to get the project ID and the project key, so you can authenticate against the api endpoint. So once you have signed up for an account (click here to register a free account), go to your project settings page, and on the right hand side, you will be able to find both your project ID and the project key ready to copy.

Second we need to download the certificates for the Airbrake website. We will need them to install into the wallet on the database server. For instructions on how to create a wallet and install certificates into it, please read my entry on installing GITHUB_UTL which covers the same procedure.

Please note, that if you are using 12c, you should only install the root certificate and the SSL certificate and NOT the final client certificate.

So now we should have the basics done, we can get ready and install the user and the packages in the database. Download the following files from my github repository:

  • pljson/*
  • user.sql
  • airbrake_acl.sql
  • airbrake.spec.sql
  • airbrake.body.sql
  • airbrake_notification.spec.sql
  • airbrake_notification.body.sql

Log into the database as sys and run the first 2 files (user.sql and airbrake_acl.sql) that will create the airbrake test user and the give the user the required permissions to connect to the airbrake website from inside the database. Once those 2 scripts has been run then connect to the database as the airbrake user using the password airbrake. First run pljson install script from above the directory where the pljson install script is located, and then the other scripts, in the order listed:


@pljson/install.sql
@airbrake.spec.sql
@airbrake.body.sql
@airbrake_notification.spec.sql
@airbrake_notification.body.sql

Once all the packages are installed, we can finally prepare the code that will show the integration from Oracle to Airbrake.

Log into the database with the airbrake account and create the following 2 procedures:


create or replace procedure t1
as
begin
  raise value_error;
end t1;
/

create or replace procedure t2
as
begin
  t1;
exception
  when others then
    airbrake_notification.automatic_stack;
end t2;
/

Once we have those procedures ready, we can test the integration to Airbrake. First we need to setup the session, and then we can test the connectivity.

First we need to setup our session so that it knows about Airbrake and the project key and id. We do that by using the airbrake package, and the session_setup procedure:


begin
  airbrake.session_setup(
    transport_protocol => 'https'
    , airbrake_host => 'airbrake.io'
    , airbrake_host_port => '443'
    , airbrake_api_name => 'api'
    , airbrake_api_version => 'v3'
    , wallet_location => 'file:/home/oracle/wallet'
    , wallet_password => 'WalletPasswd123'
    , airbrake_project_id => '[your_project_id]'
    , airbrake_project_key => '[your_project_key]'
  );
end;
/

Replace [your_project_id] with the project id from your own Airbrake account and replace [your_project_key] with the real key from your project settings page.

Next we run the demo procedure:


SQL>set serverout on
SQL> exec t2
https://airbrake.io:443/api/v3/projects/[project_id]/notices?key=[project_key]
https://airbrake.io:443/api/v3/projects/[project_id]/notices?key=[project_key]
{"id":"1528836704343180889","url":"https://airbrake.io/locate/1528836704343180889"}

PL/SQL procedure successfully completed.

So the output from that procedure is the url that it calls the api, and the result passed back to us form the Airbrake api. If you follow that link, you should get right to your Airbrake dashboard and you should see the error directly in there.

For next entry I will make the installation process a lot more easy, and I will add integration to projects and releases inside the api.

Tagged in : Pipelined function, UTL_HTTP