Docs
DocumentationQuery ReferenceAPI Reference
Open Console→→
DocumentationQuery ReferenceAPI Reference

Platform overview

What is Axiom?QuickstartArchitectureFeatures
Fundamentals
Datasets
Edge deployments
Limits
Performance
Optimize usage
Requirements
Semantic conventions
Glossary
Tour
SecurityRoadmap

Send data

Reference architecturesMethods

Understand data

Console
Query
Builder
Editor
Query results
Visualize
Traces
Metrics
Correlations
Save queries
Stream
Dashboard
Create
Elements
Create
Configure
Element types
Gauge
Heatmap
Log stream
Monitor list
Note
Pie chart
Scatter plot
Statistic
Table
Time series
Sections
Configure
Filter
Monitor
Overview
View status
Configure
Examples
Monitor types
Anomaly
Match
New values
Threshold
Alerting
Overview
Configure
Notifier types
Amp
ChatGPT Workspace Agent
Claude Code
Cursor
Custom Webhook
Discord
Email
incident.io
Jira Service Management
Microsoft Teams
Opsgenie
PagerDuty
Slack
Annotations
Command Menu
Manage
Datasets
Overview
Views
Virtual fields
Access
RBAC
Tokens
CLI
Organization
Labels
Audit log
Settings
Usage and billing
Profile
Extend
Overview
AWS Lambda
AWS PrivateLink
Cloudflare Workers
Cloudflare Logpush
Convex
Grafana
Hex
Netlify
Supabase
Tailscale
Terraform
Unkey
Vercel
Intelligence
Overview
Spotlight
AI agents
Overview
MCP Server
Overview
Tools
Query cost limits
Agent-created orgs
Skills
Overview
Axiom alerting
Build dashboards
Control costs
SRE
Translate SPL to APL
Splunk
Overview
Splunk app
Install and configure
Commands
Examples
Portal
How it works
Set up standard mode
Set up transparent mode
Observability Cloud
OCSF data
OCSF as CIM
SPL command support
Examples
Monitor and troubleshoot

Use cases

ObservabilityProduct analytics
OCSF security data
Overview
Send data
Query data
LLM observability
Overview
Use Vercel AI SDK
Manual instrumentation
GenAI attributes
Redaction policies

Miscellaneous

LLMs
Overview
List of docs pages
Full docs
Query reference
FAQs
Legal
Acceptable use policy
Axiom for Startups terms
Committed use terms
Cookies
Data processing
HIPAA
Partner agreement
Partner program guide
Privacy policy
SLA
Terms of service
Terms of use

Send data from Hono app to Axiom

This page explains how to send traces, metrics, and logs from a Hono app running on Node.js, Bun, or Cloudflare Workers to Axiom.

Hono is a lightweight web framework built on Web Standards that runs on many JavaScript runtimes, including Node.js, Bun, and Cloudflare Workers.

This page explains how to send the following data from a Hono app to Axiom:

  • Traces: The @hono/otel middleware creates an OpenTelemetry span for every request. An OpenTelemetry SDK exports the spans to Axiom over OTLP/HTTP.
  • Metrics: On Node.js and Bun, @hono/otel also records the http.server.request.duration and http.server.active_requests metrics, and the OpenTelemetry SDK exports them to Axiom.
  • Logs: The @axiomhq/logging library sends structured logs to Axiom. Each log contains the trace ID and span ID of the request that produced it.

The OpenTelemetry SDK depends on the runtime:

RuntimeTracesMetricsLogs
Node.js and Bun@hono/otel with the OpenTelemetry Node.js SDK@hono/otel with the OpenTelemetry Node.js SDK@axiomhq/logging
Cloudflare Workers@hono/otel with @microlabs/otel-cf-workersNot supported@axiomhq/logging

The OpenTelemetry Node.js SDK doesn’t run on Cloudflare Workers, and @microlabs/otel-cf-workers only exports traces. For more information, see Usage on Cloudflare Workers in the @hono/otel documentation.

Prerequisites

  • Create an Axiom account.
  • Create datasets for traces, logs, and metrics. Recommended: Create the datasets in a correlation group. To create all three at once, go to Datasets > Correlations > New correlation group, select From new datasets, and enter a prefix such as hono. Axiom creates hono-traces, hono-logs, and hono-metrics. If you only use Cloudflare Workers, you don’t need the metrics dataset.
  • Create an API token in Axiom with permissions to ingest data to these datasets.
  • A Hono app. To create one, see Getting started in the Hono documentation.

