Rename ForkWithOperationMetadata to WithOperationMetadata and preserve metadata in OperationContext.Fork

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Dotnet Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • 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.

            Assignee:
            Adelin Mbida Owona
            Reporter:
            Adelin Mbida Owona
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: