Treblle with AdonisJS
To integrate Treblle with AdonisJS, we provide an official SDK for Adonis - treblle-adonisjs
.
Installation
After installation run the configuration command in your AdonisJS project:
This will create the treblle-adonisjs
config in config/treblle.ts
.
treblle-adonisjs
relies on the following environment variables:
TREBLLE_API_KEY
TREBLLE_PROJECT_ID
So make sure you touch your .env
file to have those environment variables(You can find the values in your Treblle dashboard)
Since treblle-adonisjs
depends on the above environment variables, we recommend validating them.
Open the env.ts
file and paste the following code inside the Env.rules
object.
- Here we expect both
TREBLLE_API_KEY
andTREBLLE_PROJECT_ID
environment variables to be always present - And both should be valid strings
Setup
treblle-adonisjs
exposes a middleware that you can add globally in your start/kernel.ts
global middleware array like so:
And that’s it, Treblle will now monitor your API.
Named middleware
Assuming you have an AdonisJS app that’s not completely an API i.e a fullstack app that exposes API endpoints in say api/v1
, you can use a named middleware so you can apply Treblle’s middleware to the routes you want to monitor and observe.
For example we can do:
Then in routes.ts
you can have: