Store the TracerProvider in a thread_local VersionedValue

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Fixed
    • Priority: Major - P3
    • 9.1.0-rc0, 9.0.0-rc1
    • Affects Version/s: None
    • Component/s: None
    • None
    • Networking & Observability
    • Fully Compatible
    • v9.0
    • N&O 2026-07-20
    • 200
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      This fixes an issue on shutdown where threads could copying the shared_ptr\<TracerProvider> at the same time it is being set to `nullptr`, leading to a data race and invalid access (see the test in src/mongo/otel/traces/tracer_provider_service_test.cpp). Using a thread_local VersionedValue should be very efficient for callers of this code (e.g. starting spans).

      While the `thread_local` imposes some constraints on how the `TracerProviderService` can be used, in practice we are only calling it from `span.cpp` so it is easy to ensure the constraints are met.

            Assignee:
            Michael Nugent
            Reporter:
            Michael Nugent
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: