Skip to main content
This page guides you through the steps of configuring your Hono application running on Cloudflare Workers 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:
  • Get real-time metrics on API usage, errors, and performance
  • Track API adoption and usage by individual consumers
  • Log and inspect API requests and responses
  • Capture application logs, correlated with API requests
  • Monitor uptime and set up custom alerts

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.

Create Logpush job

Log in to the Cloudflare dashboard and navigate to Analytics & Logs > Logpush. Create a Logpush job with the following settings:
SettingValue
DestinationHTTP destination
HTTP endpointhttps://hub.apitally.io/v2/{client-id}/{env}/logpush
DatasetWorkers trace events
If logs match…Filtered logs:
EventType equals fetch and
ScriptName equals {your-worker-name}
Send the following fields…General:
Event, EventTimestampMs, Logs
In the HTTP endpoint, replace {client-id} with your app’s client ID and {env} with the environment (e.g. prod or dev). In the filter criteria, replace {your-worker-name} with the name of your Worker, as specified in your Wrangler config.

Add middleware

Next, install the Apitally Serverless SDK in your project.
npm install @apitally/serverless
Add the Apitally middleware to your Hono application using the useApitally function.
import { Hono } from "hono";
import { useApitally } from "@apitally/serverless/hono";

const app = new Hono();

useApitally(app);

// Ensure route handlers are registered after useApitally()
Add the Apitally middleware before any other middleware to ensure it wraps the entire stack.

Configure Worker

Enable Workers Logs and Logpush in your Wrangler configuration file.
logpush = true

[observability]
enabled = true
head_sampling_rate = 1

[observability.logs]
invocation_logs = true
Then, deploy your application to Cloudflare Workers.
wrangler deploy
At this point the basic setup for your application is complete and you will start seeing data in the Apitally dashboard after the first request is handled.
It can take 2-3 minutes for requests to show up in Apitally due to how Cloudflare Logpush batches log data before sending it.Also note that Cloudflare Logpush doesn’t include requests from local development environments, so you won’t see them 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. Use the setConsumer function to associate requests with consumers, for example in a middleware.
import { setConsumer } from "@apitally/serverless/hono";

app.use(async (c, next) => {
  const consumerIdentifier = c.get("jwtPayload")?.sub;
  setConsumer(c, consumerIdentifier);
  await next();
});
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

With the serverless SDK, request logging is enabled by default, however request headers and request/response bodies are not included unless explicitly enabled. The SDK automatically applies default masking rules for common sensitive headers and request/response body fields. You can configure additional masking rules and exclude certain requests from logging.
import { Hono } from "hono";
import { useApitally } from "@apitally/serverless/hono";

const app = new Hono();

useApitally(app, {
  logRequestHeaders: true,
  logRequestBody: true,
  logResponseBody: true,
});
The Request logs dashboard now shows individual requests handled by your application, including headers and payloads, if enabled. You can filter, search, and inspect them in detail.