This page guides you through the steps of configuring your Elysia application to work with Apitally. If you don’t have an account yet, now would be a good time to sign up. Once you’re done with this guide, you will be able to:
  • Analyze requests to your application
  • Keep track of errors, response times and payload sizes
  • Understand how individual API consumers use your application
  • Log and inspect API requests and responses
  • Monitor your application’s uptime and receive alerts when it’s down
  • Set up custom alert rules and get notified when they’re triggered

Create app

To get started, create a new app in the Apitally dashboard and select as your framework. Create app Here you can also configure the environments (e.g. prod and dev) for your app, or simply accept the defaults. Take a note of the client ID displayed after submitting. You will need it in the next step.

Add middleware

Next, install the Apitally SDK in your Elysia project.
bun add apitally
Add the Apitally plugin to your Elysia application and provide the clientId for your app. You’ll find the clientId on the Setup instructions page for your app in the Apitally dashboard, which is displayed immediately after creating the app.
import { Elysia } from "elysia";
import { apitallyPlugin } from "apitally/elysia";

const app = new Elysia()
  .use(
    apitallyPlugin({
      clientId: "your-client-id",
      env: "dev", // or "prod" etc.
    }),
  )
  .get("/", () => "hello");
Deploy your application with these changes, or restart if you're testing locally.
At this point the basic setup for your application is complete and you will start seeing data in the Apitally dashboard.

Identify consumers

To analyze and filter API traffic by consumers, you can associate requests with consumer identifiers in your application. In most cases, use the authenticated identity to identify the consumer. The identifier should be a string, such as a username, email address, or any other unique identifier. Optionally, you can also provide a display name and group for each consumer. Set the apitally.consumer property to associate requests with consumers, for example in a derive lifecycle function.
app.derive(async ({ apitally, jwt, cookie: { auth } }) => {
  const profile = await jwt.verify(auth);
  apitally.consumer = profile.name;
});
The Consumers dashboard now shows all consumers that have made requests to your application. You can also filter other dashboards by consumer.

Configure request logging

Logging of individual requests and responses is disabled by default to protect potentially sensitive data. If you enable it, you can configure in detail what parts of the request and response should be logged. You can also mask sensitive information (e.g. in headers) and exclude certain requests from logging. The SDK applies default masking rules for common sensitive headers, query parameters and request/response body fields.
import { Elysia } from "elysia";
import { apitallyPlugin } from "apitally/elysia";

const app = new Elysia()
  .use(
    apitallyPlugin({
      clientId: "your-client-id",
      env: "dev", // or "prod" etc.
      requestLogging: {
        enabled: true,
        logRequestHeaders: true,
        logRequestBody: true,
        logResponseBody: true,
        captureLogs: true,
      },
    }),
  )
  .get("/", () => "hello");
The Request logs dashboard now shows individual requests handled by your application. You can filter, search, and inspect them in detail.