Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ export default defineConfig({
text: 'Integration',
collapsed: true,
items: [
{
text: 'Apitally',
link: '/integrations/apitally'
},
{
text: 'Astro',
link: '/integrations/astro'
Expand Down
93 changes: 93 additions & 0 deletions docs/integrations/apitally.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
title: Apitally - ElysiaJS
head:
- - meta
- property: 'og:title'
content: Apitally - ElysiaJS

- - meta
- name: 'description'
content: We may use Apitally to capture API metrics and logs.

- - meta
- name: 'og:description'
content: We may use Apitally to capture API metrics and logs.
---

# Apitally

[Apitally](https://apitally.io/elysia) is a simple API monitoring and analytics tool with an official plugin for Elysia.

It provides real-time insights into API usage, errors, and performance. It also captures API request logs and application logs,
which are automatically correlated.

![Apitally dashboard showing API traffic metrics](/recipe/apitally/traffic-dashboard.webp)

## Basic setup

1. [Sign up](https://app.apitally.io/?signup) for an account, create a new app, and grab your client ID.

2. Install the open-source [Apitally SDK](https://github.com/apitally/apitally-js):

```bash
bun add apitally
```

3. Add the plugin to your Elysia instance and pass in your client ID:

```typescript
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");
```

A more detailed [setup guide for Elysia](https://docs.apitally.io/frameworks/elysia) is available in the Apitally docs.

## Consumers

You can associate requests with consumer identifiers, allowing you to get insights into API adoption and filter logs and metrics by consumer.

```typescript
app.derive(async ({ apitally, jwt, cookie: { auth } }) => {
const profile = await jwt.verify(auth);
apitally.consumer = {
identifier: profile.id,
name: profile.name, // optional
group: profile.role, // optional
};
});
```

## Logs

Capturing request and application logs is disabled by default. You can enable it by passing the `requestLogging` option to the plugin and
configure in detail what's included in the logs.

```typescript
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: { // [!code ++]
enabled: true, // [!code ++]
logRequestHeaders: true, // [!code ++]
logRequestBody: true, // [!code ++]
logResponseBody: true, // [!code ++]
captureLogs: true, // application logs // [!code ++]
}, // [!code ++]
}),
)
.get("/", () => "hello");
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.