From eb7699863cf0d14b3c8fb3362c51bad17112b2d9 Mon Sep 17 00:00:00 2001
From: Patrick Doyle
Date: Wed, 19 Jun 2024 22:34:40 -0400
Subject: [PATCH] Get diagnostic context as early as possible.
It doesn't actually matter yet, but the idea is to pull OTel context
from bosk diagnostic context to enable propagation, and in that case, we
want as much as possible of this processing to happen with that OTel
context in place.
---
.../drivers/mongo/SequoiaFormatDriver.java | 22 +++++++++----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/bosk-mongo/src/main/java/io/vena/bosk/drivers/mongo/SequoiaFormatDriver.java b/bosk-mongo/src/main/java/io/vena/bosk/drivers/mongo/SequoiaFormatDriver.java
index cbb9133f..5fb2b339 100644
--- a/bosk-mongo/src/main/java/io/vena/bosk/drivers/mongo/SequoiaFormatDriver.java
+++ b/bosk-mongo/src/main/java/io/vena/bosk/drivers/mongo/SequoiaFormatDriver.java
@@ -207,21 +207,21 @@ public void onEvent(ChangeStreamDocument event) throws Unprocessab
// also REPLACE. That would imply that this case is impossible.
throw new UnprocessableEventException("Missing fullDocument", event.getOperationType());
}
- BsonInt64 revision = formatter.getRevisionFromFullDocument(fullDocument);
- BsonDocument state = fullDocument.getDocument(DocumentFields.state.name(), null);
- if (state == null) {
- throw new UnprocessableEventException("Missing state field", event.getOperationType());
- }
- R newRoot = formatter.document2object(state, rootRef);
- // Note that we do not check revisionToSkip here. We probably should... but this actually
- // saves us in MongoDriverResiliencyTest.documentReappears_recovers because when the doc
- // disappears, we don't null out revisionToSkip. TODO: Rethink what's the right way to handle this.
- LOGGER.debug("| Replace {}", rootRef);
MapValue diagnosticAttributes = formatter.eventDiagnosticAttributesFromFullDocument(fullDocument);
try (var __ = rootRef.diagnosticContext().withOnly(diagnosticAttributes)) {
+ BsonInt64 revision = formatter.getRevisionFromFullDocument(fullDocument);
+ BsonDocument state = fullDocument.getDocument(DocumentFields.state.name(), null);
+ if (state == null) {
+ throw new UnprocessableEventException("Missing state field", event.getOperationType());
+ }
+ R newRoot = formatter.document2object(state, rootRef);
+ // Note that we do not check revisionToSkip here. We probably should... but this actually
+ // saves us in MongoDriverResiliencyTest.documentReappears_recovers because when the doc
+ // disappears, we don't null out revisionToSkip. TODO: Rethink what's the right way to handle this.
+ LOGGER.debug("| Replace {}", rootRef);
downstream.submitReplacement(rootRef, newRoot);
+ flushLock.finishedRevision(revision);
}
- flushLock.finishedRevision(revision);
} break;
case UPDATE: {
UpdateDescription updateDescription = event.getUpdateDescription();