How Axiom receives the data

The OpenTelemetry exporters send data to the OTLP/HTTP endpoints of your Axiom edge deployment. Axiom doesn’t support OTLP over gRPC.

SignalEndpointDataset header
Traceshttps://AXIOM_DOMAIN/v1/tracesX-Axiom-Dataset
Metricshttps://AXIOM_DOMAIN/v1/metricsX-Axiom-Metrics-Dataset

Each request also contains the Authorization: Bearer API_TOKEN header.

The @axiomhq/logging library sends logs through the @axiomhq/js client to the ingest endpoint of the same edge deployment. To select the edge deployment, set the edge option of the client to the base domain of the edge deployment.

Replace AXIOM_DOMAIN with the base domain of your edge deployment. For more information, see Edge deployments.

Edge deploymentBase domain for ingest and query
US East 1 (AWS)us-east-1.aws.edge.axiom.co
EU Central 1 (AWS)eu-central-1.aws.edge.axiom.co

Send data from Node.js or Bun

Install dependencies

In the root folder of your Hono app, install the dependencies:

shell
npm install @hono/otel @opentelemetry/api @opentelemetry/sdk-node @opentelemetry/sdk-metrics @opentelemetry/exporter-trace-otlp-proto @opentelemetry/exporter-metrics-otlp-proto @opentelemetry/resources @opentelemetry/semantic-conventions @axiomhq/js @axiomhq/logging
shell
bun add @hono/otel @opentelemetry/api @opentelemetry/sdk-node @opentelemetry/sdk-metrics @opentelemetry/exporter-trace-otlp-proto @opentelemetry/exporter-metrics-otlp-proto @opentelemetry/resources @opentelemetry/semantic-conventions @axiomhq/js @axiomhq/logging

The -proto exporters send data encoded as Protobuf (http/protobuf). To send JSON instead, use @opentelemetry/exporter-trace-otlp-http and @opentelemetry/exporter-metrics-otlp-http.

Configure environment variables

Set the following environment variables:

shell
export AXIOM_DOMAIN="AXIOM_DOMAIN"
export AXIOM_TOKEN="API_TOKEN"
export AXIOM_TRACES_DATASET="TRACES_DATASET_NAME"
export AXIOM_LOGS_DATASET="LOGS_DATASET_NAME"
export AXIOM_METRICS_DATASET="METRICS_DATASET_NAME"
Info

Replace AXIOM_DOMAIN with the base domain of your edge deployment. For more information, see Edge deployments.

Replace API_TOKEN with the Axiom API token you have generated.

Replace TRACES_DATASET_NAME, LOGS_DATASET_NAME, and METRICS_DATASET_NAME with the names of the Axiom datasets where you send traces, logs, and metrics.

Configure OpenTelemetry

Create the file src/instrumentation.ts. It starts the OpenTelemetry Node.js SDK, which exports spans to the traces dataset and metrics to the metrics dataset.

typescript
import { NodeSDK } from '@opentelemetry/sdk-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto';
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
import { resourceFromAttributes } from '@opentelemetry/resources';
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';

const endpoint = `https://${process.env.AXIOM_DOMAIN}`;
const authorization = `Bearer ${process.env.AXIOM_TOKEN}`;

export const sdk = new NodeSDK({
  resource: resourceFromAttributes({
    [ATTR_SERVICE_NAME]: 'hono-app',
  }),
  // Send spans to the traces dataset
  traceExporter: new OTLPTraceExporter({
    url: `${endpoint}/v1/traces`,
    headers: {
      Authorization: authorization,
      'X-Axiom-Dataset': process.env.AXIOM_TRACES_DATASET!,
    },
  }),
  // Send request metrics to the metrics dataset
  metricReaders: [
    new PeriodicExportingMetricReader({
      exporter: new OTLPMetricExporter({
        url: `${endpoint}/v1/metrics`,
        headers: {
          Authorization: authorization,
          'X-Axiom-Metrics-Dataset': process.env.AXIOM_METRICS_DATASET!,
        },
      }),
    }),
  ],
});

sdk.start();

Replace hono-app with the name of your service.

Warning

