@stainlessdev/xray-node 0.6.0-dev.c5f614b → 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.
- package/README.md +77 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @stainlessdev/xray-node
|
|
2
|
+
|
|
3
|
+
Node.js HTTP adapter for Stainless X-ray request logging. Use this for `node:http` servers or to power framework integrations (Express/Fastify).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @stainlessdev/xray-node
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Basic usage (node:http)
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createServer } from 'node:http';
|
|
15
|
+
import { createEmitter, wrapHttpHandler } from '@stainlessdev/xray-node';
|
|
16
|
+
|
|
17
|
+
const xray = createEmitter({
|
|
18
|
+
serviceName: 'my-service',
|
|
19
|
+
endpointUrl: 'http://localhost:4318',
|
|
20
|
+
// Optional: customize the request ID header name
|
|
21
|
+
requestId: { header: 'request-id' },
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const server = createServer(
|
|
25
|
+
wrapHttpHandler((_req, res) => {
|
|
26
|
+
res.statusCode = 200;
|
|
27
|
+
res.setHeader('Content-Type', 'text/plain');
|
|
28
|
+
res.end('ok');
|
|
29
|
+
}, xray),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
server.listen(3000);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Access the X-ray context
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { getXrayContext } from '@stainlessdev/xray-node';
|
|
39
|
+
|
|
40
|
+
const handler = wrapHttpHandler((req, res) => {
|
|
41
|
+
const ctx = getXrayContext(req);
|
|
42
|
+
ctx?.setUserId('user-123');
|
|
43
|
+
res.end('ok');
|
|
44
|
+
}, xray);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Request IDs and response headers
|
|
48
|
+
|
|
49
|
+
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.
|
|
50
|
+
|
|
51
|
+
## Configuration
|
|
52
|
+
|
|
53
|
+
`createEmitter(config)` accepts `XrayRuntimeConfig` from `@stainlessdev/xray-core`:
|
|
54
|
+
|
|
55
|
+
- `serviceName` (required)
|
|
56
|
+
- `endpointUrl` (required; falls back to `STAINLESS_XRAY_ENDPOINT_URL` when omitted; explicit `endpointUrl` wins)
|
|
57
|
+
- `environment`, `version`, `logger`, `logLevel`
|
|
58
|
+
- `exporter`: `endpointUrl`, `headers`, `timeoutMs`, `spanProcessor`, `instance` (custom SpanExporter)
|
|
59
|
+
- `capture`: request/response headers and bodies
|
|
60
|
+
- `redaction`: headers/query/body JSON-path redaction
|
|
61
|
+
- `requestId`: header name to read/write
|
|
62
|
+
- `route`: normalization options
|
|
63
|
+
|
|
64
|
+
## Adapter options (WrapOptions)
|
|
65
|
+
|
|
66
|
+
`wrapHttpHandler(handler, xray, options)` and `createEmitter(config, options?)` share:
|
|
67
|
+
|
|
68
|
+
- `route`: override the route name for the request
|
|
69
|
+
- `requestId`: explicit request ID to use (prevents auto-generation)
|
|
70
|
+
- `capture`: per-request capture overrides
|
|
71
|
+
- `redaction`: per-request redaction overrides
|
|
72
|
+
- `onRequest(ctx)`, `onResponse(ctx, log)`, `onError(ctx, err)` hooks
|
|
73
|
+
|
|
74
|
+
## Notes
|
|
75
|
+
|
|
76
|
+
- This package depends on OpenTelemetry packages as peer dependencies.
|
|
77
|
+
- Node.js >= 20 is required.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stainlessdev/xray-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Node.js HTTP adapter for Stainless X-ray request logging",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@stainlessdev/xray-core": "0.
|
|
23
|
+
"@stainlessdev/xray-core": "0.7.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@opentelemetry/api": "^1.9.0",
|