@nimbus-cqrs/eventsourcingdb 2.5.0 → 3.0.0-beta.1
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 +82 -46
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/{esm → dist}/lib/client.d.ts +28 -17
- package/{esm → dist}/lib/client.d.ts.map +1 -1
- package/{esm → dist}/lib/client.js +25 -19
- package/dist/lib/client.js.map +1 -0
- package/dist/lib/consumerRunner.d.ts +62 -0
- package/dist/lib/consumerRunner.d.ts.map +1 -0
- package/dist/lib/consumerRunner.js +386 -0
- package/dist/lib/consumerRunner.js.map +1 -0
- package/dist/lib/eventConsumer.d.ts +94 -0
- package/dist/lib/eventConsumer.d.ts.map +1 -0
- package/dist/lib/eventConsumer.js +2 -0
- package/dist/lib/eventConsumer.js.map +1 -0
- package/{esm → dist}/lib/eventMapping.d.ts +1 -1
- package/dist/lib/eventMapping.d.ts.map +1 -0
- package/{esm → dist}/lib/eventMapping.js +2 -1
- package/dist/lib/eventMapping.js.map +1 -0
- package/dist/lib/eventObserver.d.ts +158 -0
- package/dist/lib/eventObserver.d.ts.map +1 -0
- package/dist/lib/eventObserver.js +339 -0
- package/dist/lib/eventObserver.js.map +1 -0
- package/dist/lib/observerRegistry.d.ts +39 -0
- package/dist/lib/observerRegistry.d.ts.map +1 -0
- package/dist/lib/observerRegistry.js +56 -0
- package/dist/lib/observerRegistry.js.map +1 -0
- package/{esm → dist}/lib/readEvents.d.ts.map +1 -1
- package/{esm → dist}/lib/readEvents.js +3 -2
- package/dist/lib/readEvents.js.map +1 -0
- package/{esm → dist}/lib/tracing.d.ts.map +1 -1
- package/{esm → dist}/lib/tracing.js +2 -1
- package/dist/lib/tracing.js.map +1 -0
- package/dist/lib/writeEvents.d.ts +29 -0
- package/dist/lib/writeEvents.d.ts.map +1 -0
- package/dist/lib/writeEvents.js +47 -0
- package/dist/lib/writeEvents.js.map +1 -0
- package/package.json +32 -13
- package/src/index.ts +7 -0
- package/src/lib/client.ts +166 -0
- package/src/lib/consumerRunner.ts +592 -0
- package/src/lib/eventConsumer.ts +95 -0
- package/src/lib/eventMapping.ts +115 -0
- package/src/lib/eventObserver.ts +620 -0
- package/src/lib/observerRegistry.ts +69 -0
- package/src/lib/readEvents.ts +28 -0
- package/src/lib/tracing.ts +295 -0
- package/src/lib/writeEvents.ts +72 -0
- package/esm/_dnt.polyfills.d.ts +0 -7
- package/esm/_dnt.polyfills.d.ts.map +0 -1
- package/esm/_dnt.polyfills.js +0 -1
- package/esm/_dnt.shims.d.ts +0 -2
- package/esm/_dnt.shims.d.ts.map +0 -1
- package/esm/_dnt.shims.js +0 -57
- package/esm/deps/jsr.io/@std/fmt/1.0.10/colors.d.ts +0 -700
- package/esm/deps/jsr.io/@std/fmt/1.0.10/colors.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/fmt/1.0.10/colors.js +0 -903
- package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts +0 -14
- package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.js +0 -65
- package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts +0 -20
- package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.js +0 -43
- package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts +0 -44
- package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.js +0 -47
- package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts +0 -44
- package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.js +0 -51
- package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts +0 -31
- package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.js +0 -37
- package/esm/index.d.ts +0 -7
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -6
- package/esm/lib/eventMapping.d.ts.map +0 -1
- package/esm/lib/eventObserver.d.ts +0 -133
- package/esm/lib/eventObserver.d.ts.map +0 -1
- package/esm/lib/eventObserver.js +0 -299
- package/esm/lib/writeEvents.d.ts +0 -11
- package/esm/lib/writeEvents.d.ts.map +0 -1
- package/esm/lib/writeEvents.js +0 -28
- package/esm/package.json +0 -3
- /package/{esm → dist}/lib/readEvents.d.ts +0 -0
- /package/{esm → dist}/lib/tracing.d.ts +0 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { type CheckpointStore } from '@nimbus-cqrs/core';
|
|
2
|
+
import type { ConsumerStatus, EventConsumer } from './eventConsumer.ts';
|
|
3
|
+
export type RetryOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* The maximum number of retries after the initial attempt
|
|
6
|
+
* before giving up. Defaults to 3 (4 failed attempts total).
|
|
7
|
+
*/
|
|
8
|
+
maxRetries: number;
|
|
9
|
+
/**
|
|
10
|
+
* The initial delay in milliseconds before the first retry.
|
|
11
|
+
* Subsequent retries will use exponential backoff with jitter.
|
|
12
|
+
* Defaults to 3000ms.
|
|
13
|
+
*/
|
|
14
|
+
initialRetryDelayMs: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* An event observer watches one EventSourcingDB subject and feeds every
|
|
18
|
+
* event to its {@link EventConsumer}s. The consumers share the stream, each
|
|
19
|
+
* keeps its own checkpoint in the {@link checkpointStore}.
|
|
20
|
+
*
|
|
21
|
+
* On startup the observer resumes from the lowest checkpoint of its
|
|
22
|
+
* consumers, replays what they miss and then stays live for new events.
|
|
23
|
+
*
|
|
24
|
+
* See https://docs.eventsourcingdb.io/getting-started/observing-events for more information.
|
|
25
|
+
*/
|
|
26
|
+
export type EventObserver = {
|
|
27
|
+
/**
|
|
28
|
+
* The unique name of the observer. It is stored on every checkpoint
|
|
29
|
+
* and used to look the observer up with {@link getEventObserver}.
|
|
30
|
+
*/
|
|
31
|
+
name: string;
|
|
32
|
+
/**
|
|
33
|
+
* The subject of the events to observe.
|
|
34
|
+
*/
|
|
35
|
+
subject: string;
|
|
36
|
+
/**
|
|
37
|
+
* Whether to observe events recursively.
|
|
38
|
+
* Defaults to false.
|
|
39
|
+
*/
|
|
40
|
+
recursive?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The consumers of the observed events, run in declaration order.
|
|
43
|
+
*/
|
|
44
|
+
consumers: readonly EventConsumer[];
|
|
45
|
+
/**
|
|
46
|
+
* Where the consumers' checkpoints are persisted.
|
|
47
|
+
*/
|
|
48
|
+
checkpointStore: CheckpointStore;
|
|
49
|
+
/**
|
|
50
|
+
* Options for retry behavior when the observe stream / connection fails.
|
|
51
|
+
* This includes a stream that the server closes (e.g. during a restart)
|
|
52
|
+
* and a stalled connection. Uses exponential backoff with jitter
|
|
53
|
+
* between reconnects.
|
|
54
|
+
* Defaults to { maxRetries: 3, initialRetryDelayMs: 3000 }.
|
|
55
|
+
*/
|
|
56
|
+
connectionRetryOptions?: RetryOptions;
|
|
57
|
+
/**
|
|
58
|
+
* Options for retry behavior when a consumer throws. Handler retries
|
|
59
|
+
* happen in-place without reconnecting the stream. Once they are
|
|
60
|
+
* exhausted the failing consumers are halted.
|
|
61
|
+
* Defaults to { maxRetries: 3, initialRetryDelayMs: 3000 }.
|
|
62
|
+
*/
|
|
63
|
+
handlerRetryOptions?: RetryOptions;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Where an observer currently is in the stream.
|
|
67
|
+
*
|
|
68
|
+
* - `catching-up`: replaying events that were already stored when the
|
|
69
|
+
* observer started.
|
|
70
|
+
* - `live`: every event stored at startup has been processed; the
|
|
71
|
+
* observer now receives new events as they are written.
|
|
72
|
+
* - `stopped`: connection retries are exhausted and the observer gave up.
|
|
73
|
+
*/
|
|
74
|
+
export type ObserverPhase = 'catching-up' | 'live' | 'stopped';
|
|
75
|
+
/**
|
|
76
|
+
* The current status of an observer and its consumers.
|
|
77
|
+
*
|
|
78
|
+
* @property {string} name - The observer name.
|
|
79
|
+
* @property {string} subject - The observed subject.
|
|
80
|
+
* @property {ObserverPhase} phase - Where the observer is in the stream.
|
|
81
|
+
* @property {ConsumerStatus[]} consumers - The state of every consumer in declaration order.
|
|
82
|
+
*/
|
|
83
|
+
export type ObserverStatus = {
|
|
84
|
+
name: string;
|
|
85
|
+
subject: string;
|
|
86
|
+
phase: ObserverPhase;
|
|
87
|
+
consumers: ConsumerStatus[];
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* The result of {@link EventObserverHandle.healthCheck}.
|
|
91
|
+
*/
|
|
92
|
+
export type ObserverHealth = {
|
|
93
|
+
status: 'healthy' | 'error';
|
|
94
|
+
details?: string;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* The handle returned by {@link initEventObserver} to inspect a running
|
|
98
|
+
* observer.
|
|
99
|
+
*/
|
|
100
|
+
export type EventObserverHandle = {
|
|
101
|
+
/**
|
|
102
|
+
* The observer name.
|
|
103
|
+
*/
|
|
104
|
+
readonly name: string;
|
|
105
|
+
/**
|
|
106
|
+
* The observed subject.
|
|
107
|
+
*/
|
|
108
|
+
readonly subject: string;
|
|
109
|
+
/**
|
|
110
|
+
* A snapshot of the observer and its consumers.
|
|
111
|
+
*/
|
|
112
|
+
readonly status: () => ObserverStatus;
|
|
113
|
+
/**
|
|
114
|
+
* `error` when the observer stopped or any consumer is halted,
|
|
115
|
+
* `healthy` otherwise. A consumer that is still catching up is
|
|
116
|
+
* healthy.
|
|
117
|
+
*/
|
|
118
|
+
readonly healthCheck: () => ObserverHealth;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Calculates an exponential backoff delay with jitter for a given
|
|
122
|
+
* retry attempt. The jitter adds up to 30% of the base delay to
|
|
123
|
+
* avoid thundering-herd effects.
|
|
124
|
+
*
|
|
125
|
+
* @param initialDelayMs - The base delay in milliseconds before
|
|
126
|
+
* exponential scaling.
|
|
127
|
+
* @param attempt - The zero-based retry attempt number.
|
|
128
|
+
* @returns The backoff delay in milliseconds.
|
|
129
|
+
*
|
|
130
|
+
* @deprecated Import {@link calculateBackoffDelay} from
|
|
131
|
+
* `@nimbus-cqrs/core` instead. This wrapper keeps the historical
|
|
132
|
+
* 30% jitter default used by EventSourcingDB observers.
|
|
133
|
+
*/
|
|
134
|
+
export declare const calculateBackoffDelay: (initialDelayMs: number, attempt: number) => number;
|
|
135
|
+
/**
|
|
136
|
+
* Starts an event observer.
|
|
137
|
+
*
|
|
138
|
+
* Reads the newest event of the subject to know when the catch-up is over
|
|
139
|
+
* and where consumers with `startFrom: 'head'` begin, loads the consumers'
|
|
140
|
+
* checkpoints, registers the observer under its name and starts the
|
|
141
|
+
* observation loop in the background. The returned
|
|
142
|
+
* promise resolves once the loop has been started, not once the observer
|
|
143
|
+
* has caught up, so a checkpoint store that cannot be reached fails the
|
|
144
|
+
* application start instead of silently replaying everything.
|
|
145
|
+
*
|
|
146
|
+
* The loop keeps running and reconnecting according to the connection
|
|
147
|
+
* retry options until those are exhausted. Consumer failures are retried
|
|
148
|
+
* in place. Once handler retries are exhausted the failing consumers are
|
|
149
|
+
* halted and the observer moves on.
|
|
150
|
+
*
|
|
151
|
+
* @param observer - The event observer configuration.
|
|
152
|
+
* @returns A handle to inspect the running observer.
|
|
153
|
+
*
|
|
154
|
+
* @throws {GenericException} If an observer with the same name is already
|
|
155
|
+
* registered, or the consumers are declared inconsistently.
|
|
156
|
+
*/
|
|
157
|
+
export declare const initEventObserver: (observer: EventObserver) => Promise<EventObserverHandle>;
|
|
158
|
+
//# sourceMappingURL=eventObserver.d.ts.map
|
|
@@ -0,0 +1 @@
|
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,IAAI,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,cAAc,CAAC;IACtC;;;;OAIG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,cAAc,CAAC;CAC9C,CAAC;AAcF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,GAC9B,gBAAgB,MAAM,EACtB,SAAS,MAAM,KAChB,MAKE,CAAC;AA0XN;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,iBAAiB,GAC1B,UAAU,aAAa,KACxB,OAAO,CAAC,mBAAmB,CA2B7B,CAAC"}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { calculateBackoffDelay as coreCalculateBackoffDelay, getLogger, withRetry, } from '@nimbus-cqrs/core';
|
|
2
|
+
import { SpanStatusCode } from '@opentelemetry/api';
|
|
3
|
+
import { getEventSourcingDBClient } from "./client.js";
|
|
4
|
+
import { createConsumerRunner, } from "./consumerRunner.js";
|
|
5
|
+
import { isEventData } from "./eventMapping.js";
|
|
6
|
+
import { registerEventObserver } from "./observerRegistry.js";
|
|
7
|
+
import { readEvents } from "./readEvents.js";
|
|
8
|
+
import { observerConnectionReconnectsCounter, observerConnectionRetryAttemptsCounter, observerEventsHandledCounter, observerHandlerRetryAttemptsCounter, observerHandlingDuration, withObserveEventSpan, } from "./tracing.js";
|
|
9
|
+
const DEFAULT_RETRY_OPTIONS = {
|
|
10
|
+
maxRetries: 3,
|
|
11
|
+
initialRetryDelayMs: 3000,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Returns a promise that resolves after the given number of milliseconds.
|
|
15
|
+
*/
|
|
16
|
+
const delay = (ms) => {
|
|
17
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
18
|
+
};
|
|
19
|
+
const OBSERVER_BACKOFF_OPTIONS = {
|
|
20
|
+
jitterFactor: 0.3,
|
|
21
|
+
maxDelayMs: Infinity,
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Calculates an exponential backoff delay with jitter for a given
|
|
25
|
+
* retry attempt. The jitter adds up to 30% of the base delay to
|
|
26
|
+
* avoid thundering-herd effects.
|
|
27
|
+
*
|
|
28
|
+
* @param initialDelayMs - The base delay in milliseconds before
|
|
29
|
+
* exponential scaling.
|
|
30
|
+
* @param attempt - The zero-based retry attempt number.
|
|
31
|
+
* @returns The backoff delay in milliseconds.
|
|
32
|
+
*
|
|
33
|
+
* @deprecated Import {@link calculateBackoffDelay} from
|
|
34
|
+
* `@nimbus-cqrs/core` instead. This wrapper keeps the historical
|
|
35
|
+
* 30% jitter default used by EventSourcingDB observers.
|
|
36
|
+
*/
|
|
37
|
+
export const calculateBackoffDelay = (initialDelayMs, attempt) => coreCalculateBackoffDelay(initialDelayMs, attempt, OBSERVER_BACKOFF_OPTIONS);
|
|
38
|
+
const resolveRetryOptions = (options) => ({
|
|
39
|
+
maxRetries: options?.maxRetries ?? DEFAULT_RETRY_OPTIONS.maxRetries,
|
|
40
|
+
initialRetryDelayMs: options?.initialRetryDelayMs ??
|
|
41
|
+
DEFAULT_RETRY_OPTIONS.initialRetryDelayMs,
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Logs an informational message when an event observer connects or
|
|
45
|
+
* reconnects to EventSourcingDB. When {@link retryCount} is greater
|
|
46
|
+
* than zero the message indicates a successful reconnection.
|
|
47
|
+
*/
|
|
48
|
+
const logObserverConnection = (observer, retryCount, data) => {
|
|
49
|
+
const retryLabel = retryCount === 1 ? 'retry' : 'retries';
|
|
50
|
+
const message = retryCount > 0
|
|
51
|
+
? `Reconnected event observer "${observer.name}" for subject "${observer.subject}" after ${retryCount} ${retryLabel}`
|
|
52
|
+
: `Observer "${observer.name}" observing events for subject "${observer.subject}"`;
|
|
53
|
+
getLogger().info({ category: 'Nimbus', message, data });
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Handles a connection / stream error by logging it and waiting with
|
|
57
|
+
* exponential backoff before the next reconnect attempt. When the
|
|
58
|
+
* maximum number of retries is exceeded a critical log entry is
|
|
59
|
+
* emitted and no further retries are attempted.
|
|
60
|
+
*
|
|
61
|
+
* @returns `true` if the observer should retry, `false` if retries
|
|
62
|
+
* are exhausted.
|
|
63
|
+
*/
|
|
64
|
+
const handleConnectionError = async (error, observer, retryCount, maxRetries, initialRetryDelayMs) => {
|
|
65
|
+
if (retryCount > maxRetries) {
|
|
66
|
+
getLogger().critical({
|
|
67
|
+
category: 'Nimbus',
|
|
68
|
+
message: `Observer "${observer.name}" failed to observe events for subject "${observer.subject}" after ${maxRetries} ${maxRetries === 1 ? 'retry' : 'retries'}.`,
|
|
69
|
+
});
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
observerConnectionRetryAttemptsCounter.add(1, {
|
|
73
|
+
subject: observer.subject,
|
|
74
|
+
});
|
|
75
|
+
const backoffDelay = coreCalculateBackoffDelay(initialRetryDelayMs, retryCount - 1, OBSERVER_BACKOFF_OPTIONS);
|
|
76
|
+
getLogger().error({
|
|
77
|
+
category: 'Nimbus',
|
|
78
|
+
message: `Error observing events for subject "${observer.subject}" (retry ${retryCount}/${maxRetries}), retrying in ${backoffDelay}ms`,
|
|
79
|
+
error: error,
|
|
80
|
+
});
|
|
81
|
+
await delay(backoffDelay);
|
|
82
|
+
return true;
|
|
83
|
+
};
|
|
84
|
+
const recordHandlerMetrics = (metricLabels, status, startTime) => {
|
|
85
|
+
observerEventsHandledCounter.add(1, { ...metricLabels, status });
|
|
86
|
+
observerHandlingDuration.record((performance.now() - startTime) / 1000, metricLabels);
|
|
87
|
+
};
|
|
88
|
+
const correlationIdOf = (event) => {
|
|
89
|
+
return isEventData(event.data)
|
|
90
|
+
? { correlationId: event.data.nimbusMeta.correlationid }
|
|
91
|
+
: {};
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Offers the event to the consumers with in-place retries. Does not
|
|
95
|
+
* reconnect the observe stream. When all retries are exhausted, halts the
|
|
96
|
+
* failing consumers and returns without throwing so the observer can
|
|
97
|
+
* move on.
|
|
98
|
+
*/
|
|
99
|
+
const handleEventWithRetry = async (observer, runner, event, handlerRetryOptions, span, startTime) => {
|
|
100
|
+
const { maxRetries, initialRetryDelayMs } = handlerRetryOptions;
|
|
101
|
+
const metricLabels = {
|
|
102
|
+
subject: observer.subject,
|
|
103
|
+
event_type: event.type,
|
|
104
|
+
};
|
|
105
|
+
try {
|
|
106
|
+
await withRetry(() => runner.handle(event), {
|
|
107
|
+
maxRetries,
|
|
108
|
+
initialDelayMs: initialRetryDelayMs,
|
|
109
|
+
maxDelayMs: Infinity,
|
|
110
|
+
jitterFactor: 0.3,
|
|
111
|
+
onRetry: ({ error, attempt, delayMs }) => {
|
|
112
|
+
observerHandlerRetryAttemptsCounter.add(1, metricLabels);
|
|
113
|
+
span.addEvent('retry', {
|
|
114
|
+
attempt,
|
|
115
|
+
delay_ms: delayMs,
|
|
116
|
+
});
|
|
117
|
+
getLogger().error({
|
|
118
|
+
category: 'Nimbus',
|
|
119
|
+
message: `Error handling event "${event.id}" (${event.type}) on observer "${observer.name}" (retry ${attempt}/${maxRetries}), retrying in ${delayMs}ms`,
|
|
120
|
+
error,
|
|
121
|
+
...correlationIdOf(event),
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
recordHandlerMetrics(metricLabels, 'success', startTime);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
const handlerError = error instanceof Error ? error : new Error(String(error));
|
|
129
|
+
recordHandlerMetrics(metricLabels, 'skipped', startTime);
|
|
130
|
+
span.setStatus({
|
|
131
|
+
code: SpanStatusCode.ERROR,
|
|
132
|
+
message: handlerError.message,
|
|
133
|
+
});
|
|
134
|
+
span.recordException(handlerError);
|
|
135
|
+
try {
|
|
136
|
+
await runner.onExhausted(handlerError, event);
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
// The consumers are halted in memory either way. The failure
|
|
140
|
+
// marker is written with the next successful checkpoint save.
|
|
141
|
+
getLogger().critical({
|
|
142
|
+
category: 'Nimbus',
|
|
143
|
+
message: `Could not persist the failure of observer "${observer.name}" at event "${event.id}" (${event.type}).`,
|
|
144
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
145
|
+
...correlationIdOf(event),
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* The id of the newest event on the subject, or `null` when the subject
|
|
152
|
+
* has no events yet. Used to tell catch-up from live.
|
|
153
|
+
*/
|
|
154
|
+
const readHeadEventId = async (observer) => {
|
|
155
|
+
const controller = new AbortController();
|
|
156
|
+
// Antichronological, so the first event is the newest. Read only that one.
|
|
157
|
+
const iterator = readEvents(observer.subject, {
|
|
158
|
+
recursive: observer.recursive ?? false,
|
|
159
|
+
order: 'antichronological',
|
|
160
|
+
}, controller.signal)[Symbol.asyncIterator]();
|
|
161
|
+
let head = null;
|
|
162
|
+
let failure;
|
|
163
|
+
try {
|
|
164
|
+
const first = await iterator.next();
|
|
165
|
+
if (!first.done) {
|
|
166
|
+
head = first.value.id;
|
|
167
|
+
controller.abort();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
failure = error;
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
await iterator.return();
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
if (!controller.signal.aborted) {
|
|
178
|
+
failure = error;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (failure !== undefined && !controller.signal.aborted) {
|
|
182
|
+
throw failure;
|
|
183
|
+
}
|
|
184
|
+
return head;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Observes the subject with automatic reconnection on stream failure and
|
|
188
|
+
* in-place retries for consumer failures. Resolves once connection retries
|
|
189
|
+
* are exhausted.
|
|
190
|
+
*/
|
|
191
|
+
const observeWithRetry = async (observer, runtime) => {
|
|
192
|
+
const connectionRetryOptions = resolveRetryOptions(observer.connectionRetryOptions);
|
|
193
|
+
const handlerRetryOptions = resolveRetryOptions(observer.handlerRetryOptions);
|
|
194
|
+
let connectionRetryCount = 0;
|
|
195
|
+
let lastProcessedEventId;
|
|
196
|
+
while (true) {
|
|
197
|
+
try {
|
|
198
|
+
// Resolve the client on every attempt so a re-initialized
|
|
199
|
+
// singleton is picked up after reconnecting to EventSourcingDB.
|
|
200
|
+
const eventSourcingDBClient = getEventSourcingDBClient();
|
|
201
|
+
const lowerBound = lastProcessedEventId
|
|
202
|
+
? { id: lastProcessedEventId, type: 'exclusive' }
|
|
203
|
+
: runtime.runner.lowerBound;
|
|
204
|
+
logObserverConnection(observer, connectionRetryCount, {
|
|
205
|
+
observer: observer.name,
|
|
206
|
+
recursive: observer.recursive ?? false,
|
|
207
|
+
lowerBound,
|
|
208
|
+
});
|
|
209
|
+
for await (const event of eventSourcingDBClient.observeEvents(observer.subject, {
|
|
210
|
+
recursive: observer.recursive ?? false,
|
|
211
|
+
lowerBound,
|
|
212
|
+
})) {
|
|
213
|
+
// Stream is healthy once events flow again. Count a successful
|
|
214
|
+
// reconnect only here so failed reconnect attempts are excluded.
|
|
215
|
+
if (connectionRetryCount > 0) {
|
|
216
|
+
observerConnectionReconnectsCounter.add(1, {
|
|
217
|
+
subject: observer.subject,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
connectionRetryCount = 0;
|
|
221
|
+
const traceContext = event.traceparent
|
|
222
|
+
? {
|
|
223
|
+
traceparent: event.traceparent,
|
|
224
|
+
tracestate: event.tracestate,
|
|
225
|
+
}
|
|
226
|
+
: undefined;
|
|
227
|
+
const startTime = performance.now();
|
|
228
|
+
await withObserveEventSpan(event, observer.subject, traceContext, async (span) => {
|
|
229
|
+
await handleEventWithRetry(observer, runtime.runner, event, handlerRetryOptions, span, startTime);
|
|
230
|
+
});
|
|
231
|
+
// Advance after success or halt so a halted consumer does not
|
|
232
|
+
// block the stream and reconnects resume past the last event.
|
|
233
|
+
lastProcessedEventId = event.id;
|
|
234
|
+
if (runtime.phase === 'catching-up' &&
|
|
235
|
+
(runtime.head === null || BigInt(event.id) >= runtime.head)) {
|
|
236
|
+
runtime.phase = 'live';
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// Observing never ends on its own: the SDK throws when the
|
|
240
|
+
// server closes the stream, so this is only reached if the
|
|
241
|
+
// generator finishes without an error (e.g. an aborted
|
|
242
|
+
// stream). Treat it as the end of observation.
|
|
243
|
+
runtime.phase = 'stopped';
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
connectionRetryCount++;
|
|
248
|
+
const shouldRetry = await handleConnectionError(error, observer, connectionRetryCount, connectionRetryOptions.maxRetries, connectionRetryOptions.initialRetryDelayMs);
|
|
249
|
+
if (!shouldRetry) {
|
|
250
|
+
runtime.phase = 'stopped';
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
const createHandle = (observer, runtime) => {
|
|
257
|
+
const status = () => {
|
|
258
|
+
return {
|
|
259
|
+
name: observer.name,
|
|
260
|
+
subject: observer.subject,
|
|
261
|
+
phase: runtime.phase,
|
|
262
|
+
consumers: runtime.runner.status(),
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
const healthCheck = () => {
|
|
266
|
+
const current = status();
|
|
267
|
+
const halted = current.consumers
|
|
268
|
+
.filter((consumer) => {
|
|
269
|
+
return consumer.halted;
|
|
270
|
+
})
|
|
271
|
+
.map((consumer) => {
|
|
272
|
+
return consumer.name;
|
|
273
|
+
});
|
|
274
|
+
if (current.phase === 'stopped') {
|
|
275
|
+
return {
|
|
276
|
+
status: 'error',
|
|
277
|
+
details: `Observer "${observer.name}" stopped after exhausting its connection retries`,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
if (halted.length > 0) {
|
|
281
|
+
return {
|
|
282
|
+
status: 'error',
|
|
283
|
+
details: `Halted consumer(s): ${halted.join(', ')}`,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
return { status: 'healthy' };
|
|
287
|
+
};
|
|
288
|
+
return {
|
|
289
|
+
name: observer.name,
|
|
290
|
+
subject: observer.subject,
|
|
291
|
+
status,
|
|
292
|
+
healthCheck,
|
|
293
|
+
};
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* Starts an event observer.
|
|
297
|
+
*
|
|
298
|
+
* Reads the newest event of the subject to know when the catch-up is over
|
|
299
|
+
* and where consumers with `startFrom: 'head'` begin, loads the consumers'
|
|
300
|
+
* checkpoints, registers the observer under its name and starts the
|
|
301
|
+
* observation loop in the background. The returned
|
|
302
|
+
* promise resolves once the loop has been started, not once the observer
|
|
303
|
+
* has caught up, so a checkpoint store that cannot be reached fails the
|
|
304
|
+
* application start instead of silently replaying everything.
|
|
305
|
+
*
|
|
306
|
+
* The loop keeps running and reconnecting according to the connection
|
|
307
|
+
* retry options until those are exhausted. Consumer failures are retried
|
|
308
|
+
* in place. Once handler retries are exhausted the failing consumers are
|
|
309
|
+
* halted and the observer moves on.
|
|
310
|
+
*
|
|
311
|
+
* @param observer - The event observer configuration.
|
|
312
|
+
* @returns A handle to inspect the running observer.
|
|
313
|
+
*
|
|
314
|
+
* @throws {GenericException} If an observer with the same name is already
|
|
315
|
+
* registered, or the consumers are declared inconsistently.
|
|
316
|
+
*/
|
|
317
|
+
export const initEventObserver = async (observer) => {
|
|
318
|
+
const headEventId = await readHeadEventId(observer);
|
|
319
|
+
const head = headEventId === null ? null : BigInt(headEventId);
|
|
320
|
+
const runner = await createConsumerRunner({
|
|
321
|
+
observer: observer.name,
|
|
322
|
+
consumers: observer.consumers,
|
|
323
|
+
checkpointStore: observer.checkpointStore,
|
|
324
|
+
head: headEventId,
|
|
325
|
+
});
|
|
326
|
+
const alreadyLive = head === null ||
|
|
327
|
+
(runner.lowerBound.type === 'exclusive' &&
|
|
328
|
+
BigInt(runner.lowerBound.id) >= head);
|
|
329
|
+
const runtime = {
|
|
330
|
+
runner,
|
|
331
|
+
phase: alreadyLive ? 'live' : 'catching-up',
|
|
332
|
+
head,
|
|
333
|
+
};
|
|
334
|
+
const handle = createHandle(observer, runtime);
|
|
335
|
+
registerEventObserver(handle);
|
|
336
|
+
void observeWithRetry(observer, runtime);
|
|
337
|
+
return handle;
|
|
338
|
+
};
|
|
339
|
+
//# sourceMappingURL=eventObserver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventObserver.js","sourceRoot":"","sources":["../../src/lib/eventObserver.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,qBAAqB,IAAI,yBAAyB,EAClD,SAAS,EACT,SAAS,GACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAa,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAGH,oBAAoB,GACvB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACH,mCAAmC,EACnC,sCAAsC,EACtC,4BAA4B,EAC5B,mCAAmC,EACnC,wBAAwB,EAExB,oBAAoB,GACvB,MAAM,cAAc,CAAC;AAgBtB,MAAM,qBAAqB,GAAiB;IACxC,UAAU,EAAE,CAAC;IACb,mBAAmB,EAAE,IAAI;CAC5B,CAAC;AA+GF;;GAEG;AACH,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE;IACxC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAA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CAAC,IAAI,KAAK,WAAW;YACnC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC;IAE9C,MAAM,OAAO,GAAoB;QAC7B,MAAM;QACN,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa;QAC3C,IAAI;KACP,CAAC;IAEF,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC/C,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAE9B,KAAK,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEzC,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { EventObserverHandle } from './eventObserver.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Registers a started observer under its name.
|
|
4
|
+
*
|
|
5
|
+
* @param handle - The observer handle to register.
|
|
6
|
+
*
|
|
7
|
+
* @throws {GenericException} If an observer with the same name is already registered.
|
|
8
|
+
*/
|
|
9
|
+
export declare const registerEventObserver: (handle: EventObserverHandle) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Get a running event observer by name.
|
|
12
|
+
*
|
|
13
|
+
* @param name - The name the observer was started with.
|
|
14
|
+
* @returns The handle to inspect the observer.
|
|
15
|
+
*
|
|
16
|
+
* @throws {GenericException} If no observer with that name has been started.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { getEventObserver } from '@nimbus-cqrs/eventsourcingdb';
|
|
21
|
+
*
|
|
22
|
+
* const { phase } = getEventObserver('ticketing').status();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare const getEventObserver: (name: string) => EventObserverHandle;
|
|
26
|
+
/**
|
|
27
|
+
* All running event observers, in the order they were started.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { listEventObservers } from '@nimbus-cqrs/eventsourcingdb';
|
|
32
|
+
*
|
|
33
|
+
* const unhealthy = listEventObservers()
|
|
34
|
+
* .map((observer) => observer.healthCheck())
|
|
35
|
+
* .filter((health) => health.status !== 'healthy');
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const listEventObservers: () => EventObserverHandle[];
|
|
39
|
+
//# sourceMappingURL=observerRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observerRegistry.d.ts","sourceRoot":"","sources":["../../src/lib/observerRegistry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAO9D;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,mBAAmB,KAAG,IASnE,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,KAAG,mBAW/C,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,QAAO,mBAAmB,EAExD,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { GenericException } from '@nimbus-cqrs/core';
|
|
2
|
+
/**
|
|
3
|
+
* Registry of the observers started with {@link initEventObserver}.
|
|
4
|
+
*/
|
|
5
|
+
const eventObserverRegistry = new Map();
|
|
6
|
+
/**
|
|
7
|
+
* Registers a started observer under its name.
|
|
8
|
+
*
|
|
9
|
+
* @param handle - The observer handle to register.
|
|
10
|
+
*
|
|
11
|
+
* @throws {GenericException} If an observer with the same name is already registered.
|
|
12
|
+
*/
|
|
13
|
+
export const registerEventObserver = (handle) => {
|
|
14
|
+
if (eventObserverRegistry.has(handle.name)) {
|
|
15
|
+
throw new GenericException(`An event observer named "${handle.name}" is already running`, { observer: handle.name });
|
|
16
|
+
}
|
|
17
|
+
eventObserverRegistry.set(handle.name, handle);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Get a running event observer by name.
|
|
21
|
+
*
|
|
22
|
+
* @param name - The name the observer was started with.
|
|
23
|
+
* @returns The handle to inspect the observer.
|
|
24
|
+
*
|
|
25
|
+
* @throws {GenericException} If no observer with that name has been started.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { getEventObserver } from '@nimbus-cqrs/eventsourcingdb';
|
|
30
|
+
*
|
|
31
|
+
* const { phase } = getEventObserver('ticketing').status();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export const getEventObserver = (name) => {
|
|
35
|
+
const handle = eventObserverRegistry.get(name);
|
|
36
|
+
if (handle === undefined) {
|
|
37
|
+
throw new GenericException(`Event observer "${name}" has not been started. Pass it to setupEventSourcingDBClient({ eventObservers }) or initEventObserver() first.`, { observer: name });
|
|
38
|
+
}
|
|
39
|
+
return handle;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* All running event observers, in the order they were started.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { listEventObservers } from '@nimbus-cqrs/eventsourcingdb';
|
|
47
|
+
*
|
|
48
|
+
* const unhealthy = listEventObservers()
|
|
49
|
+
* .map((observer) => observer.healthCheck())
|
|
50
|
+
* .filter((health) => health.status !== 'healthy');
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export const listEventObservers = () => {
|
|
54
|
+
return [...eventObserverRegistry.values()];
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=observerRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observerRegistry.js","sourceRoot":"","sources":["../../src/lib/observerRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;GAEG;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAA+B,CAAC;AAErE;;;;;;GAMG;AACH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"version":3,"file":"readEvents.d.ts","sourceRoot":"","sources":["../../src/lib/readEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAIhE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GACnB,SAAS,MAAM,EACf,SAAS,iBAAiB,EAC1B,SAAS,WAAW,KACrB,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAMlC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getEventSourcingDBClient } from
|
|
2
|
-
import { withAsyncGeneratorSpan } from
|
|
1
|
+
import { getEventSourcingDBClient } from "./client.js";
|
|
2
|
+
import { withAsyncGeneratorSpan } from "./tracing.js";
|
|
3
3
|
/**
|
|
4
4
|
* Reads events from EventSourcingDB for a given subject.
|
|
5
5
|
*
|
|
@@ -19,3 +19,4 @@ export const readEvents = (subject, options, signal) => {
|
|
|
19
19
|
return eventSourcingDBClient.readEvents(subject, options, signal);
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
|
+
//# sourceMappingURL=readEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readEvents.js","sourceRoot":"","sources":["../../src/lib/readEvents.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACtB,OAAe,EACf,OAA0B,EAC1B,MAAoB,EACa,EAAE;IACnC,OAAO,sBAAsB,CAAC,YAAY,EAAE,GAAG,EAAE;QAC7C,MAAM,qBAAqB,GAAG,wBAAwB,EAAE,CAAC;QAEzD,OAAO,qBAAqB,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../../src/lib/tracing.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,IAAI,EAIZ,MAAM,oBAAoB,CAAC;AAE5B,eAAO,MAAM,MAAM,qCAA4B,CAAC;AAEhD,eAAO,MAAM,SAAS,oBAAoB,CAAC;AAmB3C;;;;;GAKG;AACH,eAAO,MAAM,cAAc,iFAM1B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,4BAA4B,+EAMxC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,iFAOpC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mCAAmC,+EAM/C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sCAAsC,+EAMlD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mCAAmC,+EAM/C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EACtB,WAAW,MAAM,EACjB,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,eAAe,YAAY,KAC5B,OAAO,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../../src/lib/tracing.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,IAAI,EAIZ,MAAM,oBAAoB,CAAC;AAE5B,eAAO,MAAM,MAAM,qCAA4B,CAAC;AAEhD,eAAO,MAAM,SAAS,oBAAoB,CAAC;AAmB3C;;;;;GAKG;AACH,eAAO,MAAM,cAAc,iFAM1B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,4BAA4B,+EAMxC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,iFAOpC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mCAAmC,+EAM/C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sCAAsC,+EAMlD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mCAAmC,+EAM/C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EACtB,WAAW,MAAM,EACjB,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,eAAe,YAAY,KAC5B,OAAO,CAAC,CAAC,CA8DX,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,EAClC,OAAO;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EACpD,iBAAiB,MAAM,EACvB,cAAc,YAAY,GAAG,SAAS,EACtC,IAAI,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,KAC/B,OAAO,CAAC,CAAC,CA8BX,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAuB,sBAAsB,CAAC,CAAC,EAC3C,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,GACxC,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CA0C/B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { context as otelContext,
|
|
1
|
+
import { metrics, context as otelContext, propagation, SpanKind, SpanStatusCode, trace, } from '@opentelemetry/api';
|
|
2
2
|
export const tracer = trace.getTracer('nimbus');
|
|
3
3
|
export const DB_SYSTEM = 'eventsourcingdb';
|
|
4
4
|
const meter = metrics.getMeter('nimbus');
|
|
@@ -189,3 +189,4 @@ export async function* withAsyncGeneratorSpan(operation, fn) {
|
|
|
189
189
|
span.end();
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
+
//# sourceMappingURL=tracing.js.map
|