Configure metricReaders even if you don’t plan to use metrics. Without it, the SDK reads the OTEL_METRICS_EXPORTER environment variable, which defaults to otlp, and sends the metrics that @hono/otel records to http://localhost:4318. The failing exports slow down the shutdown of your app. To turn off metrics, set OTEL_METRICS_EXPORTER=none.

Configure the logger

Create the file src/logger.ts. It creates an @axiomhq/logging logger that sends logs to the logs dataset and prints them to the console.

typescript
import { Axiom } from '@axiomhq/js';
import { AxiomJSTransport, ConsoleTransport, Logger } from '@axiomhq/logging';

const axiom = new Axiom({
  token: process.env.AXIOM_TOKEN!,
  edge: process.env.AXIOM_DOMAIN,
});

export const logger = new Logger({
  transports: [
    new AxiomJSTransport({ axiom, dataset: process.env.AXIOM_LOGS_DATASET! }),
    new ConsoleTransport(),
  ],
});

Instrument the Hono app

Update the entry point of your app. The example below does the following:

  1. Imports src/instrumentation.ts before anything else, so the SDK is ready when the first request arrives.
  2. Adds the httpInstrumentationMiddleware middleware of @hono/otel, which creates a span for every request. The span name contains the method and the route pattern, for example GET /users/:id. If the response status is 500 or higher, the span status is ERROR, and unhandled errors are recorded as exceptions on the span.
  3. Adds a middleware that creates a child logger with the trace_id and span_id of the current span, and stores it in the context. Every log that a route handler sends with this logger contains these fields.
  4. Sends the buffered logs and spans to Axiom when the process receives the SIGTERM signal.
typescript
import { sdk } from './instrumentation.js';
import { serve } from '@hono/node-server';
import { httpInstrumentationMiddleware } from '@hono/otel';
import { trace } from '@opentelemetry/api';
import { Hono } from 'hono';
import type { Logger } from '@axiomhq/logging';
import { logger } from './logger.js';

const app = new Hono<{ Variables: { logger: Logger } }>();

// Create a span for every request
app.use(httpInstrumentationMiddleware());

// Add the trace context to the logs of every request
app.use(async (c, next) => {
  const spanContext = trace.getActiveSpan()?.spanContext();
  c.set('logger', logger.with({
    trace_id: spanContext?.traceId,
    span_id: spanContext?.spanId,
  }));
  await next();
});

app.get('/', (c) => {
  c.get('logger').info('Handled request', { path: c.req.path });
  return c.text('Hello Hono!');
});

app.get('/users/:id', (c) => {
  c.get('logger').info('Fetched user', { userId: c.req.param('id') });
  return c.json({ id: c.req.param('id') });
});

app.get('/error', () => {
  throw new Error('Something went wrong');
});

app.onError((err, c) => {
  c.get('logger').error('Unhandled error', err);
  return c.text('Internal Server Error', 500);
});

serve({ fetch: app.fetch, port: 3000 });

// Send buffered logs and spans before the process exits
process.on('SIGTERM', async () => {
  await Promise.all([logger.flush(), sdk.shutdown()]);
  process.exit(0);
});
typescript
import { sdk } from './instrumentation';
import { httpInstrumentationMiddleware } from '@hono/otel';
import { trace } from '@opentelemetry/api';
import { Hono } from 'hono';
import type { Logger } from '@axiomhq/logging';
import { logger } from './logger';

const app = new Hono<{ Variables: { logger: Logger } }>();

// Create a span for every request
app.use(httpInstrumentationMiddleware());

// Add the trace context to the logs of every request
app.use(async (c, next) => {
  const spanContext = trace.getActiveSpan()?.spanContext();
  c.set('logger', logger.with({
    trace_id: spanContext?.traceId,
    span_id: spanContext?.spanId,
  }));
  await next();
});

app.get('/', (c) => {
  c.get('logger').info('Handled request', { path: c.req.path });
  return c.text('Hello Hono!');
});

app.get('/users/:id', (c) => {
  c.get('logger').info('Fetched user', { userId: c.req.param('id') });
  return c.json({ id: c.req.param('id') });
});

app.get('/error', () => {
  throw new Error('Something went wrong');
});

app.onError((err, c) => {
  c.get('logger').error('Unhandled error', err);
  return c.text('Internal Server Error', 500);
});

