Skip to content

Commit 7fe9227

Browse files
committed
Add ability to set a metrics prefix
1 parent 609ec17 commit 7fe9227

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Foundatio/Queues/QueueBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ protected QueueBase(TOptions options) : base(options?.TimeProvider, options?.Log
4141
{
4242
_options = options ?? throw new ArgumentNullException(nameof(options));
4343
_metricsPrefix = $"foundatio.{typeof(T).Name.ToLowerInvariant()}";
44+
if (!String.IsNullOrEmpty(options.MetricsPrefix))
45+
_metricsPrefix = $"{_metricsPrefix}.{options.MetricsPrefix}";
4446

4547
QueueId = options.Name + Guid.NewGuid().ToString("N").Substring(10);
4648

src/Foundatio/Queues/SharedQueueOptions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public class SharedQueueOptions<T> : SharedOptions where T : class
99
public int Retries { get; set; } = 2;
1010
public TimeSpan WorkItemTimeout { get; set; } = TimeSpan.FromMinutes(5);
1111
public ICollection<IQueueBehavior<T>> Behaviors { get; set; } = new List<IQueueBehavior<T>>();
12+
13+
/// <summary>
14+
/// Allows you to set a prefix on queue metrics. This allows you to have unique metrics for keyed queues (e.g., priority queues).
15+
/// </summary>
16+
public string MetricsPrefix { get; set; }
1217
}
1318

1419
public class SharedQueueOptionsBuilder<T, TOptions, TBuilder> : SharedOptionsBuilder<TOptions, TBuilder>
@@ -61,4 +66,14 @@ public TBuilder AddBehavior(IQueueBehavior<T> behavior)
6166

6267
return (TBuilder)this;
6368
}
69+
70+
/// <summary>
71+
/// Allows you to set a prefix on queue metrics. This allows you to have unique metrics for keyed queues (e.g., priority queues).
72+
/// </summary>
73+
public TBuilder MetricsPrefix(string prefix)
74+
{
75+
if (!String.IsNullOrEmpty(prefix))
76+
Target.MetricsPrefix = prefix;
77+
return (TBuilder)this;
78+
}
6479
}

0 commit comments

Comments
 (0)