Hono integration for Stainless X-ray request logging
npm install @stainlessdev/xray-honoHono integration for Stainless X-ray request logging. Provides middleware that wraps fetch-based Hono requests.
``sh`
pnpm add @stainlessdev/xray-hono
`ts
import { Hono } from 'hono';
import { createEmitter, type HonoXrayEnv } from '@stainlessdev/xray-hono';
const app = new Hono
const xray = createEmitter({
serviceName: 'my-service',
endpointUrl: 'http://localhost:4318',
});
app.use('*', xray);
app.use('*', async (c, next) => {
c.get('xray')?.setUserId('user-123');
await next();
});
app.get('/', (c) => c.text('ok'));
`
X-ray will auto-generate a request ID and inject it into your response headers under the configured name (requestId.header, default request-id, emitted as Request-Id) if the header is missing. If you set your own request ID first (via options.requestId or by setting the response header yourself), X-ray preserves it and does not overwrite the header.
createEmitter(config, options?) accepts XrayRuntimeConfig (config) and WrapOptions (per-request defaults):
- serviceName (required)endpointUrl
- (required; falls back to STAINLESS_XRAY_ENDPOINT_URL when omitted; explicit endpointUrl wins)environment
- , version, logger, logLevelexporter
- : endpointUrl, headers, timeoutMs, spanProcessor, instance (custom SpanExporter)capture
- : request/response headers and bodiesredaction
- : headers/query/body JSON-path redactionrequestId
- : header name to read/writeroute
- : normalization options
- route: override the route name for the requestrequestId
- : explicit request ID to use (prevents auto-generation)capture
- : per-request capture overridesredaction
- : per-request redaction overridesonRequest(ctx)
- , onResponse(ctx, log), onError(ctx, err) hooks
If you already have an XrayEmitter instance, use createHonoMiddleware(xray, options)`.
- This package depends on OpenTelemetry packages as peer dependencies.