@mark1russell7/service 0.8.0 → 0.8.2

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.
@@ -1,5 +1,5 @@
1
1
  import { n as Clock } from "./clock-DpVgpY4h.js";
2
- import { $ as UncaughtOrigin, S as Gate, X as ProcessPort, _ as CooperativeFloor, c as Logger, h as Check, m as Recorder } from "./logger-BY1RFLzq.js";
2
+ import { Q as ProcessPort, _ as Check, c as Logger, g as Recorder, tt as UncaughtOrigin, w as Gate, y as CooperativeFloor } from "./logger-BN2BfPgU.js";
3
3
  import { Extent } from "@mark1russell7/quantity";
4
4
  //#region src/latch.d.ts
5
5
  /**
@@ -384,4 +384,4 @@ interface Lifecycle {
384
384
  }
385
385
  //#endregion
386
386
  export { DurationHistogram as A, HealthVerdict as C, CheckFn as D, StartOptions as E, Outcome as F, Result as I, Trace as L, Episode as M, HealthMetrics as N, CheckMetrics as O, redact as P, Health as S, ProbeKind as T, RequestFn as _, PhaseContext as a, RequestWork as b, STAGES as c, TransportImpl as d, UncaughtOptions as f, RequestEvent as g, RequestEnd as h, LifecycleState as i, EPISODES_KEPT as j, DURATION_FRACTIONS as k, ShutdownOptions as l, stageRank as m, HealthServer as n, PhaseWork as o, cooperativeAbortAt as p, Lifecycle as r, RunOptions as s, DependencyHandle as t, Stage as u, RequestOptions as v, ProbeAnswer as w, CheckVerdict as x, RequestStream as y };
387
- //# sourceMappingURL=lifecycle-C8ffyrQ9.d.ts.map
387
+ //# sourceMappingURL=lifecycle-Br0jAjTk.d.ts.map
@@ -457,6 +457,16 @@ type ConsoleTarget = Readonly<Record<LogLevel, (...data: unknown[]) => void>>;
457
457
  * - `json`: one line of JSON for each entry, with the level, the message and each field.
458
458
  */
459
459
  type LogFormat = "text" | "json";
460
+ /** These are the ids of the trace and of the span of a log entry, with the names of the OpenTelemetry log data model. */
461
+ interface TraceIds {
462
+ readonly trace_id: string;
463
+ readonly span_id: string;
464
+ }
465
+ /**
466
+ * A source of trace ids gives the ids of the active span, or nothing when no span is active. The
467
+ * entry `@mark1russell7/service/otel` has one on the API of OpenTelemetry: `traceIds`.
468
+ */
469
+ type TraceIdsSource = () => TraceIds | undefined;
460
470
  /** These options make the console logger. */
