@stainlessdev/xray-emitter 0.1.0-branch.pedro-unify.20f830a
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 +79 -0
- package/dist/chunk-2NR6RZEP.js +1339 -0
- package/dist/chunk-2NR6RZEP.js.map +1 -0
- package/dist/chunk-3MVVO5I7.cjs +1339 -0
- package/dist/chunk-3MVVO5I7.cjs.map +1 -0
- package/dist/chunk-6UH43LVD.js +281 -0
- package/dist/chunk-6UH43LVD.js.map +1 -0
- package/dist/chunk-AHXNYJ5A.cjs +621 -0
- package/dist/chunk-AHXNYJ5A.cjs.map +1 -0
- package/dist/chunk-GNSXLLEC.cjs +281 -0
- package/dist/chunk-GNSXLLEC.cjs.map +1 -0
- package/dist/chunk-JKW6E4L3.cjs +304 -0
- package/dist/chunk-JKW6E4L3.cjs.map +1 -0
- package/dist/chunk-MPQTI5AX.js +621 -0
- package/dist/chunk-MPQTI5AX.js.map +1 -0
- package/dist/chunk-QUH3LJ5M.cjs +634 -0
- package/dist/chunk-QUH3LJ5M.cjs.map +1 -0
- package/dist/chunk-VGRLHYDA.js +634 -0
- package/dist/chunk-VGRLHYDA.js.map +1 -0
- package/dist/chunk-YVMMCTXW.js +304 -0
- package/dist/chunk-YVMMCTXW.js.map +1 -0
- package/dist/express.cjs +45 -0
- package/dist/express.cjs.map +1 -0
- package/dist/express.d.cts +17 -0
- package/dist/express.d.ts +17 -0
- package/dist/express.js +45 -0
- package/dist/express.js.map +1 -0
- package/dist/fastify.cjs +64 -0
- package/dist/fastify.cjs.map +1 -0
- package/dist/fastify.d.cts +21 -0
- package/dist/fastify.d.ts +21 -0
- package/dist/fastify.js +64 -0
- package/dist/fastify.js.map +1 -0
- package/dist/fetch.cjs +16 -0
- package/dist/fetch.cjs.map +1 -0
- package/dist/fetch.d.cts +19 -0
- package/dist/fetch.d.ts +19 -0
- package/dist/fetch.js +16 -0
- package/dist/fetch.js.map +1 -0
- package/dist/hono.cjs +71 -0
- package/dist/hono.cjs.map +1 -0
- package/dist/hono.d.cts +30 -0
- package/dist/hono.d.ts +30 -0
- package/dist/hono.js +71 -0
- package/dist/hono.js.map +1 -0
- package/dist/index.cjs +12 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.cjs +45 -0
- package/dist/internal.cjs.map +1 -0
- package/dist/internal.d.cts +53 -0
- package/dist/internal.d.ts +53 -0
- package/dist/internal.js +45 -0
- package/dist/internal.js.map +1 -0
- package/dist/next.cjs +30 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.d.cts +18 -0
- package/dist/next.d.ts +18 -0
- package/dist/next.js +30 -0
- package/dist/next.js.map +1 -0
- package/dist/node.cjs +14 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +20 -0
- package/dist/node.d.ts +20 -0
- package/dist/node.js +14 -0
- package/dist/node.js.map +1 -0
- package/dist/remix.cjs +30 -0
- package/dist/remix.cjs.map +1 -0
- package/dist/remix.d.cts +15 -0
- package/dist/remix.d.ts +15 -0
- package/dist/remix.js +30 -0
- package/dist/remix.js.map +1 -0
- package/dist/types-Z1nirh-F.d.cts +149 -0
- package/dist/types-Z1nirh-F.d.ts +149 -0
- package/package.json +94 -0
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# X-ray emitter
|
|
2
|
+
|
|
3
|
+
Node and Typescript SDKs to emit request logs to Stainless X-ray.
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm add @stainlessdev/xray-emitter
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Then using it in Express, for example:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import express from 'express';
|
|
15
|
+
import { createEmitter } from '@stainlessdev/xray-emitter/express';
|
|
16
|
+
import { getXrayContext } from '@stainlessdev/xray-emitter/node';
|
|
17
|
+
|
|
18
|
+
const app = express();
|
|
19
|
+
|
|
20
|
+
const xray = createEmitter({ serviceName: 'my-service' });
|
|
21
|
+
|
|
22
|
+
app.use(xray);
|
|
23
|
+
|
|
24
|
+
app.use((req, _res, next) => {
|
|
25
|
+
const ctx = getXrayContext(req);
|
|
26
|
+
ctx?.setUserId('user-123');
|
|
27
|
+
next();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
app.get('/', (_req, res) => {
|
|
31
|
+
res.send('ok');
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## Supported frameworks
|
|
37
|
+
|
|
38
|
+
| Framework | Import | Docs | Example |
|
|
39
|
+
|-----------|--------|------|---------|
|
|
40
|
+
| Express | `@stainlessdev/xray-emitter/express` | [README](src/express/README.md) | [example](examples/express) |
|
|
41
|
+
| Fastify | `@stainlessdev/xray-emitter/fastify` | [README](src/fastify/README.md) | [example](examples/fastify) |
|
|
42
|
+
| Hono | `@stainlessdev/xray-emitter/hono` | [README](src/hono/README.md) | [example](examples/hono) |
|
|
43
|
+
| Next.js | `@stainlessdev/xray-emitter/next` | [README](src/next/README.md) | [example](examples/next-app) |
|
|
44
|
+
| Remix | `@stainlessdev/xray-emitter/remix` | [README](src/remix/README.md) | [example](examples/remix-app) |
|
|
45
|
+
|
|
46
|
+
Lower-level adapters:
|
|
47
|
+
|
|
48
|
+
| Adapter | Import | Docs | Example |
|
|
49
|
+
|---------|--------|------|---------|
|
|
50
|
+
| Node.js (`node:http`) | `@stainlessdev/xray-emitter/node` | [README](src/node/README.md) | [example](examples/node-http) |
|
|
51
|
+
| Fetch / Edge | `@stainlessdev/xray-emitter/fetch` | [README](src/fetch/README.md) | [example](examples/edge) |
|
|
52
|
+
| Core | `@stainlessdev/xray-emitter` | [README](src/core/README.md) | — |
|
|
53
|
+
|
|
54
|
+
## Configuration
|
|
55
|
+
|
|
56
|
+
X-ray does not read standard OTEL environment variables. Configure an endpoint by passing
|
|
57
|
+
`endpointUrl` or setting `STAINLESS_XRAY_ENDPOINT_URL`. If both are set, `endpointUrl` wins. An
|
|
58
|
+
error is thrown if no endpoint is configured.
|
|
59
|
+
|
|
60
|
+
The core module (`@stainlessdev/xray-emitter`) is runtime-agnostic; use it only if you supply a
|
|
61
|
+
custom exporter instance to `createEmitter`.
|
|
62
|
+
|
|
63
|
+
### Request IDs
|
|
64
|
+
|
|
65
|
+
X-ray resolves request IDs from **response headers** when the span is closed. Configure the header name with `requestId.header` (default: `request-id`, emitted as `Request-Id`). Resolution order is: explicit `requestId` on the normalized request → response header lookup → UUIDv7 when missing.
|
|
66
|
+
|
|
67
|
+
If the configured response header is missing when the response is finalized, X-ray will set it (using the explicit ID when provided, otherwise a generated UUIDv7). Existing response headers are not overwritten.
|
|
68
|
+
|
|
69
|
+
### Fetch wrappers
|
|
70
|
+
|
|
71
|
+
`wrapFetch` may replace the request/response objects while capturing bodies. `wrapFetchPreserve` keeps the original request/response whenever possible, but it may replace the response if it needs to inject a missing `Request-Id` header.
|
|
72
|
+
|
|
73
|
+
## Development
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
pnpm install
|
|
77
|
+
pnpm build
|
|
78
|
+
pnpm test
|
|
79
|
+
```
|