@distilled.cloud/core 1.0.0-rc.18 → 1.0.0-rc.19
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/lib/_bundle/base.js +2 -2
- package/lib/_bundle/base.js.map +1 -1
- package/lib/_bundle/graphql.js +2 -2
- package/lib/_bundle/graphql.js.map +1 -1
- package/lib/_bundle/grpc.js +2 -0
- package/lib/_bundle/grpc.js.map +1 -0
- package/lib/_bundle/rest.js +1 -1
- package/lib/_bundle/rest.js.map +1 -1
- package/lib/_bundle/xml.js +1 -1
- package/lib/_bundle/xml.js.map +1 -1
- package/lib/annotations.d.ts +2 -0
- package/lib/annotations.d.ts.map +1 -1
- package/lib/annotations.js +1 -1
- package/lib/annotations.js.map +1 -1
- package/lib/api.d.ts +37 -1
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -1
- package/lib/errors.d.ts +1 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -1
- package/lib/graphql.d.ts +12 -5
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.types.d.ts.map +1 -1
- package/lib/grpc-transport-cloudflare-http2.d.ts +7 -0
- package/lib/grpc-transport-cloudflare-http2.d.ts.map +1 -0
- package/lib/grpc-transport-cloudflare-http2.js +6 -0
- package/lib/grpc-transport-cloudflare-http2.js.map +1 -0
- package/lib/grpc-transport-cloudflare-sockets.d.ts +7 -0
- package/lib/grpc-transport-cloudflare-sockets.d.ts.map +1 -0
- package/lib/grpc-transport-cloudflare-sockets.js +5 -0
- package/lib/grpc-transport-cloudflare-sockets.js.map +1 -0
- package/lib/grpc-transport-node-http2.d.ts +19 -0
- package/lib/grpc-transport-node-http2.d.ts.map +1 -0
- package/lib/grpc-transport-node-http2.js +2 -0
- package/lib/grpc-transport-node-http2.js.map +1 -0
- package/lib/grpc-transport.d.ts +76 -0
- package/lib/grpc-transport.d.ts.map +1 -0
- package/lib/grpc-transport.js +1 -0
- package/lib/hpack.d.ts +34 -0
- package/lib/hpack.d.ts.map +1 -0
- package/lib/hpack.js +2 -0
- package/lib/hpack.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -0
- package/lib/pagination.d.ts +22 -2
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +1 -1
- package/lib/protobuf.d.ts +92 -0
- package/lib/protobuf.d.ts.map +1 -0
- package/lib/protobuf.js +1 -0
- package/lib/protocol-grpc.d.ts +86 -0
- package/lib/protocol-grpc.d.ts.map +1 -0
- package/lib/protocol-grpc.js +1 -0
- package/lib/protocol-http.d.ts +11 -6
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-rest.d.ts +12 -8
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/response-validation.d.ts +1 -1
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/sdk-error.d.ts +27 -0
- package/lib/sdk-error.d.ts.map +1 -0
- package/lib/sdk-error.js +1 -0
- package/lib/sensitive.d.ts +28 -0
- package/lib/sensitive.d.ts.map +1 -0
- package/lib/sensitive.js +2 -0
- package/lib/sensitive.js.map +1 -0
- package/lib/telemetry-debug.d.ts +2 -10
- package/lib/telemetry-debug.d.ts.map +1 -1
- package/lib/telemetry-debug.js +1 -1
- package/lib/telemetry-debug.js.map +1 -1
- package/lib/telemetry-stream.d.ts +3 -1
- package/lib/telemetry-stream.d.ts.map +1 -1
- package/lib/telemetry-stream.js +1 -1
- package/lib/telemetry-stream.js.map +1 -1
- package/lib/telemetry.d.ts +23 -4
- package/lib/telemetry.d.ts.map +1 -1
- package/lib/telemetry.js +2 -2
- package/lib/telemetry.js.map +1 -1
- package/lib/trait.d.ts +7 -0
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/annotations.ts +16 -0
- package/src/api.ts +199 -25
- package/src/errors.ts +4 -0
- package/src/graphql.ts +68 -45
- package/src/graphql.types.ts +5 -1
- package/src/grpc-transport-cloudflare-http2.ts +494 -0
- package/src/grpc-transport-cloudflare-sockets.ts +299 -0
- package/src/grpc-transport-node-http2.ts +234 -0
- package/src/grpc-transport.ts +118 -0
- package/src/hpack.ts +331 -0
- package/src/index.ts +3 -0
- package/src/pagination.ts +75 -3
- package/src/protobuf.ts +1332 -0
- package/src/protocol-grpc.ts +641 -0
- package/src/protocol-http.ts +30 -30
- package/src/protocol-rest.ts +49 -118
- package/src/response-validation.ts +4 -2
- package/src/sdk-error.ts +33 -0
- package/src/sensitive.ts +154 -0
- package/src/telemetry-debug.ts +65 -21
- package/src/telemetry-stream.ts +16 -7
- package/src/telemetry.ts +91 -27
- package/src/trait.ts +10 -0
- package/src/xml.ts +10 -1
- package/lib/debug.d.ts +0 -2
- package/lib/debug.d.ts.map +0 -1
- package/lib/debug.js +0 -1
- package/src/debug.ts +0 -11
package/src/telemetry-debug.ts
CHANGED
|
@@ -17,16 +17,24 @@
|
|
|
17
17
|
*
|
|
18
18
|
* and carries the caller's `code.*` attributes.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* Every SDK also writes the same `Effect.logDebug` lines for each call,
|
|
21
|
+
* with or without an exporter. They go to the program's logger, so they
|
|
22
|
+
* show when `References.MinimumLogLevel` admits `Debug`, and a logger that
|
|
23
|
+
* reads the current span (an OTel log exporter) links them to the trace:
|
|
22
24
|
*
|
|
23
25
|
* ```
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
+
* DEBUG distilled.operation=0ms: call S3.PutObject
|
|
27
|
+
* distilled.operation: S3.PutObject
|
|
28
|
+
* url.template: /{Bucket}/{Key+}
|
|
29
|
+
* DEBUG distilled.operation=23ms: -> PUT my-bucket.s3.us-east-1.amazonaws.com
|
|
30
|
+
* DEBUG distilled.operation=25ms: <- 200
|
|
31
|
+
* DEBUG distilled.operation=27ms: ok S3.PutObject
|
|
26
32
|
* ```
|
|
27
33
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
34
|
+
* The `call` line carries the input and the `ok` line the output, each
|
|
35
|
+
* with only its sensitive values `Redacted` (`./sensitive.ts`; input and
|
|
36
|
+
* output judged independently). The lines hold no serialized body and no
|
|
37
|
+
* full URL (a URL can carry a presigned signature or a sensitive label).
|
|
30
38
|
*/
|
|
31
39
|
import * as Cause from "effect/Cause";
|
|
32
40
|
import * as Effect from "effect/Effect";
|
|
@@ -34,8 +42,53 @@ import * as Exit from "effect/Exit";
|
|
|
34
42
|
import * as Layer from "effect/Layer";
|
|
35
43
|
import * as Stream from "effect/Stream";
|
|
36
44
|
import * as Tracer from "effect/Tracer";
|
|
45
|
+
import { redactParsed } from "./sensitive.ts";
|
|
37
46
|
import { Debug, type DebugHooks, OperationSpan, tagOf } from "./telemetry.ts";
|
|
38
47
|
|
|
48
|
+
/**
|
|
49
|
+
* The call's log lines. Every line inside (the HTTP ones included) carries
|
|
50
|
+
* the operation and its URL template, and the exit line its duration. The
|
|
51
|
+
* input and output show only their sensitive values `Redacted`; each is
|
|
52
|
+
* judged by its own schema.
|
|
53
|
+
*/
|
|
54
|
+
const call: DebugHooks["call"] = (info, input, schemas, effect) => {
|
|
55
|
+
const template = info.attributes["url.template"];
|
|
56
|
+
const start =
|
|
57
|
+
schemas === undefined
|
|
58
|
+
? Effect.logDebug(`call ${info.name}`)
|
|
59
|
+
: Effect.logDebug(`call ${info.name}`, redactParsed(schemas.input, input));
|
|
60
|
+
const logged = Effect.flatMap(start, () =>
|
|
61
|
+
Effect.onExit(effect, (exit) =>
|
|
62
|
+
Exit.isSuccess(exit)
|
|
63
|
+
? schemas === undefined
|
|
64
|
+
? Effect.logDebug(`ok ${info.name}`)
|
|
65
|
+
: Effect.logDebug(`ok ${info.name}`, redactParsed(schemas.output, exit.value))
|
|
66
|
+
: Cause.hasInterruptsOnly(exit.cause)
|
|
67
|
+
? Effect.logDebug(`interrupted ${info.name}`)
|
|
68
|
+
: Effect.logDebug(`failed ${info.name}: ${tagOf(Cause.squash(exit.cause))}`),
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
return Effect.annotateLogs(Effect.withLogSpan(logged, "distilled.operation"), {
|
|
72
|
+
"distilled.operation": info.name,
|
|
73
|
+
...(typeof template === "string" ? { "url.template": template } : {}),
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** The host of `url`, without the path or query (which can carry secrets). */
|
|
78
|
+
const hostOf = (url: string): string => {
|
|
79
|
+
try {
|
|
80
|
+
return new URL(url).host;
|
|
81
|
+
} catch {
|
|
82
|
+
return "";
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** One HTTP exchange: method and host out, status back. */
|
|
87
|
+
const http: DebugHooks["http"] = (request, sent) =>
|
|
88
|
+
Effect.flatMap(Effect.logDebug(`-> ${request.method} ${hostOf(request.url)}`), () =>
|
|
89
|
+
Effect.tap(sent, (response) => Effect.logDebug(`<- ${response.status}`)),
|
|
90
|
+
);
|
|
91
|
+
|
|
39
92
|
const phase: DebugHooks["phase"] = (name, effect, attributes) =>
|
|
40
93
|
Effect.withSpan(effect, name, { level: "Debug", attributes, captureStackTrace: false });
|
|
41
94
|
|
|
@@ -113,23 +166,14 @@ const callSite: DebugHooks["callSite"] = (site) => {
|
|
|
113
166
|
};
|
|
114
167
|
};
|
|
115
168
|
|
|
116
|
-
export
|
|
117
|
-
/**
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const layerWith = (options: Options = {}): Layer.Layer<never> =>
|
|
122
|
-
Layer.succeed(Debug, {
|
|
169
|
+
export const TelemetryDebug = {
|
|
170
|
+
/** Turns on debug spans and debug log lines for every distilled call it is provided to. */
|
|
171
|
+
layer: /*@__PURE__*/ Layer.succeed(Debug, {
|
|
123
172
|
phase,
|
|
124
173
|
attempt,
|
|
125
174
|
readStream,
|
|
126
175
|
callSite,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
export const TelemetryDebug = {
|
|
131
|
-
/** Turns on debug spans for every distilled call it is provided to. */
|
|
132
|
-
layer: /*@__PURE__*/ layerWith(),
|
|
133
|
-
/** Debug spans, with options (`logRequests`). */
|
|
134
|
-
layerWith,
|
|
176
|
+
call,
|
|
177
|
+
http,
|
|
178
|
+
}) as Layer.Layer<never>,
|
|
135
179
|
} as const;
|
package/src/telemetry-stream.ts
CHANGED
|
@@ -19,7 +19,10 @@
|
|
|
19
19
|
* the span, as in those instrumentations: the conventions ask clients not
|
|
20
20
|
* to end a span later, in clean-up. `firstChunk` names the attribute that
|
|
21
21
|
* records the seconds from the span's start to the first item
|
|
22
|
-
* (`gen_ai.response.time_to_first_chunk`).
|
|
22
|
+
* (`gen_ai.response.time_to_first_chunk`). `events` reads attributes from
|
|
23
|
+
* the items as they pass, by event member, with the same rules as the
|
|
24
|
+
* output's: Bedrock `ConverseStream`'s `metadata` carries the token usage
|
|
25
|
+
* and its `messageStop` the finish reason.
|
|
23
26
|
*/
|
|
24
27
|
import * as Cause from "effect/Cause";
|
|
25
28
|
import * as Clock from "effect/Clock";
|
|
@@ -27,18 +30,20 @@ import * as Effect from "effect/Effect";
|
|
|
27
30
|
import * as Exit from "effect/Exit";
|
|
28
31
|
import * as References from "effect/References";
|
|
29
32
|
import * as Stream from "effect/Stream";
|
|
30
|
-
import { type SpanHold, tagOf } from "./telemetry.ts";
|
|
33
|
+
import { type AttributeRule, flatten, readRules, type SpanHold, tagOf } from "./telemetry.ts";
|
|
31
34
|
|
|
32
35
|
export interface StreamRule {
|
|
33
36
|
/** The output member holding the stream (the generated property name). */
|
|
34
37
|
readonly member: string;
|
|
35
38
|
/** Attribute for the seconds from the span's start to the first item. */
|
|
36
39
|
readonly firstChunk?: string;
|
|
40
|
+
/** Attributes read from each item, by event member (the generated property name). */
|
|
41
|
+
readonly events?: Readonly<Record<string, ReadonlyArray<AttributeRule>>>;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
|
-
export const holdForStream =
|
|
40
|
-
(rule
|
|
41
|
-
(fiber, name, options, debug, inSpan) => {
|
|
44
|
+
export const holdForStream = (rule: StreamRule): SpanHold => {
|
|
45
|
+
const events = flatten(rule.events);
|
|
46
|
+
return (fiber, name, options, debug, inSpan) => {
|
|
42
47
|
const clock = fiber.getRef(Clock.Clock);
|
|
43
48
|
const timing = fiber.getRef(References.TracerTimingEnabled);
|
|
44
49
|
const now = () => (timing ? clock.currentTimeNanosUnsafe() : 0n);
|
|
@@ -57,13 +62,16 @@ export const holdForStream =
|
|
|
57
62
|
const read = Stream.suspend(() => {
|
|
58
63
|
let items = debug === undefined ? stream : debug.readStream(stream, span, rule.member);
|
|
59
64
|
const attribute = rule.firstChunk;
|
|
60
|
-
if (attribute !== undefined) {
|
|
65
|
+
if (attribute !== undefined || events.length > 0) {
|
|
61
66
|
let first = true;
|
|
62
67
|
items = Stream.map(items, (item) => {
|
|
63
68
|
if (first) {
|
|
64
69
|
first = false;
|
|
65
|
-
|
|
70
|
+
if (attribute !== undefined) {
|
|
71
|
+
span.attribute(attribute, Number(now() - span.status.startTime) / 1e9);
|
|
72
|
+
}
|
|
66
73
|
}
|
|
74
|
+
readRules(events, item, (key, value) => span.attribute(key, value));
|
|
67
75
|
return item;
|
|
68
76
|
});
|
|
69
77
|
}
|
|
@@ -89,3 +97,4 @@ export const holdForStream =
|
|
|
89
97
|
}),
|
|
90
98
|
);
|
|
91
99
|
};
|
|
100
|
+
};
|
package/src/telemetry.ts
CHANGED
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
* debug (opt in): spans for distilled's internals too, INTERNAL spans
|
|
15
15
|
* at trace level `Debug`: first-call setup, serialize, sign,
|
|
16
16
|
* deserialize, one `Attempt` per try, backoff sleeps, and the
|
|
17
|
-
* caller's `code.*` attributes
|
|
17
|
+
* caller's `code.*` attributes; and `Effect.logDebug` lines
|
|
18
|
+
* for each call and HTTP exchange, the same for every SDK,
|
|
19
|
+
* with or without an exporter. Its code lives in
|
|
18
20
|
* `./telemetry-debug.ts`, so only programs that import it
|
|
19
21
|
* bundle it:
|
|
20
22
|
*
|
|
@@ -61,14 +63,36 @@ export interface DebugHooks {
|
|
|
61
63
|
parent: Tracer.Span,
|
|
62
64
|
member: string,
|
|
63
65
|
) => Stream.Stream<A, E, R>;
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
+
/**
|
|
67
|
+
* The operation call with its debug log lines: `Effect.logDebug` at the
|
|
68
|
+
* start (with the input) and on exit (with the output), every line inside
|
|
69
|
+
* annotated with the operation. With `schemas`, input and output are
|
|
70
|
+
* logged with their sensitive values `Redacted` (`./sensitive.ts`);
|
|
71
|
+
* without, they are left out.
|
|
72
|
+
*/
|
|
73
|
+
readonly call: <A, E, R>(
|
|
74
|
+
info: OperationInfo,
|
|
75
|
+
input: unknown,
|
|
76
|
+
schemas: OperationSchemas | undefined,
|
|
77
|
+
effect: Effect.Effect<A, E, R>,
|
|
78
|
+
) => Effect.Effect<A, E, R>;
|
|
79
|
+
/** One HTTP exchange (`sent`) with its debug log lines. */
|
|
80
|
+
readonly http: (
|
|
81
|
+
request: HttpClientRequest.HttpClientRequest,
|
|
82
|
+
sent: Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError>,
|
|
83
|
+
) => Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError>;
|
|
66
84
|
/** OTel `code.*` attributes for the caller's line. */
|
|
67
85
|
readonly callSite: (
|
|
68
86
|
callSite: (() => string | undefined) | undefined,
|
|
69
87
|
) => Record<string, unknown> | undefined;
|
|
70
88
|
}
|
|
71
89
|
|
|
90
|
+
/** An operation's input and output schemas, for the debug log lines. */
|
|
91
|
+
export interface OperationSchemas {
|
|
92
|
+
readonly input: AST.AST;
|
|
93
|
+
readonly output: AST.AST;
|
|
94
|
+
}
|
|
95
|
+
|
|
72
96
|
export const Debug = /*@__PURE__*/ Context.Reference<DebugHooks | undefined>(
|
|
73
97
|
"@distilled.cloud/core/Telemetry/Debug",
|
|
74
98
|
{ defaultValue: () => undefined },
|
|
@@ -92,6 +116,21 @@ export const OperationSpan = /*@__PURE__*/ Context.Reference<Call | undefined>(
|
|
|
92
116
|
{ defaultValue: () => undefined },
|
|
93
117
|
);
|
|
94
118
|
|
|
119
|
+
/**
|
|
120
|
+
* The untraced call's propagation (no exporter, so no operation span): the
|
|
121
|
+
* caller's parent span and the service's header format. Requests carry the
|
|
122
|
+
* parent's own trace context, as an OTel no-op tracer forwards it.
|
|
123
|
+
*/
|
|
124
|
+
interface Forward {
|
|
125
|
+
readonly span: Tracer.AnySpan;
|
|
126
|
+
readonly propagate: NonNullable<ServiceTelemetry["propagate"]>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const Forward = /*@__PURE__*/ Context.Reference<Forward | undefined>(
|
|
130
|
+
"@distilled.cloud/core/Telemetry/Forward",
|
|
131
|
+
{ defaultValue: () => undefined },
|
|
132
|
+
);
|
|
133
|
+
|
|
95
134
|
//#region traits
|
|
96
135
|
|
|
97
136
|
/**
|
|
@@ -365,7 +404,7 @@ export const operationInfo = (
|
|
|
365
404
|
};
|
|
366
405
|
};
|
|
367
406
|
|
|
368
|
-
const flatten = (
|
|
407
|
+
export const flatten = (
|
|
369
408
|
rules: Readonly<Record<string, ReadonlyArray<AttributeRule>>> | undefined,
|
|
370
409
|
): Array<readonly [string, AttributeRule]> => {
|
|
371
410
|
const out: Array<readonly [string, AttributeRule]> = [];
|
|
@@ -376,7 +415,7 @@ const flatten = (
|
|
|
376
415
|
};
|
|
377
416
|
|
|
378
417
|
/** Attributes the rules read from a value (the input or the output). Redacted values are skipped. */
|
|
379
|
-
const readRules = (
|
|
418
|
+
export const readRules = (
|
|
380
419
|
rules: OperationInfo["input"],
|
|
381
420
|
value: unknown,
|
|
382
421
|
set: (key: string, value: unknown) => void,
|
|
@@ -484,31 +523,51 @@ export const annotateResponse = (
|
|
|
484
523
|
}
|
|
485
524
|
};
|
|
486
525
|
|
|
526
|
+
/** The trace header for `span` in the service's format. */
|
|
527
|
+
const traceHeader = (
|
|
528
|
+
request: HttpClientRequest.HttpClientRequest,
|
|
529
|
+
propagate: NonNullable<ServiceTelemetry["propagate"]>,
|
|
530
|
+
span: Tracer.AnySpan,
|
|
531
|
+
): HttpClientRequest.HttpClientRequest =>
|
|
532
|
+
propagate === "w3c"
|
|
533
|
+
? HttpClientRequest.setHeader(
|
|
534
|
+
request,
|
|
535
|
+
"traceparent",
|
|
536
|
+
`00-${span.traceId}-${span.spanId}-${span.sampled ? "01" : "00"}`,
|
|
537
|
+
)
|
|
538
|
+
: HttpClientRequest.setHeader(request, ...propagate(span));
|
|
539
|
+
|
|
487
540
|
/**
|
|
488
541
|
* `client.execute(request)` for the traced call on this fiber: the
|
|
489
542
|
* request facts before it is sent, the response facts when it returns.
|
|
490
|
-
* Untraced calls pay
|
|
543
|
+
* Untraced calls pay two context reads, and forward the caller's trace
|
|
544
|
+
* header if there is a parent span.
|
|
491
545
|
*/
|
|
492
546
|
export const execute = (
|
|
493
547
|
context: Context.Context<any>,
|
|
494
548
|
client: HttpClient.HttpClient,
|
|
495
549
|
request: HttpClientRequest.HttpClientRequest,
|
|
550
|
+
): Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError> => {
|
|
551
|
+
const debug = Context.get(context, Debug);
|
|
552
|
+
const sent = tracedExecute(context, client, request);
|
|
553
|
+
return debug === undefined ? sent : debug.http(request, sent);
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
const tracedExecute = (
|
|
557
|
+
context: Context.Context<any>,
|
|
558
|
+
client: HttpClient.HttpClient,
|
|
559
|
+
request: HttpClientRequest.HttpClientRequest,
|
|
496
560
|
): Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError> => {
|
|
497
561
|
const call = Context.get(context, OperationSpan);
|
|
498
|
-
if (call === undefined)
|
|
562
|
+
if (call === undefined) {
|
|
563
|
+
const forward = Context.get(context, Forward);
|
|
564
|
+
return client.execute(
|
|
565
|
+
forward === undefined ? request : traceHeader(request, forward.propagate, forward.span),
|
|
566
|
+
);
|
|
567
|
+
}
|
|
499
568
|
annotateRequest(context, request.method, request.url);
|
|
500
569
|
const propagate = call.info.propagate;
|
|
501
|
-
if (propagate !== undefined)
|
|
502
|
-
const span = call.attempt ?? call.span;
|
|
503
|
-
request =
|
|
504
|
-
propagate === "w3c"
|
|
505
|
-
? HttpClientRequest.setHeader(
|
|
506
|
-
request,
|
|
507
|
-
"traceparent",
|
|
508
|
-
`00-${span.traceId}-${span.spanId}-${span.sampled ? "01" : "00"}`,
|
|
509
|
-
)
|
|
510
|
-
: HttpClientRequest.setHeader(request, ...propagate(span));
|
|
511
|
-
}
|
|
570
|
+
if (propagate !== undefined) request = traceHeader(request, propagate, call.attempt ?? call.span);
|
|
512
571
|
return Effect.map(client.execute(request), (response) => {
|
|
513
572
|
annotateResponse(
|
|
514
573
|
context,
|
|
@@ -664,6 +723,8 @@ const withFailureFrame = <A, E, R>(
|
|
|
664
723
|
*
|
|
665
724
|
* no exporter: no span. Effect's HTTP span is switched off too (nobody
|
|
666
725
|
* would see it); the failure frame still names the call.
|
|
726
|
+
* Requests still carry the caller's parent span, if any,
|
|
727
|
+
* in the service's trace header (`traceparent`, X-Ray).
|
|
667
728
|
* operation: one CLIENT span. Effect's HTTP span is switched off and
|
|
668
729
|
* protocols copy its facts (status, host, request id) onto
|
|
669
730
|
* this span, so one span per call.
|
|
@@ -683,9 +744,11 @@ export const operationSpan = <A, E, R>(
|
|
|
683
744
|
callSite: (() => string | undefined) | undefined,
|
|
684
745
|
input: unknown,
|
|
685
746
|
run: (input: unknown) => Effect.Effect<A, E, R>,
|
|
747
|
+
schemas?: OperationSchemas,
|
|
686
748
|
): Effect.Effect<A, E, R> => {
|
|
687
749
|
const measure = fiber.getRef(Metrics);
|
|
688
|
-
|
|
750
|
+
let traced = traceCall(fiber, debug, info, callSite, input, run);
|
|
751
|
+
if (debug !== undefined) traced = debug.call(info, input, schemas, traced);
|
|
689
752
|
return measure === undefined ? traced : measure(info, traced);
|
|
690
753
|
};
|
|
691
754
|
|
|
@@ -698,14 +761,15 @@ const traceCall = <A, E, R>(
|
|
|
698
761
|
run: (input: unknown) => Effect.Effect<A, E, R>,
|
|
699
762
|
): Effect.Effect<A, E, R> => {
|
|
700
763
|
if (!exporting(fiber)) {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
764
|
+
let body = run(input);
|
|
765
|
+
if (debug === undefined)
|
|
766
|
+
body = Effect.provideService(body, HttpClient.TracerDisabledWhen, always);
|
|
767
|
+
const propagate = info.propagate;
|
|
768
|
+
if (propagate !== undefined) {
|
|
769
|
+
const span = Context.getOrUndefined(fiber.context, Tracer.ParentSpan);
|
|
770
|
+
if (span !== undefined) body = Effect.provideService(body, Forward, { span, propagate });
|
|
771
|
+
}
|
|
772
|
+
return withFailureFrame(body, info.name, callSite);
|
|
709
773
|
}
|
|
710
774
|
const attributes: Record<string, unknown> =
|
|
711
775
|
debug !== undefined
|
package/src/trait.ts
CHANGED
|
@@ -125,6 +125,16 @@ export const Body = (name?: string) => makeAnnotation(bodySymbol, name ?? true);
|
|
|
125
125
|
export const querySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/query");
|
|
126
126
|
export const Query = (name?: string) => makeAnnotation(querySymbol, name ?? true);
|
|
127
127
|
|
|
128
|
+
export const commaDelimitedSymbol = /*@__PURE__*/ Symbol.for(
|
|
129
|
+
"@distilled.cloud/core/http/comma-delimited",
|
|
130
|
+
);
|
|
131
|
+
/**
|
|
132
|
+
* Sends a list-valued `Query` member as ONE comma-separated parameter
|
|
133
|
+
* (`?state=running,paused`) instead of one parameter per item -- OpenAPI's
|
|
134
|
+
* `style: form, explode: false`. Takes the trait value the codegen inlines.
|
|
135
|
+
*/
|
|
136
|
+
export const CommaDelimited = (_trait?: unknown) => makeAnnotation(commaDelimitedSymbol, true);
|
|
137
|
+
|
|
128
138
|
export const deepQuerySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/deep-query");
|
|
129
139
|
/**
|
|
130
140
|
* Binds a struct-valued input member to a family of DOTTED query parameters:
|
package/src/xml.ts
CHANGED
|
@@ -309,7 +309,16 @@ export const parseXml = (
|
|
|
309
309
|
return Effect.succeed(parseXmlSync(xml, options));
|
|
310
310
|
} catch (error) {
|
|
311
311
|
if (error instanceof XmlParseError) return Effect.fail(error);
|
|
312
|
-
|
|
312
|
+
// Anything else the parser throws (a stack overflow on deep nesting,
|
|
313
|
+
// ...) still means this document could not be parsed.
|
|
314
|
+
return Effect.fail(
|
|
315
|
+
new XmlParseError({
|
|
316
|
+
message: `XML could not be parsed: ${error instanceof Error ? error.message : String(error)}`,
|
|
317
|
+
offset: 0,
|
|
318
|
+
line: 1,
|
|
319
|
+
column: 1,
|
|
320
|
+
}),
|
|
321
|
+
);
|
|
313
322
|
}
|
|
314
323
|
});
|
|
315
324
|
|
package/lib/debug.d.ts
DELETED
package/lib/debug.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,SAAS,QAAO,OAAkE,CAAC"}
|
package/lib/debug.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { debug$debugHttp as debugHttp } from "./_bundle/rest.js";
|
package/src/debug.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Whether the call running on this fiber logs its requests and responses to
|
|
3
|
-
* stderr (`[distilled] -> GET /zones/{zone_id}`, `[distilled] <- 200 ...`):
|
|
4
|
-
* `TelemetryDebug.layerWith({ logRequests: true })` from
|
|
5
|
-
* `./telemetry-debug.ts`. Protocols check it on every request; outside a
|
|
6
|
-
* fiber, or without that layer, it is false.
|
|
7
|
-
*/
|
|
8
|
-
import * as Fiber from "effect/Fiber";
|
|
9
|
-
import { Debug } from "./telemetry.ts";
|
|
10
|
-
|
|
11
|
-
export const debugHttp = (): boolean => Fiber.getCurrent()?.getRef(Debug)?.logRequests === true;
|