Make shared OpenTelemetry instrumentation options thread-visible#1207
Conversation
The Default instance is configured at startup but its callbacks are read on the publish/subscribe path from other threads. Back the properties with volatile fields so a configuration change made after traffic has started is observed by those readers instead of relying on incidental barriers.
|
Claude finished @mtmk's task in 1m 28s —— View job Code Review
The change is correct and well-targeted. A few observations: Memory model correctness
That is exactly what's needed for the "configure once at startup, read on many hot-path threads" pattern. The fix is sound on both x86 and ARM. Hot path reads are safe All three properties are read in
var previous = options.Filter; // volatile read
options.Filter = ctx => { ... }; // volatile writeThis is a read-modify-write that isn't atomic. If two threads call
No issues found. The fix is minimal, correct, and appropriately scoped. |
The shared NatsInstrumentationOptions.Default is configured once at startup, but its Filter, Enrich, and SpanDestinationNameFormatter callbacks are read on the publish/subscribe path from other threads. Back the properties with volatile fields so a configuration change applied after traffic has started is visible to those readers rather than depending on incidental memory barriers. No new test: this is a visibility guarantee and the existing configure round-trip test already covers get/set behavior.