Skip to content

Commit e79daff

Browse files
committed
refactor(telemetry): standardize meter names and descriptions
1 parent 0478999 commit e79daff

File tree

11 files changed

+61
-71
lines changed

11 files changed

+61
-71
lines changed

src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore;
1414
public class HttpUserAgentParserAccessor(IHttpUserAgentParserProvider httpUserAgentParser)
1515
: IHttpUserAgentParserAccessor
1616
{
17-
/// <summary>
18-
/// The name of the Meter used for metrics.
19-
/// </summary>
20-
public const string MeterName = "MyCSharp.HttpUserAgentParser.AspNetCore";
21-
2217
private readonly IHttpUserAgentParserProvider _httpUserAgentParser = httpUserAgentParser;
2318

2419
/// <summary>

src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal static class HttpUserAgentParserAspNetCoreMeters
2020
/// <summary>
2121
/// Name of the meter used to publish AspNetCore User-Agent metrics.
2222
/// </summary>
23-
public const string MeterName = HttpUserAgentParserAccessor.MeterName;
23+
public const string MeterName = "mycsharp.http_user_agent_parser.aspnetcore";
2424

2525
/// <summary>
2626
/// Indicates whether the meter and its instruments have been initialized.

src/HttpUserAgentParser.AspNetCore/readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ services
5858

5959
EventSource: `MyCSharp.HttpUserAgentParser.AspNetCore` (constant: `HttpUserAgentParserAspNetCoreEventSource.EventSourceName`)
6060

61-
- `useragent-present` (incrementing)
62-
- `useragent-missing` (incrementing)
61+
- `user_agent.present` (incrementing)
62+
- `user_agent.missing` (incrementing)
6363

6464
### Monitor with dotnet-counters
6565

@@ -83,8 +83,8 @@ services
8383

8484
Meter: `MyCSharp.HttpUserAgentParser.AspNetCore` (constant: `HttpUserAgentParserAspNetCoreMeters.MeterName`)
8585

86-
- `useragent-present` (counter)
87-
- `useragent-missing` (counter)
86+
- `user_agent.present` (counter)
87+
- `user_agent.missing` (counter)
8888

8989
## Export to OpenTelemetry / Application Insights
9090

src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class HttpUserAgentParserMemoryCachedProvider(
1818
/// <summary>
1919
/// The name of the Meter used for metrics.
2020
/// </summary>
21-
public const string MeterName = "MyCSharp.HttpUserAgentParser.MemoryCache";
21+
public const string MeterName = "mycsharp.http_user_agent_parser.memorycache";
2222

2323
private readonly Microsoft.Extensions.Caching.Memory.MemoryCache _memoryCache = new(options.CacheOptions);
2424
private readonly HttpUserAgentParserMemoryCachedProviderOptions _options = options;

src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ public static void Enable(Meter? meter = null)
3535
s_cacheHit = s_meter.CreateCounter<long>(
3636
name: "cache.hit",
3737
unit: "{call}",
38-
description: "MemoryCache cache hit");
38+
description: "Cache hit");
3939

4040
s_cacheMiss = s_meter.CreateCounter<long>(
4141
name: "cache.miss",
4242
unit: "{call}",
43-
description: "MemoryCache cache miss");
43+
description: "Cache miss");
4444

4545
s_cacheSize = s_meter.CreateObservableGauge<long>(
4646
name: "cache.size",
4747
observeValue: static () => HttpUserAgentParserMemoryCacheTelemetryState.CacheSize,
4848
unit: "{entry}",
49-
description: "MemoryCache cache size");
49+
description: "Cache size");
5050
}
5151

5252
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/HttpUserAgentParser.MemoryCache/readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ services
6868

6969
EventSource: `MyCSharp.HttpUserAgentParser.MemoryCache` (constant: `HttpUserAgentParserMemoryCacheEventSource.EventSourceName`)
7070

71-
- `cache-hit` (incrementing)
72-
- `cache-miss` (incrementing)
73-
- `cache-size` (polling)
71+
- `user_agent_parser.cache.hit` (incrementing)
72+
- `user_agent_parser.cache.miss` (incrementing)
73+
- `user_agent_parser.cache.size` (polling)
7474

7575
### Monitor with dotnet-counters
7676

@@ -103,9 +103,9 @@ services
103103

104104
Meter: `MyCSharp.HttpUserAgentParser.MemoryCache` (constant: `HttpUserAgentParserMemoryCacheMeters.MeterName`)
105105

