@stainlessdev/xray-emitter 0.1.0-dev.800c87d → 0.2.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 +1 -0
- package/dist/effect.cjs +186 -0
- package/dist/effect.cjs.map +1 -0
- package/dist/effect.d.cts +33 -0
- package/dist/effect.d.ts +33 -0
- package/dist/effect.js +186 -0
- package/dist/effect.js.map +1 -0
- package/dist/emitter-BqfrGIod.d.cts +5 -0
- package/dist/emitter-CScYhwGA.d.ts +5 -0
- package/dist/fetch.d.cts +3 -4
- package/dist/fetch.d.ts +3 -4
- package/dist/hono.d.cts +1 -1
- package/dist/hono.d.ts +1 -1
- package/dist/next.d.cts +2 -1
- package/dist/next.d.ts +2 -1
- package/dist/remix.d.cts +2 -1
- package/dist/remix.d.ts +2 -1
- package/package.json +11 -1
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ app.get('/', (_req, res) => {
|
|
|
42
42
|
| Hono | `@stainlessdev/xray-emitter/hono` | [README](src/hono/README.md) | [example](examples/hono) |
|
|
43
43
|
| Next.js | `@stainlessdev/xray-emitter/next` | [README](src/next/README.md) | [example](examples/next-app) |
|
|
44
44
|
| Remix | `@stainlessdev/xray-emitter/remix` | [README](src/remix/README.md) | [example](examples/remix-app) |
|
|
45
|
+
| Effect | `@stainlessdev/xray-emitter/effect` | [README](src/effect/README.md) | [example](examples/effect) |
|
|
45
46
|
|
|
46
47
|
Lower-level adapters:
|
|
47
48
|
|
package/dist/effect.cjs
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkDBI3HXNRcjs = require('./chunk-DBI3HXNR.cjs');
|
|
4
|
+
require('./chunk-XO6YWDFL.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkGNSXLLECcjs = require('./chunk-GNSXLLEC.cjs');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunkJKW6E4L3cjs = require('./chunk-JKW6E4L3.cjs');
|
|
17
|
+
|
|
18
|
+
// src/effect/effect.ts
|
|
19
|
+
var _effect = require('effect');
|
|
20
|
+
var _platform = require('@effect/platform');
|
|
21
|
+
function createEmitter2(config, options) {
|
|
22
|
+
const emitter = _chunkDBI3HXNRcjs.createEmitter.call(void 0, config);
|
|
23
|
+
const middleware = createEffectMiddleware(emitter, options);
|
|
24
|
+
middleware.flush = emitter.flush;
|
|
25
|
+
middleware.shutdown = emitter.shutdown;
|
|
26
|
+
return middleware;
|
|
27
|
+
}
|
|
28
|
+
function createEffectMiddleware(xray, options) {
|
|
29
|
+
return ((httpApp) => _effect.Effect.gen(function* () {
|
|
30
|
+
const request = yield* _platform.HttpServerRequest.HttpServerRequest;
|
|
31
|
+
const headers = effectHeadersToRecord(request.headers);
|
|
32
|
+
const url = buildFullUrl(request.originalUrl, headers);
|
|
33
|
+
const routeCtxOption = yield* _effect.Effect.serviceOption(_platform.HttpRouter.RouteContext);
|
|
34
|
+
const route = _effect.Option.isSome(routeCtxOption) ? String(routeCtxOption.value.route.path) : _optionalChain([options, 'optionalAccess', _ => _.route]);
|
|
35
|
+
const captureReqBody = xray.config.capture.requestBody;
|
|
36
|
+
let requestBody;
|
|
37
|
+
if (captureReqBody && captureReqBody !== "none") {
|
|
38
|
+
const textResult = yield* _effect.Effect.either(request.text);
|
|
39
|
+
if (textResult._tag === "Right") {
|
|
40
|
+
const bytes = new TextEncoder().encode(textResult.right);
|
|
41
|
+
const maxBytes = xray.config.capture.maxBodyBytes;
|
|
42
|
+
const truncated = bytes.length > maxBytes;
|
|
43
|
+
const slice = truncated ? bytes.slice(0, maxBytes) : bytes;
|
|
44
|
+
requestBody = _chunkJKW6E4L3cjs.makeCapturedBody.call(void 0, slice, bytes.length, truncated, captureReqBody);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const normalizedRequest = {
|
|
48
|
+
method: request.method,
|
|
49
|
+
url,
|
|
50
|
+
route,
|
|
51
|
+
headers,
|
|
52
|
+
body: requestBody,
|
|
53
|
+
requestId: _optionalChain([options, 'optionalAccess', _2 => _2.requestId]),
|
|
54
|
+
remoteAddress: request.remoteAddress._tag === "Some" ? request.remoteAddress.value : void 0,
|
|
55
|
+
startTimeMs: Date.now()
|
|
56
|
+
};
|
|
57
|
+
const ctx = xray.startRequest(normalizedRequest);
|
|
58
|
+
_chunkGNSXLLECcjs.bindContextToObject.call(void 0, request, ctx);
|
|
59
|
+
if (_optionalChain([options, 'optionalAccess', _3 => _3.requestId])) {
|
|
60
|
+
_chunkGNSXLLECcjs.setContextRequestId.call(void 0, ctx, options.requestId);
|
|
61
|
+
}
|
|
62
|
+
if (route) {
|
|
63
|
+
_chunkGNSXLLECcjs.setContextRoute.call(void 0, ctx, route);
|
|
64
|
+
}
|
|
65
|
+
if (_optionalChain([options, 'optionalAccess', _4 => _4.capture])) {
|
|
66
|
+
_chunkGNSXLLECcjs.setCaptureOverride.call(void 0, ctx, options.capture);
|
|
67
|
+
}
|
|
68
|
+
if (_optionalChain([options, 'optionalAccess', _5 => _5.redaction])) {
|
|
69
|
+
_chunkGNSXLLECcjs.setRedactionOverride.call(void 0, ctx, options.redaction);
|
|
70
|
+
}
|
|
71
|
+
if (_optionalChain([options, 'optionalAccess', _6 => _6.onRequest])) {
|
|
72
|
+
try {
|
|
73
|
+
options.onRequest(ctx);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
_chunkJKW6E4L3cjs.logWithLevel.call(void 0, xray.config.logger, "warn", xray.config.logLevel, "xray: onRequest failed", {
|
|
76
|
+
error: err instanceof Error ? err.message : String(err)
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const exit = yield* _effect.Effect.exit(httpApp);
|
|
81
|
+
if (_effect.Exit.isSuccess(exit)) {
|
|
82
|
+
const response = exit.value;
|
|
83
|
+
const responseHeaders = effectHeadersToRecord(response.headers);
|
|
84
|
+
const log2 = xray.endRequest(ctx, {
|
|
85
|
+
statusCode: response.status,
|
|
86
|
+
headers: responseHeaders,
|
|
87
|
+
body: captureResponseBody(xray, response),
|
|
88
|
+
endTimeMs: Date.now()
|
|
89
|
+
});
|
|
90
|
+
if (_optionalChain([options, 'optionalAccess', _7 => _7.onResponse])) {
|
|
91
|
+
try {
|
|
92
|
+
options.onResponse(ctx, log2);
|
|
93
|
+
} catch (err) {
|
|
94
|
+
_chunkJKW6E4L3cjs.logWithLevel.call(void 0,
|
|
95
|
+
xray.config.logger,
|
|
96
|
+
"warn",
|
|
97
|
+
xray.config.logLevel,
|
|
98
|
+
"xray: onResponse failed",
|
|
99
|
+
{ error: err instanceof Error ? err.message : String(err) }
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return response;
|
|
104
|
+
}
|
|
105
|
+
const error = _effect.Cause.squash(exit.cause);
|
|
106
|
+
const [errorResponse] = yield* _platform.HttpServerError.causeResponse(exit.cause);
|
|
107
|
+
const log = xray.endRequest(
|
|
108
|
+
ctx,
|
|
109
|
+
{
|
|
110
|
+
statusCode: errorResponse.status,
|
|
111
|
+
headers: effectHeadersToRecord(errorResponse.headers),
|
|
112
|
+
body: void 0,
|
|
113
|
+
endTimeMs: Date.now()
|
|
114
|
+
},
|
|
115
|
+
error
|
|
116
|
+
);
|
|
117
|
+
if (_optionalChain([options, 'optionalAccess', _8 => _8.onError])) {
|
|
118
|
+
try {
|
|
119
|
+
options.onError(ctx, error);
|
|
120
|
+
} catch (errInner) {
|
|
121
|
+
_chunkJKW6E4L3cjs.logWithLevel.call(void 0, xray.config.logger, "warn", xray.config.logLevel, "xray: onError failed", {
|
|
122
|
+
error: errInner instanceof Error ? errInner.message : String(errInner)
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (_optionalChain([options, 'optionalAccess', _9 => _9.onResponse])) {
|
|
127
|
+
try {
|
|
128
|
+
options.onResponse(ctx, log);
|
|
129
|
+
} catch (errInner) {
|
|
130
|
+
_chunkJKW6E4L3cjs.logWithLevel.call(void 0,
|
|
131
|
+
xray.config.logger,
|
|
132
|
+
"warn",
|
|
133
|
+
xray.config.logLevel,
|
|
134
|
+
"xray: onResponse failed",
|
|
135
|
+
{
|
|
136
|
+
error: errInner instanceof Error ? errInner.message : String(errInner)
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return yield* _effect.Effect.failCause(exit.cause);
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
function getXrayContext(request) {
|
|
145
|
+
return _chunkGNSXLLECcjs.getXrayContextFromObject.call(void 0, request);
|
|
146
|
+
}
|
|
147
|
+
var currentXrayContext = _effect.Effect.map(_platform.HttpServerRequest.HttpServerRequest, (request) => _chunkGNSXLLECcjs.getXrayContextFromObject.call(void 0, request));
|
|
148
|
+
function effectHeadersToRecord(headers) {
|
|
149
|
+
const result = {};
|
|
150
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
151
|
+
if (typeof value === "string") {
|
|
152
|
+
result[key] = value;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
function buildFullUrl(url, headers) {
|
|
158
|
+
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
159
|
+
return url;
|
|
160
|
+
}
|
|
161
|
+
const host = headers["host"];
|
|
162
|
+
if (!host || typeof host !== "string") {
|
|
163
|
+
return url;
|
|
164
|
+
}
|
|
165
|
+
return `http://${host}${url}`;
|
|
166
|
+
}
|
|
167
|
+
function captureResponseBody(xray, response) {
|
|
168
|
+
const mode = xray.config.capture.responseBody;
|
|
169
|
+
if (!mode || mode === "none") return void 0;
|
|
170
|
+
const body = response.body;
|
|
171
|
+
if (body._tag === "Uint8Array" && body.body instanceof Uint8Array) {
|
|
172
|
+
const maxBytes = xray.config.capture.maxBodyBytes;
|
|
173
|
+
const truncated = body.body.length > maxBytes;
|
|
174
|
+
const slice = truncated ? body.body.slice(0, maxBytes) : body.body;
|
|
175
|
+
return _chunkJKW6E4L3cjs.makeCapturedBody.call(void 0, slice, body.body.length, truncated, mode);
|
|
176
|
+
}
|
|
177
|
+
return void 0;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
exports.createCoreEmitter = _chunkDBI3HXNRcjs.createEmitter; exports.createEffectMiddleware = createEffectMiddleware; exports.createEmitter = createEmitter2; exports.currentXrayContext = currentXrayContext; exports.getXrayContext = getXrayContext;
|
|
186
|
+
//# sourceMappingURL=effect.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/xray-emitter-js/xray-emitter-js/dist/effect.cjs","../src/effect/effect.ts"],"names":["createEmitter","log"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACjBA,gCAA4C;AAC5C,4CAAiF;AAkD1E,SAASA,cAAAA,CAAc,MAAA,EAA2B,OAAA,EAAsC;AAC7F,EAAA,MAAM,QAAA,EAAU,6CAAA,MAAyB,CAAA;AACzC,EAAA,MAAM,WAAA,EAAa,sBAAA,CAAuB,OAAA,EAAS,OAAO,CAAA;AAC1D,EAAA,UAAA,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,GAAA;AAAA,EACT;AACA,EAAA,MAAM,KAAA,EAAO,OAAA,CAAQ,MAAM,CAAA;AAC3B,EAAA,GAAA,CAAI,CAAC,KAAA,GAAQ,OAAO,KAAA,IAAS,QAAA,EAAU;AACrC,IAAA,OAAO,GAAA;AAAA,EACT;AACA,EAAA,OAAO,CAAA,OAAA,EAAU,IAAI,CAAA,EAAA;AACvB;AAES;AAIW,EAAA;AACI,EAAA;AAEA,EAAA;AACJ,EAAA;AACC,IAAA;AACC,IAAA;AACJ,IAAA;AACP,IAAA;AACT,EAAA;AACO,EAAA;AACT;ADhFwB;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/xray-emitter-js/xray-emitter-js/dist/effect.cjs","sourcesContent":[null,"import { Cause, Effect, Exit, Option } from 'effect';\nimport { Headers, HttpApp, HttpRouter, HttpServerError, HttpServerRequest } from '@effect/platform';\nimport type {\n CaptureConfig,\n NormalizedRequest,\n RedactionConfig,\n RequestLog,\n XrayContext,\n XrayEmitter,\n XrayRuntimeConfig,\n} from '../core/index';\nimport { createEmitter as createFetchEmitter } from '../fetch/fetch';\nimport {\n bindContextToObject,\n getXrayContextFromObject,\n logWithLevel,\n makeCapturedBody,\n setCaptureOverride,\n setContextRequestId,\n setContextRoute,\n setRedactionOverride,\n} from '../core/internal';\n\nexport { createEmitter as createCoreEmitter } from '../fetch/fetch';\nexport type {\n CaptureConfig,\n RedactionConfig,\n RequestLog,\n XrayConfig,\n XrayContext,\n XrayEmitter,\n XrayRuntimeConfig,\n} from '../core/index';\n\nexport interface WrapOptions {\n route?: string;\n requestId?: string;\n capture?: Partial<CaptureConfig>;\n redaction?: Partial<RedactionConfig>;\n onRequest?: (ctx: XrayContext) => void;\n onResponse?: (ctx: XrayContext, log: RequestLog) => void;\n onError?: (ctx: XrayContext, err: unknown) => void;\n}\n\ntype EffectMiddleware = <E, R>(httpApp: HttpApp.Default<E, R>) => HttpApp.Default<E, R>;\n\ntype EffectEmitter = EffectMiddleware & {\n flush: XrayEmitter['flush'];\n shutdown: XrayEmitter['shutdown'];\n};\n\nexport function createEmitter(config: XrayRuntimeConfig, options?: WrapOptions): EffectEmitter {\n const emitter = createFetchEmitter(config);\n const middleware = createEffectMiddleware(emitter, options) as EffectEmitter;\n middleware.flush = emitter.flush;\n middleware.shutdown = emitter.shutdown;\n return middleware;\n}\n\nexport function createEffectMiddleware(xray: XrayEmitter, options?: WrapOptions): EffectMiddleware {\n return (<E, R>(httpApp: HttpApp.Default<E, R>): HttpApp.Default<E, R> =>\n Effect.gen(function* () {\n const request = yield* HttpServerRequest.HttpServerRequest;\n\n const headers = effectHeadersToRecord(request.headers);\n const url = buildFullUrl(request.originalUrl, headers);\n\n // Try to read the route pattern from HttpRouter.RouteContext (available\n // when the middleware is applied via HttpRouter.use).\n const routeCtxOption = yield* Effect.serviceOption(HttpRouter.RouteContext);\n const route = Option.isSome(routeCtxOption)\n ? String(routeCtxOption.value.route.path)\n : options?.route;\n\n // Capture request body if configured.\n const captureReqBody = xray.config.capture.requestBody;\n let requestBody: NormalizedRequest['body'];\n if (captureReqBody && captureReqBody !== 'none') {\n const textResult = yield* Effect.either(request.text);\n if (textResult._tag === 'Right') {\n const bytes = new TextEncoder().encode(textResult.right);\n const maxBytes = xray.config.capture.maxBodyBytes;\n const truncated = bytes.length > maxBytes;\n const slice = truncated ? bytes.slice(0, maxBytes) : bytes;\n requestBody = makeCapturedBody(slice, bytes.length, truncated, captureReqBody);\n }\n }\n\n const normalizedRequest: NormalizedRequest = {\n method: request.method,\n url,\n route,\n headers,\n body: requestBody,\n requestId: options?.requestId,\n remoteAddress:\n request.remoteAddress._tag === 'Some' ? request.remoteAddress.value : undefined,\n startTimeMs: Date.now(),\n };\n\n const ctx = xray.startRequest(normalizedRequest);\n bindContextToObject(request, ctx);\n\n if (options?.requestId) {\n setContextRequestId(ctx, options.requestId);\n }\n if (route) {\n setContextRoute(ctx, route);\n }\n if (options?.capture) {\n setCaptureOverride(ctx, options.capture);\n }\n if (options?.redaction) {\n setRedactionOverride(ctx, options.redaction);\n }\n\n if (options?.onRequest) {\n try {\n options.onRequest(ctx);\n } catch (err) {\n logWithLevel(xray.config.logger, 'warn', xray.config.logLevel, 'xray: onRequest failed', {\n error: err instanceof Error ? err.message : String(err),\n });\n }\n }\n\n const exit = yield* Effect.exit(httpApp);\n\n if (Exit.isSuccess(exit)) {\n const response = exit.value;\n const responseHeaders = effectHeadersToRecord(response.headers);\n\n const log = xray.endRequest(ctx, {\n statusCode: response.status,\n headers: responseHeaders,\n body: captureResponseBody(xray, response),\n endTimeMs: Date.now(),\n });\n\n if (options?.onResponse) {\n try {\n options.onResponse(ctx, log);\n } catch (err) {\n logWithLevel(\n xray.config.logger,\n 'warn',\n xray.config.logLevel,\n 'xray: onResponse failed',\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n }\n\n return response;\n }\n\n const error = Cause.squash(exit.cause);\n\n // Resolve the HTTP response that the platform would send for this error\n // (e.g. 404 for RouteNotFound, 500 for unhandled). This mirrors what\n // HttpApp.toWebHandler does internally via causeResponse.\n const [errorResponse] = yield* HttpServerError.causeResponse(exit.cause);\n\n const log = xray.endRequest(\n ctx,\n {\n statusCode: errorResponse.status,\n headers: effectHeadersToRecord(errorResponse.headers),\n body: undefined,\n endTimeMs: Date.now(),\n },\n error,\n );\n\n if (options?.onError) {\n try {\n options.onError(ctx, error);\n } catch (errInner) {\n logWithLevel(xray.config.logger, 'warn', xray.config.logLevel, 'xray: onError failed', {\n error: errInner instanceof Error ? errInner.message : String(errInner),\n });\n }\n }\n\n if (options?.onResponse) {\n try {\n options.onResponse(ctx, log);\n } catch (errInner) {\n logWithLevel(\n xray.config.logger,\n 'warn',\n xray.config.logLevel,\n 'xray: onResponse failed',\n {\n error: errInner instanceof Error ? errInner.message : String(errInner),\n },\n );\n }\n }\n\n return yield* Effect.failCause(exit.cause);\n })) as EffectMiddleware;\n}\n\n/**\n * Retrieve the XrayContext bound to a request object.\n */\nexport function getXrayContext(\n request: HttpServerRequest.HttpServerRequest,\n): XrayContext | undefined {\n return getXrayContextFromObject(request);\n}\n\n/**\n * Effect that retrieves the XrayContext from the current HttpServerRequest in scope.\n */\nexport const currentXrayContext: Effect.Effect<\n XrayContext | undefined,\n never,\n HttpServerRequest.HttpServerRequest\n> = Effect.map(HttpServerRequest.HttpServerRequest, (request) => getXrayContextFromObject(request));\n\nfunction effectHeadersToRecord(headers: Headers.Headers): Record<string, string | string[]> {\n const result: Record<string, string | string[]> = {};\n for (const [key, value] of Object.entries(headers)) {\n if (typeof value === 'string') {\n result[key] = value;\n }\n }\n return result;\n}\n\nfunction buildFullUrl(url: string, headers: Record<string, string | string[]>): string {\n if (url.startsWith('http://') || url.startsWith('https://')) {\n return url;\n }\n const host = headers['host'];\n if (!host || typeof host !== 'string') {\n return url;\n }\n return `http://${host}${url}`;\n}\n\nfunction captureResponseBody(\n xray: XrayEmitter,\n response: { body: { _tag: string; body?: unknown; contentLength?: number } },\n): ReturnType<typeof makeCapturedBody> {\n const mode = xray.config.capture.responseBody;\n if (!mode || mode === 'none') return undefined;\n\n const body = response.body;\n if (body._tag === 'Uint8Array' && body.body instanceof Uint8Array) {\n const maxBytes = xray.config.capture.maxBodyBytes;\n const truncated = body.body.length > maxBytes;\n const slice = truncated ? body.body.slice(0, maxBytes) : body.body;\n return makeCapturedBody(slice, body.body.length, truncated, mode);\n }\n return undefined;\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { HttpApp, HttpServerRequest } from '@effect/platform';
|
|
3
|
+
import { e as CaptureConfig, f as RedactionConfig, d as XrayContext, R as RequestLog, j as XrayRuntimeConfig, a as XrayEmitter } from './types-Z1nirh-F.cjs';
|
|
4
|
+
export { X as XrayConfig } from './types-Z1nirh-F.cjs';
|
|
5
|
+
export { c as createCoreEmitter } from './emitter-BqfrGIod.cjs';
|
|
6
|
+
import '@opentelemetry/sdk-trace-base';
|
|
7
|
+
|
|
8
|
+
interface WrapOptions {
|
|
9
|
+
route?: string;
|
|
10
|
+
requestId?: string;
|
|
11
|
+
capture?: Partial<CaptureConfig>;
|
|
12
|
+
redaction?: Partial<RedactionConfig>;
|
|
13
|
+
onRequest?: (ctx: XrayContext) => void;
|
|
14
|
+
onResponse?: (ctx: XrayContext, log: RequestLog) => void;
|
|
15
|
+
onError?: (ctx: XrayContext, err: unknown) => void;
|
|
16
|
+
}
|
|
17
|
+
type EffectMiddleware = <E, R>(httpApp: HttpApp.Default<E, R>) => HttpApp.Default<E, R>;
|
|
18
|
+
type EffectEmitter = EffectMiddleware & {
|
|
19
|
+
flush: XrayEmitter['flush'];
|
|
20
|
+
shutdown: XrayEmitter['shutdown'];
|
|
21
|
+
};
|
|
22
|
+
declare function createEmitter(config: XrayRuntimeConfig, options?: WrapOptions): EffectEmitter;
|
|
23
|
+
declare function createEffectMiddleware(xray: XrayEmitter, options?: WrapOptions): EffectMiddleware;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieve the XrayContext bound to a request object.
|
|
26
|
+
*/
|
|
27
|
+
declare function getXrayContext(request: HttpServerRequest.HttpServerRequest): XrayContext | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Effect that retrieves the XrayContext from the current HttpServerRequest in scope.
|
|
30
|
+
*/
|
|
31
|
+
declare const currentXrayContext: Effect.Effect<XrayContext | undefined, never, HttpServerRequest.HttpServerRequest>;
|
|
32
|
+
|
|
33
|
+
export { CaptureConfig, RedactionConfig, RequestLog, type WrapOptions, XrayContext, XrayEmitter, XrayRuntimeConfig, createEffectMiddleware, createEmitter, currentXrayContext, getXrayContext };
|
package/dist/effect.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { HttpApp, HttpServerRequest } from '@effect/platform';
|
|
3
|
+
import { e as CaptureConfig, f as RedactionConfig, d as XrayContext, R as RequestLog, j as XrayRuntimeConfig, a as XrayEmitter } from './types-Z1nirh-F.js';
|
|
4
|
+
export { X as XrayConfig } from './types-Z1nirh-F.js';
|
|
5
|
+
export { c as createCoreEmitter } from './emitter-CScYhwGA.js';
|
|
6
|
+
import '@opentelemetry/sdk-trace-base';
|
|
7
|
+
|
|
8
|
+
interface WrapOptions {
|
|
9
|
+
route?: string;
|
|
10
|
+
requestId?: string;
|
|
11
|
+
capture?: Partial<CaptureConfig>;
|
|
12
|
+
redaction?: Partial<RedactionConfig>;
|
|
13
|
+
onRequest?: (ctx: XrayContext) => void;
|
|
14
|
+
onResponse?: (ctx: XrayContext, log: RequestLog) => void;
|
|
15
|
+
onError?: (ctx: XrayContext, err: unknown) => void;
|
|
16
|
+
}
|
|
17
|
+
type EffectMiddleware = <E, R>(httpApp: HttpApp.Default<E, R>) => HttpApp.Default<E, R>;
|
|
18
|
+
type EffectEmitter = EffectMiddleware & {
|
|
19
|
+
flush: XrayEmitter['flush'];
|
|
20
|
+
shutdown: XrayEmitter['shutdown'];
|
|
21
|
+
};
|
|
22
|
+
declare function createEmitter(config: XrayRuntimeConfig, options?: WrapOptions): EffectEmitter;
|
|
23
|
+
declare function createEffectMiddleware(xray: XrayEmitter, options?: WrapOptions): EffectMiddleware;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieve the XrayContext bound to a request object.
|
|
26
|
+
*/
|
|
27
|
+
declare function getXrayContext(request: HttpServerRequest.HttpServerRequest): XrayContext | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Effect that retrieves the XrayContext from the current HttpServerRequest in scope.
|
|
30
|
+
*/
|
|
31
|
+
declare const currentXrayContext: Effect.Effect<XrayContext | undefined, never, HttpServerRequest.HttpServerRequest>;
|
|
32
|
+
|
|
33
|
+
export { CaptureConfig, RedactionConfig, RequestLog, type WrapOptions, XrayContext, XrayEmitter, XrayRuntimeConfig, createEffectMiddleware, createEmitter, currentXrayContext, getXrayContext };
|
package/dist/effect.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createEmitter
|
|
3
|
+
} from "./chunk-ZP5OEA4I.js";
|
|
4
|
+
import "./chunk-TSCMZ5TV.js";
|
|
5
|
+
import {
|
|
6
|
+
bindContextToObject,
|
|
7
|
+
getXrayContextFromObject,
|
|
8
|
+
setCaptureOverride,
|
|
9
|
+
setContextRequestId,
|
|
10
|
+
setContextRoute,
|
|
11
|
+
setRedactionOverride
|
|
12
|
+
} from "./chunk-6UH43LVD.js";
|
|
13
|
+
import {
|
|
14
|
+
logWithLevel,
|
|
15
|
+
makeCapturedBody
|
|
16
|
+
} from "./chunk-YVMMCTXW.js";
|
|
17
|
+
|
|
18
|
+
// src/effect/effect.ts
|
|
19
|
+
import { Cause, Effect, Exit, Option } from "effect";
|
|
20
|
+
import { HttpRouter, HttpServerError, HttpServerRequest } from "@effect/platform";
|
|
21
|
+
function createEmitter2(config, options) {
|
|
22
|
+
const emitter = createEmitter(config);
|
|
23
|
+
const middleware = createEffectMiddleware(emitter, options);
|
|
24
|
+
middleware.flush = emitter.flush;
|
|
25
|
+
middleware.shutdown = emitter.shutdown;
|
|
26
|
+
return middleware;
|
|
27
|
+
}
|
|
28
|
+
function createEffectMiddleware(xray, options) {
|
|
29
|
+
return ((httpApp) => Effect.gen(function* () {
|
|
30
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
31
|
+
const headers = effectHeadersToRecord(request.headers);
|
|
32
|
+
const url = buildFullUrl(request.originalUrl, headers);
|
|
33
|
+
const routeCtxOption = yield* Effect.serviceOption(HttpRouter.RouteContext);
|
|
34
|
+
const route = Option.isSome(routeCtxOption) ? String(routeCtxOption.value.route.path) : options?.route;
|
|
35
|
+
const captureReqBody = xray.config.capture.requestBody;
|
|
36
|
+
let requestBody;
|
|
37
|
+
if (captureReqBody && captureReqBody !== "none") {
|
|
38
|
+
const textResult = yield* Effect.either(request.text);
|
|
39
|
+
if (textResult._tag === "Right") {
|
|
40
|
+
const bytes = new TextEncoder().encode(textResult.right);
|
|
41
|
+
const maxBytes = xray.config.capture.maxBodyBytes;
|
|
42
|
+
const truncated = bytes.length > maxBytes;
|
|
43
|
+
const slice = truncated ? bytes.slice(0, maxBytes) : bytes;
|
|
44
|
+
requestBody = makeCapturedBody(slice, bytes.length, truncated, captureReqBody);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const normalizedRequest = {
|
|
48
|
+
method: request.method,
|
|
49
|
+
url,
|
|
50
|
+
route,
|
|
51
|
+
headers,
|
|
52
|
+
body: requestBody,
|
|
53
|
+
requestId: options?.requestId,
|
|
54
|
+
remoteAddress: request.remoteAddress._tag === "Some" ? request.remoteAddress.value : void 0,
|
|
55
|
+
startTimeMs: Date.now()
|
|
56
|
+
};
|
|
57
|
+
const ctx = xray.startRequest(normalizedRequest);
|
|
58
|
+
bindContextToObject(request, ctx);
|
|
59
|
+
if (options?.requestId) {
|
|
60
|
+
setContextRequestId(ctx, options.requestId);
|
|
61
|
+
}
|
|
62
|
+
if (route) {
|
|
63
|
+
setContextRoute(ctx, route);
|
|
64
|
+
}
|
|
65
|
+
if (options?.capture) {
|
|
66
|
+
setCaptureOverride(ctx, options.capture);
|
|
67
|
+
}
|
|
68
|
+
if (options?.redaction) {
|
|
69
|
+
setRedactionOverride(ctx, options.redaction);
|
|
70
|
+
}
|
|
71
|
+
if (options?.onRequest) {
|
|
72
|
+
try {
|
|
73
|
+
options.onRequest(ctx);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
logWithLevel(xray.config.logger, "warn", xray.config.logLevel, "xray: onRequest failed", {
|
|
76
|
+
error: err instanceof Error ? err.message : String(err)
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const exit = yield* Effect.exit(httpApp);
|
|
81
|
+
if (Exit.isSuccess(exit)) {
|
|
82
|
+
const response = exit.value;
|
|
83
|
+
const responseHeaders = effectHeadersToRecord(response.headers);
|
|
84
|
+
const log2 = xray.endRequest(ctx, {
|
|
85
|
+
statusCode: response.status,
|
|
86
|
+
headers: responseHeaders,
|
|
87
|
+
body: captureResponseBody(xray, response),
|
|
88
|
+
endTimeMs: Date.now()
|
|
89
|
+
});
|
|
90
|
+
if (options?.onResponse) {
|
|
91
|
+
try {
|
|
92
|
+
options.onResponse(ctx, log2);
|
|
93
|
+
} catch (err) {
|
|
94
|
+
logWithLevel(
|
|
95
|
+
xray.config.logger,
|
|
96
|
+
"warn",
|
|
97
|
+
xray.config.logLevel,
|
|
98
|
+
"xray: onResponse failed",
|
|
99
|
+
{ error: err instanceof Error ? err.message : String(err) }
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return response;
|
|
104
|
+
}
|
|
105
|
+
const error = Cause.squash(exit.cause);
|
|
106
|
+
const [errorResponse] = yield* HttpServerError.causeResponse(exit.cause);
|
|
107
|
+
const log = xray.endRequest(
|
|
108
|
+
ctx,
|
|
109
|
+
{
|
|
110
|
+
statusCode: errorResponse.status,
|
|
111
|
+
headers: effectHeadersToRecord(errorResponse.headers),
|
|
112
|
+
body: void 0,
|
|
113
|
+
endTimeMs: Date.now()
|
|
114
|
+
},
|
|
115
|
+
error
|
|
116
|
+
);
|
|
117
|
+
if (options?.onError) {
|
|
118
|
+
try {
|
|
119
|
+
options.onError(ctx, error);
|
|
120
|
+
} catch (errInner) {
|
|
121
|
+
logWithLevel(xray.config.logger, "warn", xray.config.logLevel, "xray: onError failed", {
|
|
122
|
+
error: errInner instanceof Error ? errInner.message : String(errInner)
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (options?.onResponse) {
|
|
127
|
+
try {
|
|
128
|
+
options.onResponse(ctx, log);
|
|
129
|
+
} catch (errInner) {
|
|
130
|
+
logWithLevel(
|
|
131
|
+
xray.config.logger,
|
|
132
|
+
"warn",
|
|
133
|
+
xray.config.logLevel,
|
|
134
|
+
"xray: onResponse failed",
|
|
135
|
+
{
|
|
136
|
+
error: errInner instanceof Error ? errInner.message : String(errInner)
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return yield* Effect.failCause(exit.cause);
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
function getXrayContext(request) {
|
|
145
|
+
return getXrayContextFromObject(request);
|
|
146
|
+
}
|
|
147
|
+
var currentXrayContext = Effect.map(HttpServerRequest.HttpServerRequest, (request) => getXrayContextFromObject(request));
|
|
148
|
+
function effectHeadersToRecord(headers) {
|
|
149
|
+
const result = {};
|
|
150
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
151
|
+
if (typeof value === "string") {
|
|
152
|
+
result[key] = value;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
function buildFullUrl(url, headers) {
|
|
158
|
+
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
159
|
+
return url;
|
|
160
|
+
}
|
|
161
|
+
const host = headers["host"];
|
|
162
|
+
if (!host || typeof host !== "string") {
|
|
163
|
+
return url;
|
|
164
|
+
}
|
|
165
|
+
return `http://${host}${url}`;
|
|
166
|
+
}
|
|
167
|
+
function captureResponseBody(xray, response) {
|
|
168
|
+
const mode = xray.config.capture.responseBody;
|
|
169
|
+
if (!mode || mode === "none") return void 0;
|
|
170
|
+
const body = response.body;
|
|
171
|
+
if (body._tag === "Uint8Array" && body.body instanceof Uint8Array) {
|
|
172
|
+
const maxBytes = xray.config.capture.maxBodyBytes;
|
|
173
|
+
const truncated = body.body.length > maxBytes;
|
|
174
|
+
const slice = truncated ? body.body.slice(0, maxBytes) : body.body;
|
|
175
|
+
return makeCapturedBody(slice, body.body.length, truncated, mode);
|
|
176
|
+
}
|
|
177
|
+
return void 0;
|
|
178
|
+
}
|
|
179
|
+
export {
|
|
180
|
+
createEmitter as createCoreEmitter,
|
|
181
|
+
createEffectMiddleware,
|
|
182
|
+
createEmitter2 as createEmitter,
|
|
183
|
+
currentXrayContext,
|
|
184
|
+
getXrayContext
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=effect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/effect/effect.ts"],"sourcesContent":["import { Cause, Effect, Exit, Option } from 'effect';\nimport { Headers, HttpApp, HttpRouter, HttpServerError, HttpServerRequest } from '@effect/platform';\nimport type {\n CaptureConfig,\n NormalizedRequest,\n RedactionConfig,\n RequestLog,\n XrayContext,\n XrayEmitter,\n XrayRuntimeConfig,\n} from '../core/index';\nimport { createEmitter as createFetchEmitter } from '../fetch/fetch';\nimport {\n bindContextToObject,\n getXrayContextFromObject,\n logWithLevel,\n makeCapturedBody,\n setCaptureOverride,\n setContextRequestId,\n setContextRoute,\n setRedactionOverride,\n} from '../core/internal';\n\nexport { createEmitter as createCoreEmitter } from '../fetch/fetch';\nexport type {\n CaptureConfig,\n RedactionConfig,\n RequestLog,\n XrayConfig,\n XrayContext,\n XrayEmitter,\n XrayRuntimeConfig,\n} from '../core/index';\n\nexport interface WrapOptions {\n route?: string;\n requestId?: string;\n capture?: Partial<CaptureConfig>;\n redaction?: Partial<RedactionConfig>;\n onRequest?: (ctx: XrayContext) => void;\n onResponse?: (ctx: XrayContext, log: RequestLog) => void;\n onError?: (ctx: XrayContext, err: unknown) => void;\n}\n\ntype EffectMiddleware = <E, R>(httpApp: HttpApp.Default<E, R>) => HttpApp.Default<E, R>;\n\ntype EffectEmitter = EffectMiddleware & {\n flush: XrayEmitter['flush'];\n shutdown: XrayEmitter['shutdown'];\n};\n\nexport function createEmitter(config: XrayRuntimeConfig, options?: WrapOptions): EffectEmitter {\n const emitter = createFetchEmitter(config);\n const middleware = createEffectMiddleware(emitter, options) as EffectEmitter;\n middleware.flush = emitter.flush;\n middleware.shutdown = emitter.shutdown;\n return middleware;\n}\n\nexport function createEffectMiddleware(xray: XrayEmitter, options?: WrapOptions): EffectMiddleware {\n return (<E, R>(httpApp: HttpApp.Default<E, R>): HttpApp.Default<E, R> =>\n Effect.gen(function* () {\n const request = yield* HttpServerRequest.HttpServerRequest;\n\n const headers = effectHeadersToRecord(request.headers);\n const url = buildFullUrl(request.originalUrl, headers);\n\n // Try to read the route pattern from HttpRouter.RouteContext (available\n // when the middleware is applied via HttpRouter.use).\n const routeCtxOption = yield* Effect.serviceOption(HttpRouter.RouteContext);\n const route = Option.isSome(routeCtxOption)\n ? String(routeCtxOption.value.route.path)\n : options?.route;\n\n // Capture request body if configured.\n const captureReqBody = xray.config.capture.requestBody;\n let requestBody: NormalizedRequest['body'];\n if (captureReqBody && captureReqBody !== 'none') {\n const textResult = yield* Effect.either(request.text);\n if (textResult._tag === 'Right') {\n const bytes = new TextEncoder().encode(textResult.right);\n const maxBytes = xray.config.capture.maxBodyBytes;\n const truncated = bytes.length > maxBytes;\n const slice = truncated ? bytes.slice(0, maxBytes) : bytes;\n requestBody = makeCapturedBody(slice, bytes.length, truncated, captureReqBody);\n }\n }\n\n const normalizedRequest: NormalizedRequest = {\n method: request.method,\n url,\n route,\n headers,\n body: requestBody,\n requestId: options?.requestId,\n remoteAddress:\n request.remoteAddress._tag === 'Some' ? request.remoteAddress.value : undefined,\n startTimeMs: Date.now(),\n };\n\n const ctx = xray.startRequest(normalizedRequest);\n bindContextToObject(request, ctx);\n\n if (options?.requestId) {\n setContextRequestId(ctx, options.requestId);\n }\n if (route) {\n setContextRoute(ctx, route);\n }\n if (options?.capture) {\n setCaptureOverride(ctx, options.capture);\n }\n if (options?.redaction) {\n setRedactionOverride(ctx, options.redaction);\n }\n\n if (options?.onRequest) {\n try {\n options.onRequest(ctx);\n } catch (err) {\n logWithLevel(xray.config.logger, 'warn', xray.config.logLevel, 'xray: onRequest failed', {\n error: err instanceof Error ? err.message : String(err),\n });\n }\n }\n\n const exit = yield* Effect.exit(httpApp);\n\n if (Exit.isSuccess(exit)) {\n const response = exit.value;\n const responseHeaders = effectHeadersToRecord(response.headers);\n\n const log = xray.endRequest(ctx, {\n statusCode: response.status,\n headers: responseHeaders,\n body: captureResponseBody(xray, response),\n endTimeMs: Date.now(),\n });\n\n if (options?.onResponse) {\n try {\n options.onResponse(ctx, log);\n } catch (err) {\n logWithLevel(\n xray.config.logger,\n 'warn',\n xray.config.logLevel,\n 'xray: onResponse failed',\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n }\n\n return response;\n }\n\n const error = Cause.squash(exit.cause);\n\n // Resolve the HTTP response that the platform would send for this error\n // (e.g. 404 for RouteNotFound, 500 for unhandled). This mirrors what\n // HttpApp.toWebHandler does internally via causeResponse.\n const [errorResponse] = yield* HttpServerError.causeResponse(exit.cause);\n\n const log = xray.endRequest(\n ctx,\n {\n statusCode: errorResponse.status,\n headers: effectHeadersToRecord(errorResponse.headers),\n body: undefined,\n endTimeMs: Date.now(),\n },\n error,\n );\n\n if (options?.onError) {\n try {\n options.onError(ctx, error);\n } catch (errInner) {\n logWithLevel(xray.config.logger, 'warn', xray.config.logLevel, 'xray: onError failed', {\n error: errInner instanceof Error ? errInner.message : String(errInner),\n });\n }\n }\n\n if (options?.onResponse) {\n try {\n options.onResponse(ctx, log);\n } catch (errInner) {\n logWithLevel(\n xray.config.logger,\n 'warn',\n xray.config.logLevel,\n 'xray: onResponse failed',\n {\n error: errInner instanceof Error ? errInner.message : String(errInner),\n },\n );\n }\n }\n\n return yield* Effect.failCause(exit.cause);\n })) as EffectMiddleware;\n}\n\n/**\n * Retrieve the XrayContext bound to a request object.\n */\nexport function getXrayContext(\n request: HttpServerRequest.HttpServerRequest,\n): XrayContext | undefined {\n return getXrayContextFromObject(request);\n}\n\n/**\n * Effect that retrieves the XrayContext from the current HttpServerRequest in scope.\n */\nexport const currentXrayContext: Effect.Effect<\n XrayContext | undefined,\n never,\n HttpServerRequest.HttpServerRequest\n> = Effect.map(HttpServerRequest.HttpServerRequest, (request) => getXrayContextFromObject(request));\n\nfunction effectHeadersToRecord(headers: Headers.Headers): Record<string, string | string[]> {\n const result: Record<string, string | string[]> = {};\n for (const [key, value] of Object.entries(headers)) {\n if (typeof value === 'string') {\n result[key] = value;\n }\n }\n return result;\n}\n\nfunction buildFullUrl(url: string, headers: Record<string, string | string[]>): string {\n if (url.startsWith('http://') || url.startsWith('https://')) {\n return url;\n }\n const host = headers['host'];\n if (!host || typeof host !== 'string') {\n return url;\n }\n return `http://${host}${url}`;\n}\n\nfunction captureResponseBody(\n xray: XrayEmitter,\n response: { body: { _tag: string; body?: unknown; contentLength?: number } },\n): ReturnType<typeof makeCapturedBody> {\n const mode = xray.config.capture.responseBody;\n if (!mode || mode === 'none') return undefined;\n\n const body = response.body;\n if (body._tag === 'Uint8Array' && body.body instanceof Uint8Array) {\n const maxBytes = xray.config.capture.maxBodyBytes;\n const truncated = body.body.length > maxBytes;\n const slice = truncated ? body.body.slice(0, maxBytes) : body.body;\n return makeCapturedBody(slice, body.body.length, truncated, mode);\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,OAAO,QAAQ,MAAM,cAAc;AAC5C,SAA2B,YAAY,iBAAiB,yBAAyB;AAkD1E,SAASA,eAAc,QAA2B,SAAsC;AAC7F,QAAM,UAAU,cAAmB,MAAM;AACzC,QAAM,aAAa,uBAAuB,SAAS,OAAO;AAC1D,aAAW,QAAQ,QAAQ;AAC3B,aAAW,WAAW,QAAQ;AAC9B,SAAO;AACT;AAEO,SAAS,uBAAuB,MAAmB,SAAyC;AACjG,UAAQ,CAAO,YACb,OAAO,IAAI,aAAa;AACtB,UAAM,UAAU,OAAO,kBAAkB;AAEzC,UAAM,UAAU,sBAAsB,QAAQ,OAAO;AACrD,UAAM,MAAM,aAAa,QAAQ,aAAa,OAAO;AAIrD,UAAM,iBAAiB,OAAO,OAAO,cAAc,WAAW,YAAY;AAC1E,UAAM,QAAQ,OAAO,OAAO,cAAc,IACtC,OAAO,eAAe,MAAM,MAAM,IAAI,IACtC,SAAS;AAGb,UAAM,iBAAiB,KAAK,OAAO,QAAQ;AAC3C,QAAI;AACJ,QAAI,kBAAkB,mBAAmB,QAAQ;AAC/C,YAAM,aAAa,OAAO,OAAO,OAAO,QAAQ,IAAI;AACpD,UAAI,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+
export { c as createEmitter } from './emitter-BqfrGIod.cjs';
|
|
2
|
+
import { a as XrayEmitter, e as CaptureConfig, f as RedactionConfig, d as XrayContext, R as RequestLog } from './types-Z1nirh-F.cjs';
|
|
2
3
|
import '@opentelemetry/sdk-trace-base';
|
|
3
4
|
|
|
4
|
-
declare function createEmitter(config: XrayRuntimeConfig): XrayEmitter;
|
|
5
|
-
|
|
6
5
|
interface WrapOptions {
|
|
7
6
|
route?: string;
|
|
8
7
|
requestId?: string;
|
|
@@ -16,4 +15,4 @@ declare function wrapFetch(handler: (req: Request) => Response | Promise<Respons
|
|
|
16
15
|
declare function wrapFetchPreserve(handler: (req: Request) => Response | Promise<Response>, xray: XrayEmitter, options?: WrapOptions): (req: Request) => Promise<Response>;
|
|
17
16
|
declare function getXrayContext(req: Request): XrayContext | undefined;
|
|
18
17
|
|
|
19
|
-
export { type WrapOptions,
|
|
18
|
+
export { type WrapOptions, getXrayContext, wrapFetch, wrapFetchPreserve };
|
package/dist/fetch.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
export { c as createEmitter } from './emitter-CScYhwGA.js';
|
|
2
|
+
import { a as XrayEmitter, e as CaptureConfig, f as RedactionConfig, d as XrayContext, R as RequestLog } from './types-Z1nirh-F.js';
|
|
2
3
|
import '@opentelemetry/sdk-trace-base';
|
|
3
4
|
|
|
4
|
-
declare function createEmitter(config: XrayRuntimeConfig): XrayEmitter;
|
|
5
|
-
|
|
6
5
|
interface WrapOptions {
|
|
7
6
|
route?: string;
|
|
8
7
|
requestId?: string;
|
|
@@ -16,4 +15,4 @@ declare function wrapFetch(handler: (req: Request) => Response | Promise<Respons
|
|
|
16
15
|
declare function wrapFetchPreserve(handler: (req: Request) => Response | Promise<Response>, xray: XrayEmitter, options?: WrapOptions): (req: Request) => Promise<Response>;
|
|
17
16
|
declare function getXrayContext(req: Request): XrayContext | undefined;
|
|
18
17
|
|
|
19
|
-
export { type WrapOptions,
|
|
18
|
+
export { type WrapOptions, getXrayContext, wrapFetch, wrapFetchPreserve };
|
package/dist/hono.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { d as XrayContext, j as XrayRuntimeConfig, a as XrayEmitter } from './types-Z1nirh-F.cjs';
|
|
2
2
|
export { e as CaptureConfig, f as RedactionConfig, R as RequestLog, X as XrayConfig } from './types-Z1nirh-F.cjs';
|
|
3
|
+
export { c as createCoreEmitter } from './emitter-BqfrGIod.cjs';
|
|
3
4
|
import { WrapOptions } from './fetch.cjs';
|
|
4
|
-
export { createEmitter as createCoreEmitter } from './fetch.cjs';
|
|
5
5
|
import '@opentelemetry/sdk-trace-base';
|
|
6
6
|
|
|
7
7
|
interface HonoCompatibleContext {
|
package/dist/hono.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { d as XrayContext, j as XrayRuntimeConfig, a as XrayEmitter } from './types-Z1nirh-F.js';
|
|
2
2
|
export { e as CaptureConfig, f as RedactionConfig, R as RequestLog, X as XrayConfig } from './types-Z1nirh-F.js';
|
|
3
|
+
export { c as createCoreEmitter } from './emitter-CScYhwGA.js';
|
|
3
4
|
import { WrapOptions } from './fetch.js';
|
|
4
|
-
export { createEmitter as createCoreEmitter } from './fetch.js';
|
|
5
5
|
import '@opentelemetry/sdk-trace-base';
|
|
6
6
|
|
|
7
7
|
interface HonoCompatibleContext {
|
package/dist/next.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { j as XrayRuntimeConfig, a as XrayEmitter } from './types-Z1nirh-F.cjs';
|
|
2
2
|
export { e as CaptureConfig, f as RedactionConfig, R as RequestLog, X as XrayConfig, d as XrayContext } from './types-Z1nirh-F.cjs';
|
|
3
|
+
export { c as createCoreEmitter } from './emitter-BqfrGIod.cjs';
|
|
3
4
|
import { WrapOptions } from './fetch.cjs';
|
|
4
|
-
export {
|
|
5
|
+
export { getXrayContext } from './fetch.cjs';
|
|
5
6
|
import '@opentelemetry/sdk-trace-base';
|
|
6
7
|
|
|
7
8
|
type NextRouteContext = {
|
package/dist/next.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { j as XrayRuntimeConfig, a as XrayEmitter } from './types-Z1nirh-F.js';
|
|
2
2
|
export { e as CaptureConfig, f as RedactionConfig, R as RequestLog, X as XrayConfig, d as XrayContext } from './types-Z1nirh-F.js';
|
|
3
|
+
export { c as createCoreEmitter } from './emitter-CScYhwGA.js';
|
|
3
4
|
import { WrapOptions } from './fetch.js';
|
|
4
|
-
export {
|
|
5
|
+
export { getXrayContext } from './fetch.js';
|
|
5
6
|
import '@opentelemetry/sdk-trace-base';
|
|
6
7
|
|
|
7
8
|
type NextRouteContext = {
|
package/dist/remix.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { j as XrayRuntimeConfig, a as XrayEmitter } from './types-Z1nirh-F.cjs';
|
|
2
2
|
export { e as CaptureConfig, f as RedactionConfig, R as RequestLog, X as XrayConfig, d as XrayContext } from './types-Z1nirh-F.cjs';
|
|
3
|
+
export { c as createCoreEmitter } from './emitter-BqfrGIod.cjs';
|
|
3
4
|
import { WrapOptions } from './fetch.cjs';
|
|
4
|
-
export {
|
|
5
|
+
export { getXrayContext } from './fetch.cjs';
|
|
5
6
|
import '@opentelemetry/sdk-trace-base';
|
|
6
7
|
|
|
7
8
|
type RequestHandler = (request: Request, loadContext?: unknown) => Response | Promise<Response>;
|
package/dist/remix.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { j as XrayRuntimeConfig, a as XrayEmitter } from './types-Z1nirh-F.js';
|
|
2
2
|
export { e as CaptureConfig, f as RedactionConfig, R as RequestLog, X as XrayConfig, d as XrayContext } from './types-Z1nirh-F.js';
|
|
3
|
+
export { c as createCoreEmitter } from './emitter-CScYhwGA.js';
|
|
3
4
|
import { WrapOptions } from './fetch.js';
|
|
4
|
-
export {
|
|
5
|
+
export { getXrayContext } from './fetch.js';
|
|
5
6
|
import '@opentelemetry/sdk-trace-base';
|
|
6
7
|
|
|
7
8
|
type RequestHandler = (request: Request, loadContext?: unknown) => Response | Promise<Response>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stainlessdev/xray-emitter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -51,6 +51,11 @@
|
|
|
51
51
|
"types": "./dist/remix.d.ts",
|
|
52
52
|
"import": "./dist/remix.js",
|
|
53
53
|
"require": "./dist/remix.cjs"
|
|
54
|
+
},
|
|
55
|
+
"./effect": {
|
|
56
|
+
"types": "./dist/effect.d.ts",
|
|
57
|
+
"import": "./dist/effect.js",
|
|
58
|
+
"require": "./dist/effect.cjs"
|
|
54
59
|
}
|
|
55
60
|
},
|
|
56
61
|
"files": [
|
|
@@ -65,9 +70,11 @@
|
|
|
65
70
|
"@opentelemetry/semantic-conventions": "^1.29.0"
|
|
66
71
|
},
|
|
67
72
|
"devDependencies": {
|
|
73
|
+
"@effect/platform": "^0.94.0",
|
|
68
74
|
"@types/express": "^5.0.0",
|
|
69
75
|
"@types/node": "^20.19.29",
|
|
70
76
|
"esbuild": "^0.25.0",
|
|
77
|
+
"effect": "^3.19.0",
|
|
71
78
|
"express": "^5.2.1",
|
|
72
79
|
"fastify": "^5.6.2",
|
|
73
80
|
"hono": "^4.11.4",
|
|
@@ -86,6 +93,9 @@
|
|
|
86
93
|
"format:check": "oxfmt --check .github examples src",
|
|
87
94
|
"clean": "rm -rf dist",
|
|
88
95
|
"release": "node scripts/release.js",
|
|
96
|
+
"test:bun": "find src -name '*.test.ts' ! -path '*/test/*' ! -path '*/express/*' ! -path '*/node/*' -print0 | xargs -0 -n1 bun test",
|
|
97
|
+
"example:effect": "pnpm --filter ./examples/effect start",
|
|
98
|
+
"example:effect-bun": "pnpm --filter ./examples/effect start:bun",
|
|
89
99
|
"example:edge": "pnpm --filter ./examples/edge start",
|
|
90
100
|
"example:express": "pnpm --filter ./examples/express start",
|
|
91
101
|
"example:fastify": "pnpm --filter ./examples/fastify start",
|