Treblle with Fastify
To integrate Treblle with Fastify, we provide an official SDK for Fastify - treblle-fastify
.
Installation
Register treblle-fastify
treblle-fastify
is a Fastify plugin, so you need to register it.
Notice you are not providing your apiKey
and projectId
, this is because treblle-fastify
will look for the following environment variables:
TREBLLE_API_KEY
TREBLLE_PROJECT_ID
And use them for the apiKey
and projectId
respectively. That said, we recommend you set these environment variables in your .env
file or your production server environment.
Config options
The treblle-fastify
plugin can optionally take the following properties.
For example you can setup the treblle-fastify
plugin like so:
Platformatic DB
Since the Treblle SDK for Fastify is a Fastify plugin, you can easily set up Treblle in a Platformatic DB application with the following steps:
install the SDK
Run the below command to install the Treblle SDK in your Platformatic DB project
Setup environment variables
In your .env
file, add the following environment variables for your Treblle API Key and Project ID respectively:
PLT_TREBLLE_API_KEY
PLT_TREBLLE_PROJECT_ID
Add plugin options
Next edit your platformatic.db.json
config file to have an options
property with environment variable placeholders for the Treblle credentials you set earlier in your .env
file:
Setup the plugin
To setup the plugin create treblle.js
file in plugins/
folder and add the below code:
Now when a request comes into your Platformatic DB app, it will get sent to your Treblle dashboard.