@stainlessdev/xray-fastify 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-fastify
2
+
3
+ Fastify integration for Stainless X-ray request logging. Registers hooks that wrap Fastify requests and responses.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm add @stainlessdev/xray-fastify
9
+ ```
10
+
11
+ ## Basic usage
12
+
13
+ ```ts
14
+ import Fastify from 'fastify';
15
+ import { createEmitter } from '@stainlessdev/xray-fastify';
16
+
17
+ const app = Fastify();
18
+
19
+ const xray = createEmitter({
20
+ serviceName: 'my-service',
21
+ endpointUrl: 'http://localhost:4318',
22
+ });
23
+
24
+ xray(app);
25
+
26
+ app.addHook('onRequest', async (request) => {
27
+ request.xray?.setUserId('user-123');
28
+ });
29
+
30
+ app.get('/', async () => ({ ok: true }));
31
+ ```
32
+
33
+ ## Request IDs and response headers
34
+
35
+ 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.
36
+
37
+ ## Configuration
38
+
39
+ `createEmitter(config, options?)` accepts `XrayRuntimeConfig` (config) and `WrapOptions` (per-request defaults):
40
+
41
+ - `serviceName` (required)
42
+ - `endpointUrl` (required; falls back to `STAINLESS_XRAY_ENDPOINT_URL` when omitted; explicit `endpointUrl` wins)
43
+ - `environment`, `version`, `logger`, `logLevel`
44
+ - `exporter`: `endpointUrl`, `headers`, `timeoutMs`, `spanProcessor`, `instance` (custom SpanExporter)
45
+ - `capture`: request/response headers and bodies
46
+ - `redaction`: headers/query/body JSON-path redaction
47
+ - `requestId`: header name to read/write
48
+ - `route`: normalization options
49
+
50
+ ## Adapter options (WrapOptions)
51
+
52
+ - `route`: override the route name for the request
53
+ - `requestId`: explicit request ID to use (prevents auto-generation)
54
+ - `capture`: per-request capture overrides
55
+ - `redaction`: per-request redaction overrides
56
+ - `onRequest(ctx)`, `onResponse(ctx, log)`, `onError(ctx, err)` hooks
57
+
58
+ ## Advanced usage
59
+
60
+ If you already have an `XrayEmitter` instance, use `addFastifyHooks(app, xray, options)`.
61
+
62
+ ## Notes
63
+
64
+ - This package depends on OpenTelemetry packages as peer dependencies.
65
+ - Node.js >= 20 is required.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stainlessdev/xray-fastify",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Fastify 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-node": "0.6.0"
23
+ "@stainlessdev/xray-core": "0.7.0",
24
+ "@stainlessdev/xray-node": "0.7.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@opentelemetry/api": "^1.9.0",