Skip to content

Commit

Permalink
Get diagnostic context as early as possible.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
prdoyle committed Jun 20, 2024
1 parent 98d63a8 commit eb76998
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,21 @@ public void onEvent(ChangeStreamDocument<BsonDocument> 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<String> 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();
Expand Down

0 comments on commit eb76998

Please sign in to comment.