diff --git a/src/NATS.Client.Core/NatsInstrumentationOptions.cs b/src/NATS.Client.Core/NatsInstrumentationOptions.cs index 2ec442b4c..85e4c0867 100644 --- a/src/NATS.Client.Core/NatsInstrumentationOptions.cs +++ b/src/NATS.Client.Core/NatsInstrumentationOptions.cs @@ -7,6 +7,13 @@ namespace NATS.Client.Core; /// public sealed class NatsInstrumentationOptions { + // The shared Default instance is configured at startup but its callbacks are read on the + // publish/subscribe path from other threads. Backing fields are volatile so a configuration + // change made after traffic has started is observed by those readers. + private volatile Func? _filter; + private volatile Action? _enrich; + private volatile Func? _spanDestinationNameFormatter; + public static NatsInstrumentationOptions Default { get; } = new(); /// @@ -17,12 +24,20 @@ public sealed class NatsInstrumentationOptions /// - If filter returns `true`, the request is collected. /// - If filter returns `false` or throws an exception the request is NOT collected. /// - public Func? Filter { get; set; } + public Func? Filter + { + get => _filter; + set => _filter = value; + } /// /// Gets or sets an action to enrich an Activity. /// - public Action? Enrich { get; set; } + public Action? Enrich + { + get => _enrich; + set => _enrich = value; + } /// /// Gets or sets a function that formats the destination name used in span names. @@ -30,5 +45,9 @@ public sealed class NatsInstrumentationOptions /// /// The input is the raw NATS subject. This only changes activity names, not telemetry tags. /// - public Func? SpanDestinationNameFormatter { get; set; } + public Func? SpanDestinationNameFormatter + { + get => _spanDestinationNameFormatter; + set => _spanDestinationNameFormatter = value; + } }