@stainlessdev/xray-hono 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +65 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # @stainlessdev/xray-hono
2
+
3
+ Hono integration for Stainless X-ray request logging. Provides middleware that wraps `fetch`-based Hono requests.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm add @stainlessdev/xray-hono
9
+ ```
10
+
11
+ ## Basic usage
12
+
13
+ ```ts
14
+ import { Hono } from 'hono';
15
+ import { createEmitter, type HonoXrayEnv } from '@stainlessdev/xray-hono';
16
+
17
+ const app = new Hono<HonoXrayEnv>();
18
+
19
+ const xray = createEmitter({
20
+ serviceName: 'my-service',
21
+ endpointUrl: 'http://localhost:4318',
22
+ });
23
+
24
+ app.use('*', xray);
25
+
26
+ app.use('*', async (c, next) => {
27
+ c.get('xray')?.setUserId('user-123');
28
+ await next();
29
+ });
30
+
31
+ app.get('/', (c) => c.text('ok'));
32
+ ```
33
+
34
+ ## Request IDs and response headers
35
+
36
+ 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.
37
+
38
+ ## Configuration
39
+
40
+ `createEmitter(config, options?)` accepts `XrayRuntimeConfig` (config) and `WrapOptions` (per-request defaults):
41
+
42
+ - `serviceName` (required)
43
+ - `endpointUrl` (required; falls back to `STAINLESS_XRAY_ENDPOINT_URL` when omitted; explicit `endpointUrl` wins)
44
+ - `environment`, `version`, `logger`, `logLevel`
45
+ - `exporter`: `endpointUrl`, `headers`, `timeoutMs`, `spanProcessor`, `instance` (custom SpanExporter)
46
+ - `capture`: request/response headers and bodies
47
+ - `redaction`: headers/query/body JSON-path redaction
48
+ - `requestId`: header name to read/write
49
+ - `route`: normalization options
50
+
51
+ ## Adapter options (WrapOptions)
52
+
53
+ - `route`: override the route name for the request
54
+ - `requestId`: explicit request ID to use (prevents auto-generation)
55
+ - `capture`: per-request capture overrides
56
+ - `redaction`: per-request redaction overrides
57
+ - `onRequest(ctx)`, `onResponse(ctx, log)`, `onError(ctx, err)` hooks
58
+
59
+ ## Advanced usage
60
+
61
+ If you already have an `XrayEmitter` instance, use `createHonoMiddleware(xray, options)`.
62
+
63
+ ## Notes
64
+
65
+ - This package depends on OpenTelemetry packages as peer dependencies.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stainlessdev/xray-hono",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Hono integration for Stainless X-ray request logging",
5
5
  "files": [
6
6
  "dist"
@@ -20,8 +20,8 @@
20
20
  "access": "public"
21
21
  },
22
22
  "dependencies": {
23
- "@stainlessdev/xray-fetch": "0.6.0",
24
- "@stainlessdev/xray-core": "0.6.0"
23
+ "@stainlessdev/xray-core": "0.7.0",
24
+ "@stainlessdev/xray-fetch": "0.7.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@hono/node-server": "^1.19.8",