106-
- `cache-hit` (counter)
107-
- `cache-miss` (counter)
108-
- `cache-size` (observable gauge)
106+
- `user_agent_parser.cache.hit` (counter)
107+
- `user_agent_parser.cache.miss` (counter)
108+
- `user_agent_parser.cache.size` (observable gauge)
109109

110110
## Export to OpenTelemetry / Application Insights
111111

src/HttpUserAgentParser/HttpUserAgentParser.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ namespace MyCSharp.HttpUserAgentParser;
1616
/// </summary>
1717
public static class HttpUserAgentParser
1818
{
19-
/// <summary>
20-
/// The name of the Meter used for metrics.
21-
/// </summary>
22-
public const string MeterName = "MyCSharp.HttpUserAgentParser";
23-
2419
/// <summary>
2520
/// Parses given <param name="userAgent">user agent</param>
2621
/// </summary>

src/HttpUserAgentParser/Telemetry/HttpUserAgentParserEventSource.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public sealed class HttpUserAgentParserEventSource : EventSource
3030
private readonly IncrementingEventCounter _parseRequests;
3131
private readonly EventCounter? _parseDurationSeconds;
3232

33-
private readonly IncrementingEventCounter _concurrentCacheHit;
34-
private readonly IncrementingEventCounter _concurrentCacheMiss;
35-
private readonly PollingCounter _concurrentCacheSize;
33+
private readonly IncrementingEventCounter _cacheHit;
34+
private readonly IncrementingEventCounter _cacheMiss;
35+
private readonly PollingCounter _cacheSize;
3636

3737
/// <summary>
3838
/// Initializes all EventCounters and polling counters used by this EventSource.
@@ -53,24 +53,24 @@ private HttpUserAgentParserEventSource()
5353
};
5454

5555
// Providers (cache)
56-
_concurrentCacheHit = new IncrementingEventCounter("cache-concurrentdictionary-hit", this)
56+
_cacheHit = new IncrementingEventCounter("cache-hit", this)
5757
{
58-
DisplayName = "ConcurrentDictionary cache hit",
58+
DisplayName = "Cache hit",
5959
DisplayUnits = "calls",
6060
};
6161

62-
_concurrentCacheMiss = new IncrementingEventCounter("cache-concurrentdictionary-miss", this)
62+
_cacheMiss = new IncrementingEventCounter("cache-miss", this)
6363
{
64-
DisplayName = "ConcurrentDictionary cache miss",
64+
DisplayName = "Cache miss",
6565
DisplayUnits = "calls",
6666
};
6767

68-
_concurrentCacheSize = new PollingCounter(
69-
"cache-concurrentdictionary-size",
68+
_cacheSize = new PollingCounter(
69+
"cache-size",
7070
this,
7171
static () => HttpUserAgentParserTelemetryState.ConcurrentCacheSize)
7272
{
73-
DisplayName = "ConcurrentDictionary cache size",
73+
DisplayName = "Cache size",
7474
DisplayUnits = "entries",
7575
};
7676
}
@@ -105,43 +105,43 @@ internal void ParseDuration(double seconds)
105105
}
106106

107107
/// <summary>
108-
/// Records a cache hit in the concurrent dictionary provider.
108+
/// Records a cache hit.
109109
/// </summary>
110110
[NonEvent]
111-
internal void ConcurrentCacheHit()
111+
internal void CacheHit()
112112
{
113113
if (!IsEnabled())
114114
{
115115
return;
116116
}
117117

118-
_concurrentCacheHit?.Increment();
118+
_cacheHit?.Increment();
119119
}
120120

121121
/// <summary>
122-
/// Records a cache miss in the concurrent dictionary provider.
122+
/// Records a cache miss.
123123
/// </summary>
124124
[NonEvent]
125-
internal void ConcurrentCacheMiss()
125+
internal void CacheMiss()
126126
{
127127
if (!IsEnabled())
128128
{
129129
return;
130130
}
131131

132-
_concurrentCacheMiss?.Increment();
132+
_cacheMiss?.Increment();
133133
}
134134

135135
/// <summary>
136-
/// Updates the concurrent cache size used by the polling counter.
136+
/// Updates the size used by the polling counter.
137137
/// </summary>
138138
/// <param name="size">Current number of entries in the cache.</param>
139139
/// <remarks>
140140
/// The size is updated even when telemetry is disabled so that the polling
141141
/// counter reports a correct value once a listener attaches.
142142
/// </remarks>
143143
[NonEvent]
144-
internal static void ConcurrentCacheSizeSet(int size) => HttpUserAgentParserTelemetryState.SetConcurrentCacheSize(size);
144+
internal static void CacheSizeSet(int size) => HttpUserAgentParserTelemetryState.SetConcurrentCacheSize(size);
145145