461
471
  interface ConsoleLoggerOptions {
462
472
  /** This level is the least severe level that the logger writes. The default is `info`. */
@@ -465,6 +475,12 @@ interface ConsoleLoggerOptions {
465
475
  readonly console?: ConsoleTarget | undefined;
466
476
  /** This format tells how the logger writes each entry. The default is `text`. */
467
477
  readonly format?: LogFormat | undefined;
478
+ /**
479
+ * This source gives the trace ids of each entry. The logger adds them to the fields, but a field
480
+ * of the entry with the same name stays. With no source, or when the source gives nothing, the
481
+ * entry does not change.
482
+ */
483
+ readonly traceIds?: TraceIdsSource | undefined;
468
484
  }
469
485
  /**
470
486
  * This function makes the console logger. It writes each entry at its level or more severe to the
@@ -483,5 +499,5 @@ declare const consoleLogger: (options?: ConsoleLoggerOptions) => Logger;
483
499
  */
484
500
  declare const logEvents: (logger: Logger, description?: ServiceDescription) => Recorder;
485
501
  //#endregion
486
- export { UncaughtOrigin as $, FailsBy as A, RoutePattern as B, MessageTrigger as C, ServiceDescription as D, RepeatSignal as E, asWindow as F, ExitTrigger as G, EXIT_SIGNALS as H, failSpan as I, PROCESS_TRIGGERS as J, HostStream as K, heartbeatDetection as L, Span as M, Timing as N, Step as O, asDebounce as P, UNCAUGHT_ORIGINS as Q, recoverSpan as R, Gate as S, ProgressMarks as T, EmbeddedProcess as U, RouteRequest as V, ExitSignal as W, ProcessPort as X, ProcessHost as Y, ProcessTrigger as Z, CooperativeFloor as _, LogFields as a, nodeProcess as at, ExitCodes as b, Logger as c, Operation as ct, logEvents as d, embeddedProcess as et, LifecycleEvent as f, Controller as g, Check as h, LogEntry as i, matchesMessage as it, Poll as j, Transport as k, atLeast as l, mayReissue as lt, Recorder as m, ConsoleTarget as n, isExitSignal as nt, LogFormat as o, processPortOf as ot, MachineName as p, MessageShape as q, LOG_LEVELS as r, isMessageShape as rt, LogLevel as s, Idempotency as st, ConsoleLoggerOptions as t, isExitCode as tt, consoleLogger as u, Coupling as v, Phase as w, FORMAT as x, Dependency as y, OperationOf as z };
487
- //# sourceMappingURL=logger-BY1RFLzq.d.ts.map
502
+ export { ProcessTrigger as $, Step as A, recoverSpan as B, FORMAT as C, ProgressMarks as D, Phase as E, Timing as F, EmbeddedProcess as G, RoutePattern as H, asDebounce as I, HostStream as J, ExitSignal as K, asWindow as L, FailsBy as M, Poll as N, RepeatSignal as O, Span as P, ProcessPort as Q, failSpan as R, ExitCodes as S, MessageTrigger as T, RouteRequest as U, OperationOf as V, EXIT_SIGNALS as W, PROCESS_TRIGGERS as X, MessageShape as Y, ProcessHost as Z, Check as _, LogFields as a, isMessageShape as at, Coupling as b, Logger as c, processPortOf as ct, atLeast as d, mayReissue as dt, UNCAUGHT_ORIGINS as et, consoleLogger as f, Recorder as g, MachineName as h, LogEntry as i, isExitSignal as it, Transport as j, ServiceDescription as k, TraceIds as l, Idempotency as lt, LifecycleEvent as m, ConsoleTarget as n, embeddedProcess as nt, LogFormat as o, matchesMessage as ot, logEvents as p, ExitTrigger as q, LOG_LEVELS as r, isExitCode as rt, LogLevel as s, nodeProcess as st, ConsoleLoggerOptions as t, UncaughtOrigin as tt, TraceIdsSource as u, Operation as ut, Controller as v, Gate as w, Dependency as x, CooperativeFloor as y, heartbeatDetection as z };
503
+ //# sourceMappingURL=logger-BN2BfPgU.d.ts.map
@@ -1,6 +1,6 @@
1
- import { ct as Operation, j as Poll } from "./logger-BY1RFLzq.js";
2
- import { C as MANIFESTATIONS, D as firstDetector, E as Situation, O as unwatched, S as Detector, T as Meeting, _ as Sent, a as ClientKnobs, c as ClientSpec, d as Factory, g as SendOptions, h as STARTING_POLL, i as ClientJoin, l as ClientStep, n as CheckOptions, o as ClientOptions, r as Client, s as ClientSocket, t as Attempt, u as DialFn, w as Manifestation } from "./core-Cuh3oSfr.js";
3
- import { t as Judge } from "./dial-ZJNa6s9i.js";
1
+ import { N as Poll, ut as Operation } from "./logger-BN2BfPgU.js";
2
+ import { C as MANIFESTATIONS, D as firstDetector, E as Situation, O as unwatched, S as Detector, T as Meeting, _ as Sent, a as ClientKnobs, c as ClientSpec, d as Factory, g as SendOptions, h as STARTING_POLL, i as ClientJoin, l as ClientStep, n as CheckOptions, o as ClientOptions, r as Client, s as ClientSocket, t as Attempt, u as DialFn, w as Manifestation } from "./core-Dt0HEVMq.js";
3
+ import { t as Judge } from "./dial-CSQOl-yj.js";
4
4
  import { Extent, Quantity } from "@mark1russell7/quantity";
5
5
  import { Machine } from "@mark1russell7/algebra";
6
6
  //#region src/mongodb/connection.d.ts
@@ -0,0 +1,13 @@
1
+ import { l as TraceIds, u as TraceIdsSource } from "./logger-BN2BfPgU.js";
2
+ import { n as IncomingHeaders, t as CallContext } from "./call-context-gR8FhbF_.js";
3
+ //#region src/otel.d.ts
4
+ /** This function gives the trace id and the span id of the active span, or nothing when no valid span is active. */
5
+ export declare const traceIds: () => TraceIds | undefined;
6
+ /**
7
+ * This call context uses the propagator that the program registers. An incoming call starts from the root
8
+ * context, thus it gets no value of the context that runs the server. A call that is not trusted loses its baggage.
9
+ */
10
+ export declare const callContext: CallContext;
11
+ //#endregion
12
+ export type { CallContext, IncomingHeaders, TraceIds, TraceIdsSource };
13
+ //# sourceMappingURL=otel.d.ts.map
package/build/otel.js ADDED
@@ -0,0 +1,34 @@
1
+ import { ROOT_CONTEXT, context, isSpanContextValid, propagation, trace } from "@opentelemetry/api";
2
+ //#region src/otel.ts
3
+ /** This function gives the trace id and the span id of the active span, or nothing when no valid span is active. */
4
+ const traceIds = () => {
5
+ const span = trace.getActiveSpan()?.spanContext();
6
+ return span !== void 0 && isSpanContextValid(span) ? {
7
+ trace_id: span.traceId,
8
+ span_id: span.spanId
9
+ } : void 0;
10
+ };
11
+ /** This getter reads the headers of `node:http`: the names are in lower case, and a value can be a list. */
12
+ const incoming = {
13
+ keys: (headers) => Object.keys(headers),
14
+ get: (headers, key) => headers[key.toLowerCase()]
15
+ };
16
+ /**
17
+ * This call context uses the propagator that the program registers. An incoming call starts from the root
18
+ * context, thus it gets no value of the context that runs the server. A call that is not trusted loses its baggage.
19
+ */
20
+ const callContext = {
21
+ run: (headers, trusted, fn) => {
22
+ const kept = trusted ? headers : Object.fromEntries(Object.entries(headers).filter(([name]) => name !== "baggage"));
23
+ return context.with(propagation.extract(ROOT_CONTEXT, kept, incoming), fn);
24
+ },
25
+ headers: () => {
26
+ const headers = {};
27
+ propagation.inject(context.active(), headers);
28
+ return headers;
29
+ }
30
+ };
31
+ //#endregion
32
+ export { callContext, traceIds };
33
+
34
+ //# sourceMappingURL=otel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otel.js","names":[],"sources":["../src/otel.ts"],"sourcesContent":["// @mark1russell7/service/otel: the trace ids of the active span and the context of a call, from the API of OpenTelemetry.\n// This entry is the only entry that loads @opentelemetry/api, an optional peer. A service gives\n// `traceIds` to `consoleLogger`, and then each log entry has the `trace_id` and the `span_id` of\n// its span. The API does nothing until a program registers an SDK (for example\n// `startNodeTelemetry()` of @mark1russell7/otel-ts/node). Before that, `traceIds` gives nothing,\n// and each entry stays as it was.\n//\n// `callContext` takes the context across the network: the HTTP transport (option `callContext`) runs each\n// handler in the context of its request, and the HTTP and gRPC clients send the headers of the active context.\n// The propagator that the program registers writes and reads the headers.\n\nimport { context, isSpanContextValid, propagation, ROOT_CONTEXT, trace, type TextMapGetter } from \"@opentelemetry/api\";\nimport type { CallContext, IncomingHeaders } from \"./call-context.ts\";\nimport type { TraceIds } from \"./logger.ts\";\n\nexport type { CallContext, IncomingHeaders } from \"./call-context.ts\";\nexport type { TraceIds, TraceIdsSource } from \"./logger.ts\";\n\n/** This function gives the trace id and the span id of the active span, or nothing when no valid span is active. */\nexport const traceIds = (): TraceIds | undefined => {\n const span = trace.getActiveSpan()?.spanContext();\n return span !== undefined && isSpanContextValid(span) ? { trace_id: span.traceId, span_id: span.spanId } : undefined;\n};\n\n/** This getter reads the headers of `node:http`: the names are in lower case, and a value can be a list. */\nconst incoming: TextMapGetter<IncomingHeaders> = {\n keys: (headers) => Object.keys(headers),\n get: (headers, key) => headers[key.toLowerCase()] as string | string[] | undefined,\n};\n\n/**\n * This call context uses the propagator that the program registers. An incoming call starts from the root\n * context, thus it gets no value of the context that runs the server. A call that is not trusted loses its baggage.\n */\nexport const callContext: CallContext = {\n run: (headers, trusted, fn) => {\n const kept = trusted ? headers : Object.fromEntries(Object.entries(headers).filter(([name]) => name !== \"baggage\"));\n return context.with(propagation.extract(ROOT_CONTEXT, kept, incoming), fn);\n },\n headers: () => {\n const headers: Record<string, string> = {};\n propagation.inject(context.active(), headers);\n return headers;\n },\n};\n"],"mappings":";;;AAmBA,MAAa,iBAAuC;CAClD,MAAM,OAAO,MAAM,cAAc,CAAC,EAAE,YAAY;CAChD,OAAO,SAAS,KAAA,KAAa,mBAAmB,IAAI,IAAI;EAAE,UAAU,KAAK;EAAS,SAAS,KAAK;CAAO,IAAI,KAAA;AAC7G;;AAGA,MAAM,WAA2C;CAC/C,OAAO,YAAY,OAAO,KAAK,OAAO;CACtC,MAAM,SAAS,QAAQ,QAAQ,IAAI,YAAY;AACjD;;;;;AAMA,MAAa,cAA2B;CACtC,MAAM,SAAS,SAAS,OAAO;EAC7B,MAAM,OAAO,UAAU,UAAU,OAAO,YAAY,OAAO,QAAQ,OAAO,CAAC,CAAC,QAAQ,CAAC,UAAU,SAAS,SAAS,CAAC;EAClH,OAAO,QAAQ,KAAK,YAAY,QAAQ,cAAc,MAAM,QAAQ,GAAG,EAAE;CAC3E;CACA,eAAe;EACb,MAAM,UAAkC,CAAC;EACzC,YAAY,OAAO,QAAQ,OAAO,GAAG,OAAO;EAC5C,OAAO;CACT;AACF"}
package/build/pg.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ct as Operation, j as Poll } from "./logger-BY1RFLzq.js";
2
- import { C as MANIFESTATIONS, D as firstDetector, E as Situation, O as unwatched, S as Detector, T as Meeting, _ as Sent, a as ClientKnobs, c as ClientSpec, d as Factory, g as SendOptions, h as STARTING_POLL, i as ClientJoin, l as ClientStep, n as CheckOptions, o as ClientOptions, r as Client, s as ClientSocket, t as Attempt, u as DialFn, w as Manifestation } from "./core-Cuh3oSfr.js";
1
+ import { N as Poll, ut as Operation } from "./logger-BN2BfPgU.js";
2
+ import { C as MANIFESTATIONS, D as firstDetector, E as Situation, O as unwatched, S as Detector, T as Meeting, _ as Sent, a as ClientKnobs, c as ClientSpec, d as Factory, g as SendOptions, h as STARTING_POLL, i as ClientJoin, l as ClientStep, n as CheckOptions, o as ClientOptions, r as Client, s as ClientSocket, t as Attempt, u as DialFn, w as Manifestation } from "./core-Dt0HEVMq.js";
3
3
  import { Extent, Quantity } from "@mark1russell7/quantity";
