public void AdditionalLabels_AppliesUserAgent() { HttpExporterTestDataProvider.SetupHttpContext(_context, TestStatusCode, TestMethod, TestAction, TestController, TestUserAgent); var middleware = new HttpRequestCountMiddleware(_next, new HttpRequestCountOptions { Registry = _registry, AdditionalLabels = new Dictionary <string, Func <HttpContext, string> > { { UserAgentLabel, HttpExporterTestDataProvider.GetUserAgent } } }); var child = (ChildBase)middleware.CreateChild(_context); var expectedLabels = HttpRequestLabelNames.All.Concat(new[] { UserAgentLabel }).ToArray(); CollectionAssert.AreEquivalent(expectedLabels, child.Labels.Names); CollectionAssert.AreEquivalent(new[] { TestStatusCode.ToString(), TestMethod, TestAction, TestController, TestUserAgent }, child.Labels.Values); }
public void CustomMetric_WithExtendedLabels_AppliesExtendedLabels() { // Route parameters tracked: // foo = 123 // bar = (missing) // method = excellent // remapped to route_method HttpExporterTestDataProvider.SetupHttpContext(_context, TestStatusCode, TestMethod, TestAction, TestController, routeParameters: new[]
public void CustomMetric_WithNoLabels_AppliesNoLabels() { HttpExporterTestDataProvider.SetupHttpContext(_context, TestStatusCode, TestMethod, TestAction, TestController); var middleware = new HttpRequestCountMiddleware(_next, new HttpRequestCountOptions { Counter = _metrics.CreateCounter("xxx", "") }); var child = (ChildBase)middleware.CreateChild(_context); Assert.AreEqual(0, child.Labels.Count); }
public void CustomMetric_WithStandardLabels_AppliesStandardLabels() { HttpExporterTestDataProvider.SetupHttpContext(_context, TestStatusCode, TestMethod, TestAction, TestController); var middleware = new HttpRequestCountMiddleware(_next, new HttpRequestCountOptions { Counter = _metrics.CreateCounter("xxx", "", HttpRequestLabelNames.All) }); var child = (ChildBase)middleware.CreateChild(_context); CollectionAssert.AreEquivalent(HttpRequestLabelNames.All, child.Labels.Names); CollectionAssert.AreEquivalent(new[] { TestStatusCode.ToString(), TestMethod, TestAction, TestController }, child.Labels.Values); }