146146
/// <summary>
147147
/// Releases all EventCounter and PollingCounter resources used by this EventSource.
@@ -157,9 +157,9 @@ protected override void Dispose(bool disposing)
157157
_parseRequests?.Dispose();
158158
_parseDurationSeconds?.Dispose();
159159

160-
_concurrentCacheHit?.Dispose();
161-
_concurrentCacheMiss?.Dispose();
162-
_concurrentCacheSize?.Dispose();
160+
_cacheHit?.Dispose();
161+
_cacheMiss?.Dispose();
162+
_cacheSize?.Dispose();
163163
}
164164

165165
base.Dispose(disposing);

src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal static class HttpUserAgentParserMeters
2020
/// <summary>
2121
/// The meter name used for all instruments.
2222
/// </summary>
23-
public const string MeterName = HttpUserAgentParser.MeterName;
23+
public const string MeterName = "mycsharp.http_user_agent_parser";
2424

2525
private static int s_initialized;
2626

@@ -69,20 +69,20 @@ public static void Enable(Meter? meter = null)
6969
description: "Parse duration");
7070

7171
s_concurrentCacheHit = s_meter.CreateCounter<long>(
72-
name: "cache.concurrent_dictionary.hit",
72+
name: "cache.hit",
7373
unit: "{call}",
74-
description: "ConcurrentDictionary cache hit");
74+
description: "Cache hit");
7575

7676
s_concurrentCacheMiss = s_meter.CreateCounter<long>(
77-
name: "cache.concurrent_dictionary.miss",
77+
name: "cache.miss",
7878
unit: "{call}",
79-
description: "ConcurrentDictionary cache miss");
79+
description: "Cache miss");
8080

8181
s_concurrentCacheSize = s_meter.CreateObservableGauge<long>(
82-
name: "cache.concurrent_dictionary.size",
82+
name: "cache.size",
8383
observeValue: static () => HttpUserAgentParserTelemetryState.ConcurrentCacheSize,
8484
unit: "{entry}",
85-
description: "ConcurrentDictionary cache size");
85+
description: "Cache size");
8686
}
8787

8888
/// <summary>
@@ -98,16 +98,16 @@ public static void Enable(Meter? meter = null)
9898
public static void ParseDuration(double seconds) => s_parseDuration?.Record(seconds);
9999

100100
/// <summary>
101-
/// Emits a counter increment for a concurrent dictionary cache hit.
101+
/// Emits a counter increment for a cache hit.
102102
/// </summary>
103103
[MethodImpl(MethodImplOptions.AggressiveInlining)]
104-
public static void ConcurrentCacheHit() => s_concurrentCacheHit?.Add(1);
104+
public static void CacheHit() => s_concurrentCacheHit?.Add(1);
105105

106106
/// <summary>
107-
/// Emits a counter increment for a concurrent dictionary cache miss.
107+
/// Emits a counter increment for a cache miss.
108108
/// </summary>
109109
[MethodImpl(MethodImplOptions.AggressiveInlining)]
110-
public static void ConcurrentCacheMiss() => s_concurrentCacheMiss?.Add(1);
110+
public static void CacheMiss() => s_concurrentCacheMiss?.Add(1);
111111

112112
/// <summary>
113113
/// Resets static state to support isolated unit tests.

src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ public static void ConcurrentCacheHit()
117117
int flags = Volatile.Read(ref s_enabledFlags);
118118
if ((flags & EventCountersFlag) != 0)
119119
{
120-
HttpUserAgentParserEventSource.Log.ConcurrentCacheHit();
120+
HttpUserAgentParserEventSource.Log.CacheHit();
121121
}
122122

123123
if ((flags & MetersFlag) != 0)
124124
{
125-
HttpUserAgentParserMeters.ConcurrentCacheHit();
125+
HttpUserAgentParserMeters.CacheHit();
126126
}
127127
}
128128

@@ -135,12 +135,12 @@ public static void ConcurrentCacheMiss()
135135
int flags = Volatile.Read(ref s_enabledFlags);
136136
if ((flags & EventCountersFlag) != 0)
137137
{
138-
HttpUserAgentParserEventSource.Log.ConcurrentCacheMiss();
138+
HttpUserAgentParserEventSource.Log.CacheMiss();
139139
}
140140

141141
if ((flags & MetersFlag) != 0)
142142
{
143-
HttpUserAgentParserMeters.ConcurrentCacheMiss();
143+
HttpUserAgentParserMeters.CacheMiss();
144144
}
145145
}
146146

0 commit comments

Comments
 (0)