4
4
  import { Machine } from "@mark1russell7/algebra";
5
5
  //#region src/pg/connection.d.ts
@@ -1,5 +1,5 @@
1
1
  import { n as Clock } from "./clock-DpVgpY4h.js";
2
- import { c as Logger } from "./logger-BY1RFLzq.js";
2
+ import { c as Logger } from "./logger-BN2BfPgU.js";
3
3
  //#region src/host/ports.d.ts
4
4
  /** These options go with one command: the folder that it runs in, and the most time that it can take. */
5
5
  interface CommandOptions {
@@ -122,4 +122,4 @@ interface HostPorts {
122
122
  declare const joinPath: (platform: string, ...parts: readonly string[]) => string;
123
123
  //#endregion
124
124
  export { FilePort as a, ProcessMark as c, StopSignal as d, joinPath as f, CommandResult as i, ProcessesPort as l, CommandOptions as n, HostPorts as o, CommandPort as r, NetPort as s, ChildHandle as t, SpawnRequest as u };
125
- //# sourceMappingURL=ports-D-Anj51B.d.ts.map
125
+ //# sourceMappingURL=ports-CSr7qWrA.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { n as Clock } from "./clock-DpVgpY4h.js";
2
- import { D as ServiceDescription } from "./logger-BY1RFLzq.js";
3
- import { d as TransportImpl, r as Lifecycle } from "./lifecycle-C8ffyrQ9.js";
2
+ import { k as ServiceDescription } from "./logger-BN2BfPgU.js";
3
+ import { d as TransportImpl, r as Lifecycle } from "./lifecycle-Br0jAjTk.js";
4
4
  import { Extent, Quantity } from "@mark1russell7/quantity";
5
5
  //#region src/units.d.ts
6
6
  /**
@@ -148,4 +148,4 @@ declare const redeliverOnce: <J>(then: JobAction | RedeliveryPolicy<J>, poison?:
148
148
  declare const queueDrain: <J>(knobs: QueueKnobs, options: QueueDrainOptions<J>) => QueueDrain;
149
149
  //#endregion
150
150
  export { JobSource as a, QueueKnobs as c, queueDrain as d, redeliverOnce as f, JobSettle as i, RedeliveryPolicy as l, JobContext as n, QueueDrain as o, UnitRequest as p, JobFailure as r, QueueDrainOptions as s, JobAction as t, RequeueCause as u };
151
- //# sourceMappingURL=queue-rfmKMwju.d.ts.map
151
+ //# sourceMappingURL=queue-fIkOXKVG.d.ts.map
@@ -1,7 +1,7 @@
1
- import { j as Poll } from "./logger-BY1RFLzq.js";
2
- import { C as MANIFESTATIONS, D as firstDetector, E as Situation, O as unwatched, S as Detector, T as Meeting, _ as Sent, a as ClientKnobs, b as retryProblems, c as ClientSpec, d as Factory, f as ReadyWait, g as SendOptions, h as STARTING_POLL, i as ClientJoin, l as ClientStep, n as CheckOptions, o as ClientOptions, p as RetryKnobs, r as Client, s as ClientSocket, t as Attempt, u as DialFn, v as readyWait, w as Manifestation, y as retryBackoff } from "./core-Cuh3oSfr.js";
3
- import { t as Judge } from "./dial-ZJNa6s9i.js";
4
- import { i as JobSettle } from "./queue-rfmKMwju.js";
1
+ import { N as Poll } from "./logger-BN2BfPgU.js";
2
+ import { C as MANIFESTATIONS, D as firstDetector, E as Situation, O as unwatched, S as Detector, T as Meeting, _ as Sent, a as ClientKnobs, b as retryProblems, c as ClientSpec, d as Factory, f as ReadyWait, g as SendOptions, h as STARTING_POLL, i as ClientJoin, l as ClientStep, n as CheckOptions, o as ClientOptions, p as RetryKnobs, r as Client, s as ClientSocket, t as Attempt, u as DialFn, v as readyWait, w as Manifestation, y as retryBackoff } from "./core-Dt0HEVMq.js";
3
+ import { t as Judge } from "./dial-CSQOl-yj.js";
4
+ import { i as JobSettle } from "./queue-fIkOXKVG.js";
5
5
  import { Extent, Quantity } from "@mark1russell7/quantity";
6
6
  import { Machine } from "@mark1russell7/algebra";
7
7
  //#region src/rabbitmq/connection.d.ts
package/build/redis.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { n as Clock } from "./clock-DpVgpY4h.js";
2
- import { L as heartbeatDetection, ct as Operation } from "./logger-BY1RFLzq.js";
3
- import { C as MANIFESTATIONS, D as firstDetector, E as Situation, O as unwatched, S as Detector, T as Meeting, _ as Sent, a as ClientKnobs, c as ClientSpec, d as Factory, g as SendOptions, i as ClientJoin, l as ClientStep, n as CheckOptions, o as ClientOptions, p as RetryKnobs, r as Client, s as ClientSocket, t as Attempt, u as DialFn, w as Manifestation, y as retryBackoff } from "./core-Cuh3oSfr.js";
2
+ import { ut as Operation, z as heartbeatDetection } from "./logger-BN2BfPgU.js";
3
+ import { C as MANIFESTATIONS, D as firstDetector, E as Situation, O as unwatched, S as Detector, T as Meeting, _ as Sent, a as ClientKnobs, c as ClientSpec, d as Factory, g as SendOptions, i as ClientJoin, l as ClientStep, n as CheckOptions, o as ClientOptions, p as RetryKnobs, r as Client, s as ClientSocket, t as Attempt, u as DialFn, w as Manifestation, y as retryBackoff } from "./core-Dt0HEVMq.js";
4
4
  import { n as LimiterStore } from "./store-1CsNoJ8O.js";
5
5
  import { Extent, Quantity } from "@mark1russell7/quantity";
6
6
  import { Machine } from "@mark1russell7/algebra";
@@ -1,8 +1,8 @@
1
1
  import { n as Clock } from "./clock-DpVgpY4h.js";
2
- import { $ as UncaughtOrigin, G as ExitTrigger, W as ExitSignal, X as ProcessPort, c as Logger, i as LogEntry, s as LogLevel } from "./logger-BY1RFLzq.js";
3
- import { D as CheckFn, F as Outcome, _ as RequestFn, d as TransportImpl, h as RequestEnd, r as Lifecycle } from "./lifecycle-C8ffyrQ9.js";
4
- import { n as ServiceBuilder } from "./builder-BWfcgx__.js";
5
- import { c as ProcessMark, d as StopSignal, i as CommandResult, n as CommandOptions, o as HostPorts, t as ChildHandle, u as SpawnRequest } from "./ports-D-Anj51B.js";
2
+ import { K as ExitSignal, Q as ProcessPort, c as Logger, i as LogEntry, q as ExitTrigger, s as LogLevel, tt as UncaughtOrigin } from "./logger-BN2BfPgU.js";
3
+ import { D as CheckFn, F as Outcome, _ as RequestFn, d as TransportImpl, h as RequestEnd, r as Lifecycle } from "./lifecycle-Br0jAjTk.js";
4
+ import { n as ServiceBuilder } from "./builder-DQj3NNNc.js";
5
+ import { c as ProcessMark, d as StopSignal, i as CommandResult, n as CommandOptions, o as HostPorts, t as ChildHandle, u as SpawnRequest } from "./ports-CSr7qWrA.js";
6
6
  import { FakeClock, fakeClock } from "@mark1russell7/algebra/clock";
7
7
  //#region src/fakes.d.ts
8
8
  /** A fake process receives triggers from a test, and keeps each exit code in place of an exit. */