@stainlessdev/xray-next 0.6.0 → 0.7.0-dev.588fa57

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 +60 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @stainlessdev/xray-next
2
+
3
+ Next.js integration for Stainless X-ray request logging. Wraps App Router route handlers (Next.js `Route Handlers`) in fetch-based runtimes.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm add @stainlessdev/xray-next
9
+ ```
10
+
11
+ ## Basic usage (App Router route handler)
12
+
13
+ ```ts
14
+ import { createEmitter, getXrayContext } from '@stainlessdev/xray-next';
15
+
16
+ const xray = createEmitter({
17
+ serviceName: 'my-service',
18
+ endpointUrl: 'http://localhost:4318',
19
+ });
20
+
21
+ export const POST = xray(async (req, ctx) => {
22
+ const params = await ctx.params;
23
+ const body = await req.text();
24
+ getXrayContext(req)?.setUserId('user-123');
25
+ return new Response(`id:${params.id ?? ''}:${body}`, { status: 200 });
26
+ });
27
+ ```
28
+
29
+ ## Request IDs and response headers
30
+
31
+ 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.
32
+
33
+ ## Configuration
34
+
35
+ `createEmitter(config, options?)` accepts `XrayRuntimeConfig` (config) and `WrapOptions` (per-request defaults):
36
+
37
+ - `serviceName` (required)
38
+ - `endpointUrl` (required; falls back to `STAINLESS_XRAY_ENDPOINT_URL` when omitted; explicit `endpointUrl` wins)
39
+ - `environment`, `version`, `logger`, `logLevel`
40
+ - `exporter`: `endpointUrl`, `headers`, `timeoutMs`, `spanProcessor`, `instance` (custom SpanExporter)
41
+ - `capture`: request/response headers and bodies
42
+ - `redaction`: headers/query/body JSON-path redaction
43
+ - `requestId`: header name to read/write
44
+ - `route`: normalization options
45
+
46
+ ## Adapter options (WrapOptions)
47
+
48
+ - `route`: override the route name for the request
49
+ - `requestId`: explicit request ID to use (prevents auto-generation)
50
+ - `capture`: per-request capture overrides
51
+ - `redaction`: per-request redaction overrides
52
+ - `onRequest(ctx)`, `onResponse(ctx, log)`, `onError(ctx, err)` hooks
53
+
54
+ ## Advanced usage
55
+
56
+ If you already have an `XrayEmitter` instance, use `wrapNextRoute(handler, xray, options)`.
57
+
58
+ ## Notes
59
+
60
+ - This package depends on OpenTelemetry packages as peer dependencies.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stainlessdev/xray-next",
3
- "version": "0.6.0",
3
+ "version": "0.7.0-dev.588fa57",
4
4
  "description": "Next.js 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-core": "0.6.0",
24
- "@stainlessdev/xray-fetch": "0.6.0"
23
+ "@stainlessdev/xray-core": "0.7.0-dev.588fa57",
24
+ "@stainlessdev/xray-fetch": "0.7.0-dev.588fa57"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@opentelemetry/api": "^1.9.0",