// Send buffered logs and spans before the process exits
process.on('SIGTERM', async () => {
  await Promise.all([logger.flush(), sdk.shutdown()]);
  process.exit(0);
});

export default app;

@hono/otel instruments the request-response lifecycle as a whole and doesn’t create spans for individual middleware. To trace outgoing HTTP requests and database calls on Node.js, add OpenTelemetry instrumentations to the SDK. For more information, see OpenTelemetry using Node.js.

Run the app

Start the app:

shell
npm run dev
shell
bun run dev

Send a few requests to generate data:

shell
curl http://localhost:3000/
curl http://localhost:3000/users/42
curl http://localhost:3000/error

The SDK exports spans every few seconds and metrics every minute. The logger sends logs in batches in the background.

Send data from Cloudflare Workers

On Cloudflare Workers, the instrument function of @microlabs/otel-cf-workers sets up OpenTelemetry for the Worker and exports spans to Axiom. It creates a span for every invocation and automatically traces outgoing fetch calls. The @hono/otel middleware adds a child span that contains the Hono route.

Install dependencies

In the root folder of your Hono app, install the dependencies:

shell
npm install @hono/otel @microlabs/otel-cf-workers @opentelemetry/api @axiomhq/js @axiomhq/logging
npm install --save-exact @opentelemetry/semantic-conventions@1.44.0
Warning

@microlabs/otel-cf-workers version 1.0.0-rc.52 imports the ATTR_FAAS_TIME attribute, which @opentelemetry/semantic-conventions version 1.45.0 no longer exports. With version 1.45.0 or later, the Worker fails to build with the error No matching export ... for import "ATTR_FAAS_TIME". Pinning @opentelemetry/semantic-conventions to version 1.44.0 avoids this error.

Configure the Worker

In your Wrangler configuration file, turn on the nodejs_compat compatibility flag, which @microlabs/otel-cf-workers requires, and add the Axiom settings as environment variables:

JSON
{
  "name": "my-hono-app",
  "main": "src/index.ts",
  "compatibility_date": "2026-11-19",
  "compatibility_flags": ["nodejs_compat"],
  "vars": {
    "AXIOM_DOMAIN": "AXIOM_DOMAIN",
    "AXIOM_TRACES_DATASET": "TRACES_DATASET_NAME",
    "AXIOM_LOGS_DATASET": "LOGS_DATASET_NAME"
  }
}
Info

Replace AXIOM_DOMAIN with the base domain of your edge deployment. For more information, see Edge deployments.

Replace TRACES_DATASET_NAME and LOGS_DATASET_NAME with the names of the Axiom datasets where you send traces and logs.

Store the API token as a secret, not as an environment variable in the Wrangler configuration file. For local development, create a .dev.vars file in the root folder of your app:

shell
AXIOM_TOKEN=API_TOKEN

For the deployed Worker, run the following command, and then enter the API token:

shell
npx wrangler secret put AXIOM_TOKEN

For more information, see Secrets in the Cloudflare documentation.

Instrument the Hono app

Update src/index.ts. The example below does the following:

  1. Adds the httpInstrumentationMiddleware middleware of @hono/otel, which creates a span for every request.
  2. Adds a middleware that creates a logger for every request. The environment variables of a Worker are only available while it handles a request, so the logger can’t be created when the module loads. The logger adds the trace_id and span_id of the current span to every log.
  3. Sends the logs of the request to Axiom with c.executionCtx.waitUntil, which keeps the Worker running after it sends the response until the logs are delivered. For more information, see executionCtx in the Hono documentation.
  4. Wraps the app with the instrument function, which exports the spans to the traces dataset.
typescript
import { Axiom } from '@axiomhq/js';
import { AxiomJSTransport, ConsoleTransport, Logger } from '@axiomhq/logging';
import { httpInstrumentationMiddleware } from '@hono/otel';
import { instrument, type ResolveConfigFn } from '@microlabs/otel-cf-workers';
import { trace } from '@opentelemetry/api';
import { Hono } from 'hono';

type Bindings = {
  AXIOM_DOMAIN: string;
  AXIOM_TOKEN: string;
  AXIOM_TRACES_DATASET: string;
  AXIOM_LOGS_DATASET: string;
};

const app = new Hono<{ Bindings: Bindings; Variables: { logger: Logger } }>();

// Create a span for every request
app.use(httpInstrumentationMiddleware());

