28 lines
1.3 KiB
C#
28 lines
1.3 KiB
C#
using System.Diagnostics.Metrics;
|
|
using ItWorx.KnowledgeHub.Application.Operations;
|
|
|
|
namespace ItWorx.KnowledgeHub.IntegrationTests.Operations;
|
|
|
|
public sealed class PlatformMetricsTests
|
|
{
|
|
[Fact]
|
|
public void Metrics_reject_unbounded_operation_and_outcome_dimensions()
|
|
{
|
|
var observed = new List<KeyValuePair<string, object?>>();
|
|
using var listener = new MeterListener();
|
|
listener.InstrumentPublished = (instrument, current) =>
|
|
{
|
|
if (instrument.Meter.Name == "ItWorx.KnowledgeHub.Platform") current.EnableMeasurementEvents(instrument);
|
|
};
|
|
listener.SetMeasurementEventCallback<double>((_, _, tags, _) => observed.AddRange(tags.ToArray()));
|
|
listener.SetMeasurementEventCallback<long>((_, _, tags, _) => observed.AddRange(tags.ToArray()));
|
|
listener.Start();
|
|
using var metrics = new PlatformMetrics();
|
|
metrics.Record("private query and bearer token", "secret", 0.1, 3);
|
|
Assert.NotEmpty(observed);
|
|
Assert.All(observed, tag => Assert.Contains(tag.Key, new[] { "operation", "outcome" }));
|
|
Assert.DoesNotContain(observed, tag => tag.Value?.ToString()?.Contains("secret", StringComparison.Ordinal) == true);
|
|
Assert.Contains(observed, tag => tag.Value?.ToString() == "other");
|
|
}
|
|
}
|