-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
Follow-up to the OpenTelemetry work in CSHARP-5935. Missed code review feedback on src/MongoDB.Driver/OperationContext.cs:
1. Naming mismatch
ForkWithOperationMetadata (line 141) should be renamed to WithOperationMetadata to match the established convention on this class:
- Fork() — independent copy with same state (e.g. CoreSession.Fork, ChannelHandle.Fork)
- WithX(...) — independent copy with one property changed (e.g. WithTimeout at line 200)
The new method is semantically the second — it returns a copy with metadata fields adjusted — so the Fork prefix is misleading and reuses a word that already has a specific meaning in this codebase.
2. Fork() drops the new metadata fields
Fork() (lines 135–139) does not copy OperationName, DatabaseName, CollectionName, or IsTracingEnabled, so it violates its "independent copy, same state" contract. WithTimeout (lines 214–221) correctly copies these four fields — Fork() should be updated to match.
No visible bug today because the three call sites only invoke Fork() on the tracing-disabled branch, where IsTracingEnabled on the result is false and metadata is never read. It is a latent bug: the invariant "Fork is only reached with empty metadata" is not enforced anywhere and will silently break if a new call site or a new reader of those fields is added.
Acceptance criteria
- ForkWithOperationMetadata renamed to WithOperationMetadata; all call sites and tests updated.
- Fork() copies OperationName, DatabaseName, CollectionName, IsTracingEnabled.
- Test in OperationContextTests verifying that Fork() preserves metadata.