// Create a logger for every request and send its logs after the response
app.use(async (c, next) => {
  const axiom = new Axiom({ token: c.env.AXIOM_TOKEN, edge: c.env.AXIOM_DOMAIN });
  const spanContext = trace.getActiveSpan()?.spanContext();
  const logger = new Logger({
    transports: [
      new AxiomJSTransport({ axiom, dataset: c.env.AXIOM_LOGS_DATASET }),
      new ConsoleTransport(),
    ],
    args: {
      trace_id: spanContext?.traceId,
      span_id: spanContext?.spanId,
    },
  });
  c.set('logger', logger);
  try {
    await next();
  } finally {
    c.executionCtx.waitUntil(logger.flush());
  }
});

app.get('/', (c) => {
  c.get('logger').info('Handled request', { path: c.req.path });
  return c.text('Hello Hono!');
});

app.get('/users/:id', (c) => {
  c.get('logger').info('Fetched user', { userId: c.req.param('id') });
  return c.json({ id: c.req.param('id') });
});

app.get('/error', () => {
  throw new Error('Something went wrong');
});

app.onError((err, c) => {
  c.get('logger').error('Unhandled error', err);
  return c.text('Internal Server Error', 500);
});

// Send spans to the traces dataset
const config: ResolveConfigFn<Bindings> = (env) => ({
  exporter: {
    url: `https://${env.AXIOM_DOMAIN}/v1/traces`,
    headers: {
      Authorization: `Bearer ${env.AXIOM_TOKEN}`,
      'X-Axiom-Dataset': env.AXIOM_TRACES_DATASET,
    },
  },
  service: { name: 'hono-worker' },
});

export default instrument(app, config);

Replace hono-worker with the name of your service.

Each request produces the following spans in the same trace:

  • fetchHandler GET: The span that @microlabs/otel-cf-workers creates for the invocation.
  • A span with the method and the route pattern, for example GET /users/:id: The span that @hono/otel creates.
  • fetch POST AXIOM_DOMAIN: The outgoing request that sends the logs of the request to Axiom.

The Workers runtime only advances the clock during I/O, so the duration of CPU-bound work appears as zero. For more information, see Limitations in the @microlabs/otel-cf-workers documentation.

Run the Worker

Start the Worker locally:

shell
npm run dev

Send a few requests to generate data:

shell
curl http://localhost:8787/
curl http://localhost:8787/users/42
curl http://localhost:8787/error

To deploy the Worker to Cloudflare, run the following command:

shell
npm run deploy

View data in Axiom

Traces

To list the slowest routes, run the following query:

APL
['TRACES_DATASET_NAME']
| where ['service.name'] == 'hono-app'
| summarize count(), percentile(duration, 95) by name

Replace hono-app with the service name you have configured.

To view a trace, click a span in the query results. For more information, see Explore traces.

Logs

To list the errors of your app, run the following query:

APL
['LOGS_DATASET_NAME']
| where level == 'error'

To find the logs that belong to a trace, filter the logs by trace ID:

APL
['LOGS_DATASET_NAME']
| where ['fields.trace_id'] == 'TRACE_ID'

Replace TRACE_ID with the ID of the trace.

Metrics

To compute the 90th and 99th percentiles of the request duration for each route, run the following MPL query:

MPL
`METRICS_DATASET_NAME`:`http.server.request.duration`
| where `http.response.status_code` < 400
| bucket by `http.request.method`, `http.route` to 5m using interpolate_cumulative_histogram(rate, 0.90, 0.99)

The query computes a rate from consecutive exports, so it returns results after the SDK has exported metrics at least twice. With the default export interval, this takes about two minutes of traffic.

For more information, see Query metrics.

Related pages

  • Send data from JavaScript app to Axiom
  • OpenTelemetry using Node.js
  • OpenTelemetry using Cloudflare Workers
  • Send OpenTelemetry data to Axiom
  • Correlations
Was this page helpful?
Suggest edits on GitHub
On this page
PrerequisitesHow Axiom receives the dataSend data from Node.js or BunInstall dependenciesConfigure environment variablesConfigure OpenTelemetryConfigure the loggerInstrument the Hono appRun the appSend data from Cloudflare WorkersInstall dependenciesConfigure the WorkerInstrument the Hono appRun the WorkerView data in AxiomTracesLogsMetricsRelated pages