Using Apitally for Performance and Request Analytics in an Adonis.js Application
To use Apitally for performance and request analytics in an Adonis.js application, install the package, configure it with your client ID, and enable desired logging and monitoring features through its integration steps.[1][2][3]
Installation and Basic Setup
- Install Apitally:
Run the following command in your Adonis.js project directory:npm install apitally
- Configure with Ace:
Initialize the integration with:node ace configure apitally/adonisjs
This command:
- Creates a
config/apitally.ts
config file. - Registers Apitally in
adonisrc.ts
. - Adds the middleware to
start/kernel.ts
. - Injects required environment variables into
.env
andstart/env.ts
.[2][1]
- Creates a
Configuration Options
- Edit Configuration:
Inconfig/apitally.ts
, set up with your client ID and environment:import { defineConfig } from 'apitally/adonisjs' const apitallyConfig = defineConfig({ clientId: 'your-client-id', env: 'dev', // or 'prod' requestLogging: { enabled: true, logRequestHeaders: true, logRequestBody: true, logResponseBody: true, captureLogs: true, }, }) export default apitallyConfig;
- Middleware:
Ensure the Apitally middleware is registered so all HTTP requests are tracked.[1][2]
Advanced Features
- Per-Consumer Tracking:
To track requests by authenticated users, use thesetConsumer
function in custom middleware:import { setConsumer } from 'apitally/adonisjs' async handle(ctx, next) { if (ctx.auth.isAuthenticated) { setConsumer(ctx, ctx.auth.user!.email) } await next() }
- Error Reporting:
Capture errors inapp/exceptions/handler.ts
using:import { captureError } from 'apitally/adonisjs' async report(error, ctx) { captureError(error, ctx) return super.report(error, ctx) }
- Dashboards & Alerts:
After deployment, Apitally’s dashboard allows real-time monitoring of API traffic, errors, latency, consumer activity, and alert setup—all configurable via its UI.[3]
With this integration, Apitally enables powerful analytics, in-depth logging, error tracking, and alert-based monitoring for Adonis.js applications.[2][3][1]