Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/NATS.Client.Core/NatsInstrumentationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ namespace NATS.Client.Core;
/// </summary>
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<NatsInstrumentationContext, bool>? _filter;
private volatile Action<Activity, NatsInstrumentationContext>? _enrich;
private volatile Func<string, string>? _spanDestinationNameFormatter;

public static NatsInstrumentationOptions Default { get; } = new();

/// <summary>
Expand All @@ -17,18 +24,30 @@ 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.
/// </remarks>
public Func<NatsInstrumentationContext, bool>? Filter { get; set; }
public Func<NatsInstrumentationContext, bool>? Filter
{
get => _filter;
set => _filter = value;
}

/// <summary>
/// Gets or sets an action to enrich an Activity.
/// </summary>
public Action<Activity, NatsInstrumentationContext>? Enrich { get; set; }
public Action<Activity, NatsInstrumentationContext>? Enrich
{
get => _enrich;
set => _enrich = value;
}

/// <summary>
/// Gets or sets a function that formats the destination name used in span names.
/// </summary>
/// <remarks>
/// The input is the raw NATS subject. This only changes activity names, not telemetry tags.
/// </remarks>
public Func<string, string>? SpanDestinationNameFormatter { get; set; }
public Func<string, string>? SpanDestinationNameFormatter
{
get => _spanDestinationNameFormatter;
set => _spanDestinationNameFormatter = value;
}
}
Loading