@reventlessdev/reventless-core 3.0.0-alpha.326 → 3.0.0-alpha.328
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/CHANGELOG.md +18 -0
- package/package.json +6 -6
- package/src/CommandSent.res +22 -0
- package/src/CommandSent.res.mjs +22 -0
- package/src/Projection.res +26 -1
- package/src/Projection.res.mjs +19 -1
- package/src/RowChange.res +37 -0
- package/src/RowChange.res.mjs +62 -0
- package/src/adapter/Runtime/AggregateRuntime_Builder_Common.res.mjs +5 -5
- package/src/adapter/Runtime/EventCollectorRuntime_Builder_Single.res.mjs +2 -2
- package/src/admin/Platform_Admin_Callback.res.mjs +1 -1
- package/src/components/Aggregate/Aggregate_Callback.res +88 -18
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +53 -32
- package/src/components/Api/GraphQL_FragmentGenerator.res +22 -0
- package/src/components/Api/GraphQL_FragmentGenerator.res.mjs +20 -4
- package/src/components/Api/GraphQL_SchemaInspector.res.mjs +2 -2
- package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +1 -1
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +9 -0
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +20 -14
- package/src/components/CommandGenerator/CommandGenerator_Callback.res +47 -6
- package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +41 -4
- package/src/components/CommandTopic/CommandTopic_Callback.res.mjs +1 -1
- package/src/components/CommandTopic/CommandTopic_Helpers.res +9 -1
- package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +7 -6
- package/src/components/CommandTopic/CommandTopic_Operations.res +2 -0
- package/src/components/CommandTopic/CommandTopic_Operations.res.mjs +2 -2
- package/src/components/Counter/Counter_Callback.res.mjs +3 -3
- package/src/components/Counter/Counter_Operations.res.mjs +4 -4
- package/src/components/DcbEventLog/DcbEventLog_Operations.res.mjs +3 -3
- package/src/components/EventLog/EventLog_Operations.res +1 -0
- package/src/components/EventLog/EventLog_Operations.res.mjs +3 -3
- package/src/components/EventMapper/EventMapper_Callback.res +12 -2
- package/src/components/EventMapper/EventMapper_Callback.res.mjs +16 -14
- package/src/components/EventTopic/EventTopic_Operations.res +2 -0
- package/src/components/EventTopic/EventTopic_Operations.res.mjs +2 -2
- package/src/components/Extension/Extension_Operations.res +4 -0
- package/src/components/Extension/Extension_Operations.res.mjs +8 -8
- package/src/components/ExtensionPoint/ExtensionPoint_Callback.res +5 -1
- package/src/components/ExtensionPoint/ExtensionPoint_Callback.res.mjs +4 -3
- package/src/components/ExtensionPoint/ExtensionPoint_Operations.res +2 -0
- package/src/components/ExtensionPoint/ExtensionPoint_Operations.res.mjs +9 -8
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +4 -0
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +4 -2
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +12 -0
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +14 -12
- package/src/components/QueryDb/QueryDb_Operations.res +2 -0
- package/src/components/QueryDb/QueryDb_Operations.res.mjs +3 -0
- package/src/components/ReadModel/ReadModel_Callback.res +1 -0
- package/src/components/ReadModel/ReadModel_Callback.res.mjs +1 -1
- package/src/components/SideEffectHandler/SideEffectHandler_Callback.res +2 -0
- package/src/components/SideEffectHandler/SideEffectHandler_Callback.res.mjs +6 -6
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +36 -7
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +38 -20
- package/src/components/StateViewSlice/StateViewSlice_Builder.res +2 -0
- package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +2 -2
- package/src/components/StateViewSlice/StateViewSlice_Callback.res +6 -0
- package/src/components/StateViewSlice/StateViewSlice_Callback.res.mjs +3 -2
- package/src/components/Task/Task_Builder.res +5 -3
- package/src/components/Task/Task_Builder.res.mjs +2 -1
- package/src/plugin/component/Plugin_Callback.res +6 -2
- package/src/plugin/component/Plugin_Callback.res.mjs +3 -2
- package/src/plugin/connect/PluginExtensionPoint_Plugin.res.mjs +6 -6
- package/src/util/CommandPublisher.res.mjs +9 -9
- package/src/util/EffectLogger.res +85 -17
- package/src/util/EffectLogger.res.mjs +63 -12
- package/src/util/FTPHandler.res.mjs +6 -6
- package/src/util/Metrics.res +151 -16
- package/src/util/Metrics.res.mjs +123 -3
- package/src/util/ScheduleOps.res.mjs +4 -4
- package/src/util/Util_AdapterRuntime.res.mjs +2 -2
- package/src/util/Util_Promise.res.mjs +1 -1
- package/src/util/Util_QueryDbRuntime.res.mjs +1 -1
- package/src/util/Validation.res.mjs +1 -1
- package/tests/api/GraphQL_FragmentGeneratorTest.res.mjs +2 -2
- package/tests/api/IdentitySemanticTest.res.mjs +1 -1
- package/tests/commandgenerator/OwnerStampingTest.res +65 -0
- package/tests/commandgenerator/OwnerStampingTest.res.mjs +62 -0
- package/tests/commandtopic/CommandOutcomeHookTest.res +25 -0
- package/tests/commandtopic/CommandOutcomeHookTest.res.mjs +28 -0
- package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +4 -4
- package/tests/logger/ComponentLineIdsTest.res +97 -0
- package/tests/logger/ComponentLineIdsTest.res.mjs +118 -0
- package/tests/logger/LogFormatTest.res.mjs +5 -5
- package/tests/logger/LoggerSinkTest.res.mjs +3 -3
- package/tests/querydb/RowChangeTest.res +87 -0
- package/tests/querydb/RowChangeTest.res.mjs +157 -0
- package/tests/util/MetricsTest.res +72 -0
- package/tests/util/MetricsTest.res.mjs +108 -0
|
@@ -150,7 +150,7 @@ function Make(Spec) {
|
|
|
150
150
|
let resetCache = () => Lru$ReventlessCore.clear(projectionCache);
|
|
151
151
|
let handleSingleCommand = (tagKeysByEventType, crossPartitionTagKeys, payloadTagKeys, partitionTag, dcbEventLog, command$p) => {
|
|
152
152
|
let cmdJson = Message$ReventlessCore.commandJsonOfCommand$p(Id$Reventless.$$String.toString, Spec.commandSchema, command$p);
|
|
153
|
-
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, cmdJson.commandJson, `handling command: ` + LogFormat$ReventlessCore.cmdDetailNoId(cmdJson)));
|
|
153
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, cmdJson.commandJson, EffectLogger$ReventlessCore.idsOf(undefined, undefined, cmdJson.meta), `handling command: ` + LogFormat$ReventlessCore.cmdDetailNoId(cmdJson)));
|
|
154
154
|
let asksForRepeat = Message$ReventlessCore.hasStableMsgId(command$p.meta);
|
|
155
155
|
let query = DcbTag$Reventless.buildQueryFromCommand(asksForRepeat ? queryEventTypesWithOwn : queryEventTypes, Spec.commandSchema, command$p.command, tagKeysByEventType, crossPartitionTagKeys, payloadTagKeys);
|
|
156
156
|
let queryDetail = query.map(qi => {
|
|
@@ -164,7 +164,7 @@ function Make(Spec) {
|
|
|
164
164
|
return types + `{` + tags + `}`;
|
|
165
165
|
}
|
|
166
166
|
}).join(" OR ");
|
|
167
|
-
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, `query: ` + queryDetail));
|
|
167
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, EffectLogger$ReventlessCore.idsOf(undefined, undefined, cmdJson.meta), `query: ` + queryDetail));
|
|
168
168
|
let entityId;
|
|
169
169
|
if (partitionTag !== undefined) {
|
|
170
170
|
switch (partitionTag.TAG) {
|
|
@@ -182,6 +182,24 @@ function Make(Spec) {
|
|
|
182
182
|
} else {
|
|
183
183
|
entityId = undefined;
|
|
184
184
|
}
|
|
185
|
+
let ids;
|
|
186
|
+
let exit = 0;
|
|
187
|
+
if (partitionTag !== undefined) {
|
|
188
|
+
switch (partitionTag.TAG) {
|
|
189
|
+
case "Simple" :
|
|
190
|
+
ids = EffectLogger$ReventlessCore.idsOf(entityId, partitionTag._0.key, cmdJson.meta);
|
|
191
|
+
break;
|
|
192
|
+
case "Composite" :
|
|
193
|
+
case "ByEventType" :
|
|
194
|
+
exit = 1;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
exit = 1;
|
|
199
|
+
}
|
|
200
|
+
if (exit === 1) {
|
|
201
|
+
ids = EffectLogger$ReventlessCore.idsOf(undefined, undefined, cmdJson.meta);
|
|
202
|
+
}
|
|
185
203
|
let ownerFieldsOf = raw => {
|
|
186
204
|
if (partitionTag !== undefined) {
|
|
187
205
|
if (entityId !== undefined) {
|
|
@@ -282,7 +300,7 @@ function Make(Spec) {
|
|
|
282
300
|
if (cacheHit && retries === 3) {
|
|
283
301
|
Metrics$ReventlessCore.emitCount("DcbDecisionModelDeltaEventCount", Spec.name, reads.length);
|
|
284
302
|
}
|
|
285
|
-
return EffectLogger$ReventlessCore.logInfo(comp, undefined, `read` + (
|
|
303
|
+
return EffectLogger$ReventlessCore.logInfo(comp, undefined, ids, `read` + (
|
|
286
304
|
cacheHit ? " (cached, delta)" : ""
|
|
287
305
|
) + `: ` + reads.length.toString() + ` event(s)` + (
|
|
288
306
|
reads.length === 0 ? "" : ` [` + reads.join(", ") + `]`
|
|
@@ -292,16 +310,16 @@ function Make(Spec) {
|
|
|
292
310
|
let owners = param[3];
|
|
293
311
|
let headPosition = param[1];
|
|
294
312
|
let state = param[0];
|
|
295
|
-
return Effect.flatMap(EffectLogger$ReventlessCore.logDebug(comp, undefined, `deciding: id=` + Stdlib_Option.getOr(entityId, "-") + ` head=` + Stdlib_Option.getOr(headPosition, "-") + ` cmd=` + LogFormat$ReventlessCore.cmdName(cmdJson)), () => {
|
|
313
|
+
return Effect.flatMap(EffectLogger$ReventlessCore.logDebug(comp, undefined, ids, `deciding: id=` + Stdlib_Option.getOr(entityId, "-") + ` head=` + Stdlib_Option.getOr(headPosition, "-") + ` cmd=` + LogFormat$ReventlessCore.cmdName(cmdJson)), () => {
|
|
296
314
|
let match = ownershipRefusal(owners);
|
|
297
315
|
if (repeated) {
|
|
298
|
-
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.correlationId, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
316
|
+
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.correlationId, cmdJson.meta.causationId, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
299
317
|
entityId: entityId,
|
|
300
318
|
eventCount: 0
|
|
301
319
|
}) : ({
|
|
302
320
|
eventCount: 0
|
|
303
321
|
}));
|
|
304
|
-
return Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, `repeat dropped: ` + LogFormat$ReventlessCore.cmdName(cmdJson) + ` msgId=` + cmdJson.meta.msgId + ` already caused events in id=` + Stdlib_Option.getOr(entityId, "-")), () => ({
|
|
322
|
+
return Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, ids, `repeat dropped: ` + LogFormat$ReventlessCore.cmdName(cmdJson) + ` msgId=` + cmdJson.meta.msgId + ` already caused events in id=` + Stdlib_Option.getOr(entityId, "-")), () => ({
|
|
305
323
|
TAG: "Ok",
|
|
306
324
|
_0: "ok"
|
|
307
325
|
}));
|
|
@@ -313,9 +331,9 @@ function Make(Spec) {
|
|
|
313
331
|
headPosition,
|
|
314
332
|
owners
|
|
315
333
|
]);
|
|
316
|
-
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "AccessRefusal", cmdJson.meta.correlationId, cmdJson.meta.msgId, rejected);
|
|
334
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "AccessRefusal", cmdJson.meta.correlationId, cmdJson.meta.causationId, cmdJson.meta.msgId, rejected);
|
|
317
335
|
let line = `refused: ` + rejected.errorDetail + ` id=` + Stdlib_Option.getOr(entityId, "-");
|
|
318
|
-
return Effect.map(match.isDefect ? EffectLogger$ReventlessCore.logError(comp, undefined, line) : EffectLogger$ReventlessCore.logWarn(comp, undefined, line), () => ({
|
|
336
|
+
return Effect.map(match.isDefect ? EffectLogger$ReventlessCore.logError(comp, undefined, ids, line) : EffectLogger$ReventlessCore.logWarn(comp, undefined, ids, line), () => ({
|
|
319
337
|
TAG: "Ok",
|
|
320
338
|
_0: "rejected"
|
|
321
339
|
}));
|
|
@@ -329,13 +347,13 @@ function Make(Spec) {
|
|
|
329
347
|
headPosition,
|
|
330
348
|
owners
|
|
331
349
|
]);
|
|
332
|
-
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.correlationId, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
350
|
+
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.correlationId, cmdJson.meta.causationId, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
333
351
|
entityId: entityId,
|
|
334
352
|
eventCount: 0
|
|
335
353
|
}) : ({
|
|
336
354
|
eventCount: 0
|
|
337
355
|
}));
|
|
338
|
-
return Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, "no events produced"), () => ({
|
|
356
|
+
return Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, ids, "no events produced"), () => ({
|
|
339
357
|
TAG: "Ok",
|
|
340
358
|
_0: "ok"
|
|
341
359
|
}));
|
|
@@ -373,20 +391,20 @@ function Make(Spec) {
|
|
|
373
391
|
query: query,
|
|
374
392
|
after: headPosition
|
|
375
393
|
};
|
|
376
|
-
return Effect.flatMap(Effect.flatMap(EffectLogger$ReventlessCore.logInfo(comp, eventJsons, `produced ` + eventCount + ` event(s): [` + eventDetails + `]`), () => Effect.promise(() => dcbEventLog.append(rawEvents, condition))), appendResult => {
|
|
394
|
+
return Effect.flatMap(Effect.flatMap(EffectLogger$ReventlessCore.logInfo(comp, eventJsons, ids, `produced ` + eventCount + ` event(s): [` + eventDetails + `]`), () => Effect.promise(() => dcbEventLog.append(rawEvents, condition))), appendResult => {
|
|
377
395
|
if (appendResult.TAG === "Ok") {
|
|
378
396
|
cachePut([
|
|
379
397
|
state,
|
|
380
398
|
headPosition,
|
|
381
399
|
owners
|
|
382
400
|
]);
|
|
383
|
-
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.correlationId, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
401
|
+
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.correlationId, cmdJson.meta.causationId, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
384
402
|
entityId: entityId,
|
|
385
403
|
eventCount: rawEvents.length
|
|
386
404
|
}) : ({
|
|
387
405
|
eventCount: rawEvents.length
|
|
388
406
|
}));
|
|
389
|
-
return Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, `append: ` + eventCount + ` event(s)`), () => ({
|
|
407
|
+
return Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, ids, `append: ` + eventCount + ` event(s)`), () => ({
|
|
390
408
|
TAG: "Ok",
|
|
391
409
|
_0: "ok"
|
|
392
410
|
}));
|
|
@@ -409,17 +427,17 @@ function Make(Spec) {
|
|
|
409
427
|
owners
|
|
410
428
|
];
|
|
411
429
|
Metrics$ReventlessCore.emitCount("AppendRetry", Spec.name, undefined);
|
|
412
|
-
return Effect.flatMap(EffectLogger$ReventlessCore.logWarn(comp, undefined, `append failed (retrying ` + ((3 - retries | 0) + 1 | 0).toString() + `/` + (3).toString() + `): ` + errDetail), () => attempt(retries - 1 | 0));
|
|
430
|
+
return Effect.flatMap(EffectLogger$ReventlessCore.logWarn(comp, undefined, ids, `append failed (retrying ` + ((3 - retries | 0) + 1 | 0).toString() + `/` + (3).toString() + `): ` + errDetail), () => attempt(retries - 1 | 0));
|
|
413
431
|
} else {
|
|
414
432
|
cacheInvalidate();
|
|
415
433
|
if (errorCode === CommandOutcome$Reventless.code("Conflict")) {
|
|
416
434
|
Metrics$ReventlessCore.emitCount("AppendConflict", Spec.name, undefined);
|
|
417
435
|
}
|
|
418
|
-
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", cmdJson.meta.correlationId, cmdJson.meta.msgId, {
|
|
436
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", cmdJson.meta.correlationId, cmdJson.meta.causationId, cmdJson.meta.msgId, {
|
|
419
437
|
errorCode: errorCode,
|
|
420
438
|
errorDetail: errDetail
|
|
421
439
|
});
|
|
422
|
-
return Effect.map(EffectLogger$ReventlessCore.logError(comp, undefined, `append failed, retries exhausted: ` + errDetail), () => ({
|
|
440
|
+
return Effect.map(EffectLogger$ReventlessCore.logError(comp, undefined, ids, `append failed, retries exhausted: ` + errDetail), () => ({
|
|
423
441
|
TAG: "Error",
|
|
424
442
|
_0: errDetail
|
|
425
443
|
}));
|
|
@@ -432,11 +450,11 @@ function Make(Spec) {
|
|
|
432
450
|
headPosition,
|
|
433
451
|
owners
|
|
434
452
|
]);
|
|
435
|
-
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", cmdJson.meta.correlationId, cmdJson.meta.msgId, {
|
|
453
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", cmdJson.meta.correlationId, cmdJson.meta.causationId, cmdJson.meta.msgId, {
|
|
436
454
|
errorCode: CommandOutcome$Reventless.code("AppendFailed"),
|
|
437
455
|
errorDetail: detail
|
|
438
456
|
});
|
|
439
|
-
return Effect.map(EffectLogger$ReventlessCore.logError(comp, undefined, `append refused: ` + detail), () => ({
|
|
457
|
+
return Effect.map(EffectLogger$ReventlessCore.logError(comp, undefined, ids, `append refused: ` + detail), () => ({
|
|
440
458
|
TAG: "Error",
|
|
441
459
|
_0: detail
|
|
442
460
|
}));
|
|
@@ -452,11 +470,11 @@ function Make(Spec) {
|
|
|
452
470
|
let match$1 = Message$ReventlessCore.splitMessage(errorJson);
|
|
453
471
|
let payloadDict = match$1[1];
|
|
454
472
|
let errorDetail = Object.entries(payloadDict).length === 0 ? "" : JSON.stringify(payloadDict);
|
|
455
|
-
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "DomainRejection", cmdJson.meta.correlationId, cmdJson.meta.msgId, {
|
|
473
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "DomainRejection", cmdJson.meta.correlationId, cmdJson.meta.causationId, cmdJson.meta.msgId, {
|
|
456
474
|
errorCode: errorCode,
|
|
457
475
|
errorDetail: errorDetail
|
|
458
476
|
});
|
|
459
|
-
return Effect.map(EffectLogger$ReventlessCore.logError(comp, undefined, `decide rejected: ` + errorCode + ` ` + errorDetail), () => ({
|
|
477
|
+
return Effect.map(EffectLogger$ReventlessCore.logError(comp, undefined, ids, `decide rejected: ` + errorCode + ` ` + errorDetail), () => ({
|
|
460
478
|
TAG: "Ok",
|
|
461
479
|
_0: "rejected"
|
|
462
480
|
}));
|
|
@@ -154,6 +154,7 @@ module Make = (
|
|
|
154
154
|
->Option.getOr("unknown")
|
|
155
155
|
EffectLogger.logError(
|
|
156
156
|
~comp,
|
|
157
|
+
~ids=EffectLogger.idsOf(meta),
|
|
157
158
|
`project failed for ${eventType}: ${errMsg}`,
|
|
158
159
|
)->Effect.runSync
|
|
159
160
|
[]
|
|
@@ -171,6 +172,7 @@ module Make = (
|
|
|
171
172
|
}
|
|
172
173
|
EffectLogger.logInfo(
|
|
173
174
|
~comp,
|
|
175
|
+
~ids=EffectLogger.idsOf(meta),
|
|
174
176
|
~detail=eventData,
|
|
175
177
|
`handling event ${idxStr}/${total}: ${LogFormat.bold(
|
|
176
178
|
eventType,
|
|
@@ -122,14 +122,14 @@ function Make(RuntimeEnvironment) {
|
|
|
122
122
|
} catch (raw_exn) {
|
|
123
123
|
let exn$1 = Primitive_exceptions.internalToException(raw_exn);
|
|
124
124
|
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$1), Stdlib_JsExn.message), "unknown");
|
|
125
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, `project failed for ` + eventType + `: ` + errMsg));
|
|
125
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, EffectLogger$ReventlessCore.idsOf(undefined, undefined, meta), `project failed for ` + eventType + `: ` + errMsg));
|
|
126
126
|
actions = [];
|
|
127
127
|
}
|
|
128
128
|
let idxStr = (i + 1 | 0).toString();
|
|
129
129
|
let actionsStr = LogFormat$ReventlessCore.actionNames(actions);
|
|
130
130
|
let f = Object.entries(dataDict).map(param => param[0] + `:` + JSON.stringify(param[1])).join(",");
|
|
131
131
|
let fieldsStr = f === "" ? "" : `({` + f + `})`;
|
|
132
|
-
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, dataDict, `handling event ` + idxStr + `/` + total + `: ` + LogFormat$ReventlessCore.bold(eventType) + fieldsStr + ` ` + actionsStr));
|
|
132
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, dataDict, EffectLogger$ReventlessCore.idsOf(undefined, undefined, meta), `handling event ` + idxStr + `/` + total + `: ` + LogFormat$ReventlessCore.bold(eventType) + fieldsStr + ` ` + actionsStr));
|
|
133
133
|
let match$1 = ViewChange$ReventlessCore.entityOfEnvelope(envelopeDict);
|
|
134
134
|
let sources = [ViewChange$ReventlessCore.sourceOf(meta, match$1[0], match$1[1], undefined)];
|
|
135
135
|
return actions.map(action => [
|
|
@@ -59,8 +59,14 @@ module Make = (
|
|
|
59
59
|
),
|
|
60
60
|
)
|
|
61
61
|
let actionsStr = LogFormat.actionNames(actions)
|
|
62
|
+
let tag = raw.tags->Array.get(0)
|
|
62
63
|
EffectLogger.logInfo(
|
|
63
64
|
~comp,
|
|
65
|
+
~ids=EffectLogger.idsOf(
|
|
66
|
+
raw.meta,
|
|
67
|
+
~entityId=?tag->Option.map(t => t.value),
|
|
68
|
+
~entityType=?tag->Option.map(t => t.key),
|
|
69
|
+
),
|
|
64
70
|
~detail=raw.data,
|
|
65
71
|
`handling event ${idx.contents->Int.toString}/${count}: ${LogFormat.bold(
|
|
66
72
|
raw.eventType,
|
|
@@ -43,7 +43,8 @@ function Make(Spec) {
|
|
|
43
43
|
recordedAt: raw.recordedAt
|
|
44
44
|
}).map(__x => Projection$Reventless.mapActionId(__x, Spec.Id.toString, Spec.Id.makeFromString));
|
|
45
45
|
let actionsStr = LogFormat$ReventlessCore.actionNames(actions);
|
|
46
|
-
|
|
46
|
+
let tag = raw.tags[0];
|
|
47
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, raw.data, EffectLogger$ReventlessCore.idsOf(Stdlib_Option.map(tag, t => t.value), Stdlib_Option.map(tag, t => t.key), raw.meta), `handling event ` + idx.contents.toString() + `/` + count + `: ` + LogFormat$ReventlessCore.bold(raw.eventType) + `(` + id + `) ` + actionsStr));
|
|
47
48
|
let sources = [ViewChange$ReventlessCore.sourceOf(raw.meta, Stdlib_Option.map(raw.tags[0], tag => tag.value), Stdlib_Option.map(raw.tags[0], tag => tag.key), undefined)];
|
|
48
49
|
allActions.push(...actions.map(action => ({
|
|
49
50
|
action: Projection$ReventlessCore.rewriteAction(action, raw.meta.time, Spec.stateSchema),
|
|
@@ -53,7 +54,7 @@ function Make(Spec) {
|
|
|
53
54
|
});
|
|
54
55
|
let skipped = rawEvents.length - events.length | 0;
|
|
55
56
|
if (skipped > 0) {
|
|
56
|
-
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, `skipped=` + skipped.toString() + ` events (decode mismatch)`));
|
|
57
|
+
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, undefined, `skipped=` + skipped.toString() + ` events (decode mismatch)`));
|
|
57
58
|
}
|
|
58
59
|
return await Projection$ReventlessCore.handleSourcedActions(comp, onChange, allActions, queryDbOps, Spec.subIdConfig);
|
|
59
60
|
};
|
|
@@ -140,9 +140,11 @@ module Make = (
|
|
|
140
140
|
)
|
|
141
141
|
)
|
|
142
142
|
|
|
143
|
-
let publishCommands: Task.publishCommands = (aggregateName, cmdJsons) =>
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
let publishCommands: Task.publishCommands = (aggregateName, cmdJsons) =>
|
|
144
|
+
CommandSent.announcing(
|
|
145
|
+
~comp=`Task(${Spec.name})`,
|
|
146
|
+
publishToAggregates->Dict.get(aggregateName)->Option.getOrThrow,
|
|
147
|
+
)(cmdJsons)
|
|
146
148
|
|
|
147
149
|
let config = Spec.setup(queryEngine, queryBucketName, opts)
|
|
148
150
|
|
|
@@ -11,6 +11,7 @@ import * as Task$ReventlessCore from "./Task.res.mjs";
|
|
|
11
11
|
import * as Logger$ReventlessCore from "../../util/Logger.res.mjs";
|
|
12
12
|
import * as Aggregate$ReventlessCore from "../Aggregate/Aggregate.res.mjs";
|
|
13
13
|
import * as Component$ReventlessCore from "../Component.res.mjs";
|
|
14
|
+
import * as CommandSent$ReventlessCore from "../../CommandSent.res.mjs";
|
|
14
15
|
import * as Util_Promise$ReventlessCore from "../../util/Util_Promise.res.mjs";
|
|
15
16
|
import * as ComponentType$ReventlessCore from "../../ComponentType.res.mjs";
|
|
16
17
|
import * as RuntimeHints$ReventlessInfra from "@reventlessdev/reventless-infra/src/types/RuntimeHints.res.mjs";
|
|
@@ -63,7 +64,7 @@ function Make(Spec) {
|
|
|
63
64
|
return Pulumi.output("");
|
|
64
65
|
}
|
|
65
66
|
}));
|
|
66
|
-
let publishCommands = (aggregateName, cmdJsons) => Stdlib_Option.getOrThrow(publishToAggregates[aggregateName], undefined)(cmdJsons);
|
|
67
|
+
let publishCommands = (aggregateName, cmdJsons) => CommandSent$ReventlessCore.announcing(`Task(` + Spec.name + `)`, Stdlib_Option.getOrThrow(publishToAggregates[aggregateName], undefined))(cmdJsons);
|
|
67
68
|
let config = Spec.setup(queryEngine, queryBucketName, opts);
|
|
68
69
|
let sideEffectHandler = Stdlib_Option.map(config.sideEffects, sideEffects => SpecificSideEffectHandler.make(extra$1, sideEffects, Aggregate$ReventlessCore.allEventTopics(allAggregates), allCommandTopics, undefined, queryEngine, scheduler, resourceNaming, undefined, undefined, undefined, opts));
|
|
69
70
|
Stdlib_Option.forEach(sideEffectHandler, handler => Builder_Helpers$ReventlessCore.registerTaskSideEffectHandler(Component$ReventlessCore.operations(handler).apply(param => {}), SpecificSideEffectHandler.finish));
|
|
@@ -14,6 +14,10 @@ module type T = {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
module Make = (Spec: Spec): T => {
|
|
17
|
+
// What this dispatcher logs is an event routed to an extension point or an extension, so its
|
|
18
|
+
// lines go by a contract's component name rather than the plugin's.
|
|
19
|
+
let comp = (id: string) => `ExtensionRouting(${id})`
|
|
20
|
+
|
|
17
21
|
let warnedServices = ref(Belt.Set.String.empty)
|
|
18
22
|
|
|
19
23
|
let knownServiceNames = () =>
|
|
@@ -44,7 +48,7 @@ module Make = (Spec: Spec): T => {
|
|
|
44
48
|
warnedServices := warnedServices.contents->Belt.Set.String.add(serviceName)
|
|
45
49
|
let known = knownServiceNames()->Array.join(", ")
|
|
46
50
|
EffectLogger.logWarn(
|
|
47
|
-
~comp
|
|
51
|
+
~comp=comp(id),
|
|
48
52
|
`incoming event has service="${serviceName}" but no handler is registered for it — known services: [${known}]. Likely cause: an ExtensionPointMapping/Extension Delegate.name does not match the source's serviceName (DCB sources use "<plugin>DcbEventLog").`,
|
|
49
53
|
)
|
|
50
54
|
}
|
|
@@ -76,7 +80,7 @@ module Make = (Spec: Spec): T => {
|
|
|
76
80
|
Spec.incomingExtensionEventHandlers->Dict.get(serviceName)->Option.isSome
|
|
77
81
|
if isHandled {
|
|
78
82
|
EffectLogger.logInfo(
|
|
79
|
-
~comp
|
|
83
|
+
~comp=comp(id),
|
|
80
84
|
`incoming event: ${LogFormat.eventSummary(eventJson')}`,
|
|
81
85
|
)->Effect.zipRight(
|
|
82
86
|
handleEventEffect(
|
|
@@ -9,6 +9,7 @@ import * as LogFormat$ReventlessCore from "../../util/LogFormat.res.mjs";
|
|
|
9
9
|
import * as EffectLogger$ReventlessCore from "../../util/EffectLogger.res.mjs";
|
|
10
10
|
|
|
11
11
|
function Make(Spec) {
|
|
12
|
+
let comp = id => `ExtensionRouting(` + id + `)`;
|
|
12
13
|
let warnedServices = {
|
|
13
14
|
contents: undefined
|
|
14
15
|
};
|
|
@@ -27,7 +28,7 @@ function Make(Spec) {
|
|
|
27
28
|
return Stdlib_Option.mapOr(Message$ReventlessCore.serviceNameOfMsg(eventJson$p), Effect.succeed(), serviceName => {
|
|
28
29
|
let isHandled = Stdlib_Option.isSome(Spec.incomingConnectExtensionEventHandlers[serviceName]) || Stdlib_Option.isSome(Spec.outgoingExtensionPointEventHandlers[serviceName]) || Stdlib_Option.isSome(Spec.outgoingExtensionEventHandlers[serviceName]) || Stdlib_Option.isSome(Spec.incomingExtensionEventHandlers[serviceName]);
|
|
29
30
|
if (isHandled) {
|
|
30
|
-
return Effect.zipRight(EffectLogger$ReventlessCore.logInfo(
|
|
31
|
+
return Effect.zipRight(EffectLogger$ReventlessCore.logInfo(comp(id), undefined, undefined, `incoming event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)), Effect.zipRight(handleEventEffect(eventJson$p, Spec.incomingConnectExtensionEventHandlers), Effect.map(Effect.all([
|
|
31
32
|
handleEventEffect(eventJson$p, Spec.outgoingExtensionPointEventHandlers),
|
|
32
33
|
handleEventEffect(eventJson$p, Spec.outgoingExtensionEventHandlers),
|
|
33
34
|
handleEventEffect(eventJson$p, Spec.incomingExtensionEventHandlers)
|
|
@@ -40,7 +41,7 @@ function Make(Spec) {
|
|
|
40
41
|
}
|
|
41
42
|
warnedServices.contents = Belt_SetString.add(warnedServices.contents, serviceName);
|
|
42
43
|
let known = knownServiceNames().join(", ");
|
|
43
|
-
return EffectLogger$ReventlessCore.logWarn(
|
|
44
|
+
return EffectLogger$ReventlessCore.logWarn(comp(id), undefined, undefined, `incoming event has service="` + serviceName + `" but no handler is registered for it — known services: [` + known + `]. Likely cause: an ExtensionPointMapping/Extension Delegate.name does not match the source's serviceName (DCB sources use "<plugin>DcbEventLog").`);
|
|
44
45
|
}
|
|
45
46
|
});
|
|
46
47
|
}));
|
|
@@ -44,7 +44,7 @@ function Make(Spec) {
|
|
|
44
44
|
]
|
|
45
45
|
], 1000);
|
|
46
46
|
if (jsons.length === 0) {
|
|
47
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logWarn(PluginExtensionPointSpec$ReventlessInfra.name, undefined, `ForwardCommand: Couldn't find Plugin with ExtensionPoint ` + extensionPointName));
|
|
47
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logWarn(PluginExtensionPointSpec$ReventlessInfra.name, undefined, undefined, `ForwardCommand: Couldn't find Plugin with ExtensionPoint ` + extensionPointName));
|
|
48
48
|
}
|
|
49
49
|
let plugin = jsons[0];
|
|
50
50
|
let exit = 0;
|
|
@@ -55,12 +55,12 @@ function Make(Spec) {
|
|
|
55
55
|
} catch (raw_err) {
|
|
56
56
|
let err = Primitive_exceptions.internalToException(raw_err);
|
|
57
57
|
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err), Stdlib_JsExn.message), "unknown");
|
|
58
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logError(PluginExtensionPointSpec$ReventlessInfra.name, undefined, `ForwardCommand: Couldn't decode Plugin: ` + errMsg));
|
|
58
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError(PluginExtensionPointSpec$ReventlessInfra.name, undefined, undefined, `ForwardCommand: Couldn't decode Plugin: ` + errMsg));
|
|
59
59
|
}
|
|
60
60
|
if (exit === 1) {
|
|
61
61
|
let extensionPoint = plugin$1.extensionPoints.find(extensionPoint => extensionPoint.name === extensionPointName);
|
|
62
62
|
if (extensionPoint === undefined) {
|
|
63
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logWarn(PluginExtensionPointSpec$ReventlessInfra.name, undefined, `ForwardCommand: Couldn't find ExtensionPoint ` + extensionPointName + ` in ` + plugin$1.name));
|
|
63
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logWarn(PluginExtensionPointSpec$ReventlessInfra.name, undefined, undefined, `ForwardCommand: Couldn't find ExtensionPoint ` + extensionPointName + ` in ` + plugin$1.name));
|
|
64
64
|
}
|
|
65
65
|
let exit$1 = 0;
|
|
66
66
|
let val;
|
|
@@ -70,10 +70,10 @@ function Make(Spec) {
|
|
|
70
70
|
} catch (raw_err$1) {
|
|
71
71
|
let err$1 = Primitive_exceptions.internalToException(raw_err$1);
|
|
72
72
|
let errMsg$1 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err$1), Stdlib_JsExn.message), "unknown");
|
|
73
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logError(PluginExtensionPointSpec$ReventlessInfra.name, undefined, `ForwardCommand: Error on publish command: ` + errMsg$1));
|
|
73
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError(PluginExtensionPointSpec$ReventlessInfra.name, undefined, undefined, `ForwardCommand: Error on publish command: ` + errMsg$1));
|
|
74
74
|
}
|
|
75
75
|
if (exit$1 === 2) {
|
|
76
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logInfo(PluginExtensionPointSpec$ReventlessInfra.name, undefined, `ForwardCommand: published command to ` + plugin$1.name + ` ` + extensionPoint.commandTopic));
|
|
76
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logInfo(PluginExtensionPointSpec$ReventlessInfra.name, undefined, undefined, `ForwardCommand: published command to ` + plugin$1.name + ` ` + extensionPoint.commandTopic));
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
};
|
|
@@ -164,7 +164,7 @@ function Make(Spec) {
|
|
|
164
164
|
case "ConnectPlugin" :
|
|
165
165
|
let pluginDefinition = cmd._0;
|
|
166
166
|
let protocolErrors = pluginDefinition.extensionProtocols.flatMap(proto => Compat$ReventlessInterop.validateProtocol(CompatMatrix$ReventlessInterop.platformPlugin, proto.extensionPointName, proto.commandVersion, proto.eventVersion));
|
|
167
|
-
let reportAction = protocolErrors.length !== 0 ? (Effect.runSync(EffectLogger$ReventlessCore.logWarn(PluginExtensionPointSpec$ReventlessInfra.name, undefined, `Protocol version mismatch for plugin ` + pluginDefinition.id + `: ` + Stdlib_Option.getOr(JSON.stringify(protocolErrors), "[]"))), [{
|
|
167
|
+
let reportAction = protocolErrors.length !== 0 ? (Effect.runSync(EffectLogger$ReventlessCore.logWarn(PluginExtensionPointSpec$ReventlessInfra.name, undefined, undefined, `Protocol version mismatch for plugin ` + pluginDefinition.id + `: ` + Stdlib_Option.getOr(JSON.stringify(protocolErrors), "[]"))), [{
|
|
168
168
|
TAG: "PublishCommand",
|
|
169
169
|
_0: Plugin$ReventlessCore.name(id),
|
|
170
170
|
_1: {
|
|
@@ -30,13 +30,13 @@ function Make(Spec) {
|
|
|
30
30
|
let e = Primitive_exceptions.internalToException(raw_e);
|
|
31
31
|
if (e.RE_EXN_ID === "JsExn") {
|
|
32
32
|
let errMsg = Stdlib_Option.getOr(Stdlib_JsExn.message(e._1), "unknown");
|
|
33
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logError("CommandPublisher", undefined, `Couldn't publish commands: ` + errMsg));
|
|
33
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError("CommandPublisher", undefined, undefined, `Couldn't publish commands: ` + errMsg));
|
|
34
34
|
}
|
|
35
35
|
throw e;
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
let toJsons = commandsToSend => {
|
|
39
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, `toJsons: commandsToSend: ` + commandsToSend.length.toString() + ` rest: ` + buffer.length.toString()));
|
|
39
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, undefined, `toJsons: commandsToSend: ` + commandsToSend.length.toString() + ` rest: ` + buffer.length.toString()));
|
|
40
40
|
return commandsToSend.map(param => {
|
|
41
41
|
let commandJson = Message$ReventlessCore.encode(param[1], Spec.commandSchema);
|
|
42
42
|
return {
|
|
@@ -67,13 +67,13 @@ function Make(Spec) {
|
|
|
67
67
|
let e = Primitive_exceptions.internalToException(raw_e);
|
|
68
68
|
if (e.RE_EXN_ID === "JsExn") {
|
|
69
69
|
let errMsg = Stdlib_Option.getOr(Stdlib_JsExn.message(e._1), "unknown");
|
|
70
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError("CommandPublisher", undefined, `send error: couldn't publish ` + size.toString() + ` commands: ` + errMsg));
|
|
70
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError("CommandPublisher", undefined, undefined, `send error: couldn't publish ` + size.toString() + ` commands: ` + errMsg));
|
|
71
71
|
} else {
|
|
72
72
|
throw e;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
if (exit === 1) {
|
|
76
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, `send: finished SendAllInOneChunk: ` + size.toString()));
|
|
76
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, undefined, `send: finished SendAllInOneChunk: ` + size.toString()));
|
|
77
77
|
}
|
|
78
78
|
running.contents = undefined;
|
|
79
79
|
return;
|
|
@@ -88,7 +88,7 @@ function Make(Spec) {
|
|
|
88
88
|
let sizeStr = size$1.toString();
|
|
89
89
|
let bufferSizeStr = buffer.length.toString();
|
|
90
90
|
let chunkCountStr = chunkCount.contents.toString();
|
|
91
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, `send: bufferSize: ` + bufferSizeStr + `, chunk: ` + chunkCountStr + `, size: ` + sizeStr));
|
|
91
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, undefined, `send: bufferSize: ` + bufferSizeStr + `, chunk: ` + chunkCountStr + `, size: ` + sizeStr));
|
|
92
92
|
let commandsToSend$1 = buffer.slice(0, size$1);
|
|
93
93
|
buffer.splice(0, size$1);
|
|
94
94
|
let promise$1 = Config.publishCommands(Spec.name, toJsons(commandsToSend$1));
|
|
@@ -102,13 +102,13 @@ function Make(Spec) {
|
|
|
102
102
|
let e$1 = Primitive_exceptions.internalToException(raw_e$1);
|
|
103
103
|
if (e$1.RE_EXN_ID === "JsExn") {
|
|
104
104
|
let errorMessage = Stdlib_Option.getOr(Stdlib_JsExn.message(e$1._1), "unknown Error");
|
|
105
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError("CommandPublisher", undefined, `send error: couldn't publish chunk ` + chunkCountStr + ` (` + sizeStr + ` commands): ` + errorMessage));
|
|
105
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError("CommandPublisher", undefined, undefined, `send error: couldn't publish chunk ` + chunkCountStr + ` (` + sizeStr + ` commands): ` + errorMessage));
|
|
106
106
|
} else {
|
|
107
107
|
throw e$1;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
if (exit$1 === 1) {
|
|
111
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, `send: finished chunk ` + chunkCountStr + `: ` + sizeStr));
|
|
111
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, undefined, `send: finished chunk ` + chunkCountStr + `: ` + sizeStr));
|
|
112
112
|
}
|
|
113
113
|
return await send();
|
|
114
114
|
};
|
|
@@ -128,12 +128,12 @@ function Make(Spec) {
|
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
130
|
let clear = () => {
|
|
131
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, "clear"));
|
|
131
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, undefined, "clear"));
|
|
132
132
|
buffer.splice(0, buffer.length);
|
|
133
133
|
flush.contents = false;
|
|
134
134
|
};
|
|
135
135
|
let flush$1 = async () => {
|
|
136
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, "flush"));
|
|
136
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, undefined, "flush"));
|
|
137
137
|
flush.contents = true;
|
|
138
138
|
return await send();
|
|
139
139
|
};
|
|
@@ -153,29 +153,97 @@ install()
|
|
|
153
153
|
|
|
154
154
|
// ─── Structured log helpers ──────────────────────────────────────────────────
|
|
155
155
|
// Returns Effect.t<unit> — usable in Effect pipelines or with ->Effect.runSync.
|
|
156
|
+
// Run with ->Effect.runSync, a line is on a fiber of its own and loses what the
|
|
157
|
+
// invocation annotated (its correlationId, causationId, plugin): pass ~ids, the ids
|
|
158
|
+
// of the message the line is about, which ride on the log effect itself.
|
|
156
159
|
//
|
|
157
|
-
// ~comp / ~detail attach as Effect log annotations; install() reads them back.
|
|
160
|
+
// ~comp / ~detail / ~ids attach as Effect log annotations; install() reads them back.
|
|
158
161
|
// ~detail: structured JSON shown only in a JSON sink (expandable on click);
|
|
159
162
|
// the in-memory terminal output shows only the message line.
|
|
160
163
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
/** The ids of the message a line is about, and of the entity it is handled for. Given on the
|
|
165
|
+
log call, they are annotations of the log effect itself, so they reach the line also when it
|
|
166
|
+
runs on a fiber of its own (`->Effect.runSync`), and they win over the same fields the
|
|
167
|
+
invocation annotated: one invocation can carry messages of several flows. */
|
|
168
|
+
type ids = {
|
|
169
|
+
msgId?: string,
|
|
170
|
+
correlationId?: string,
|
|
171
|
+
causationId?: string,
|
|
172
|
+
entityId?: string,
|
|
173
|
+
entityType?: string,
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** The ids of a message, from its meta; the entity when the caller knows it. */
|
|
177
|
+
let idsOf = (~entityId=?, ~entityType=?, meta: Message.meta): ids => {
|
|
178
|
+
msgId: meta.msgId,
|
|
179
|
+
correlationId: meta.correlationId,
|
|
180
|
+
causationId: ?meta.causationId,
|
|
181
|
+
?entityId,
|
|
182
|
+
?entityType,
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The ids of the event a work item came from: an automation's or a translation's row. */
|
|
186
|
+
let idsOfSource = (source: Message.flowSource): ids => {
|
|
187
|
+
msgId: source.msgId,
|
|
188
|
+
correlationId: source.correlationId,
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** The ids of a message given as JSON, read from its `meta` without decoding the rest; none
|
|
192
|
+
when it has no meta. */
|
|
193
|
+
let idsOfJson = (json: JSON.t): option<ids> =>
|
|
194
|
+
switch json {
|
|
195
|
+
| JSON.Object(d) =>
|
|
196
|
+
switch d->Dict.get("meta") {
|
|
197
|
+
| Some(JSON.Object(m)) =>
|
|
198
|
+
let str = k =>
|
|
199
|
+
switch m->Dict.get(k) {
|
|
200
|
+
| Some(JSON.String(s)) if s != "" => Some(s)
|
|
201
|
+
| _ => None
|
|
202
|
+
}
|
|
203
|
+
Some({
|
|
204
|
+
msgId: ?str("msgId"),
|
|
205
|
+
correlationId: ?str("correlationId"),
|
|
206
|
+
causationId: ?str("causationId"),
|
|
207
|
+
})
|
|
208
|
+
| _ => None
|
|
209
|
+
}
|
|
210
|
+
| _ => None
|
|
167
211
|
}
|
|
168
|
-
|
|
169
|
-
|
|
212
|
+
|
|
213
|
+
// Attach comp/detail/ids as annotations on the log effect. detail is stringified
|
|
214
|
+
// so it rides through Effect's string-keyed annotation map; install() re-parses it.
|
|
215
|
+
let _annotate = (eff, ~comp=?, ~detail=?, ~ids: option<ids>=?) => {
|
|
216
|
+
let one = (eff, key, value) =>
|
|
217
|
+
switch value {
|
|
218
|
+
| Some(v) => eff->Effect.annotateLogs(key, v)
|
|
219
|
+
| None => eff
|
|
220
|
+
}
|
|
221
|
+
let eff = eff->one("comp", comp)->one("detail", detail->Option.map(d => d->JSON.stringify))
|
|
222
|
+
switch ids {
|
|
223
|
+
| Some(i) =>
|
|
224
|
+
eff
|
|
225
|
+
->one("msgId", i.msgId)
|
|
226
|
+
->one("correlationId", i.correlationId)
|
|
227
|
+
->one("causationId", i.causationId)
|
|
228
|
+
->one("entityId", i.entityId)
|
|
229
|
+
->one("entityType", i.entityType)
|
|
170
230
|
| None => eff
|
|
171
231
|
}
|
|
172
232
|
}
|
|
173
233
|
|
|
174
|
-
let logInfo = (~comp=?, ~detail=?, msg) =>
|
|
175
|
-
Effect.logInfo(msg)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
let
|
|
179
|
-
Effect.
|
|
180
|
-
|
|
181
|
-
|
|
234
|
+
let logInfo = (~comp=?, ~detail=?, ~ids=?, msg) =>
|
|
235
|
+
Effect.logInfo(msg)
|
|
236
|
+
->_annotate(~comp?, ~detail?, ~ids?)
|
|
237
|
+
->_withMinimumLogLevel(_effectMin(~comp?, ()))
|
|
238
|
+
let logWarn = (~comp=?, ~detail=?, ~ids=?, msg) =>
|
|
239
|
+
Effect.logWarning(msg)
|
|
240
|
+
->_annotate(~comp?, ~detail?, ~ids?)
|
|
241
|
+
->_withMinimumLogLevel(_effectMin(~comp?, ()))
|
|
242
|
+
let logError = (~comp=?, ~detail=?, ~ids=?, msg) =>
|
|
243
|
+
Effect.logError(msg)
|
|
244
|
+
->_annotate(~comp?, ~detail?, ~ids?)
|
|
245
|
+
->_withMinimumLogLevel(_effectMin(~comp?, ()))
|
|
246
|
+
let logDebug = (~comp=?, ~detail=?, ~ids=?, msg) =>
|
|
247
|
+
Effect.logDebug(msg)
|
|
248
|
+
->_annotate(~comp?, ~detail?, ~ids?)
|
|
249
|
+
->_withMinimumLogLevel(_effectMin(~comp?, ()))
|