-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
6 changed files
with
63 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Prometheus.Client.HttpRequestDurations/Tools/HttpContextExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Http; | ||
#if HasRoutes | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Routing; | ||
using Microsoft.AspNetCore.Routing; | ||
#endif | ||
|
||
namespace Prometheus.Client.HttpRequestDurations.Tools | ||
{ | ||
internal static class HttpContextExtensions | ||
{ | ||
#if HasRoutes | ||
public static string GetRouteName(this HttpContext httpContext) | ||
{ | ||
if (httpContext == null) | ||
throw new ArgumentNullException(nameof(httpContext)); | ||
|
||
var endpoint = httpContext.GetEndpoint(); | ||
|
||
var result = endpoint?.Metadata.GetMetadata<RouteNameMetadata>()?.RouteName; | ||
|
||
if (string.IsNullOrEmpty(result)) | ||
{ | ||
var routeAttribute = endpoint?.Metadata.GetMetadata<RouteAttribute>(); | ||
var methodAttribute = endpoint?.Metadata.GetMetadata<HttpMethodAttribute>(); | ||
|
||
result = $"{routeAttribute?.Template}{methodAttribute?.Template}"; | ||
} | ||
|
||
return result; | ||
} | ||
#endif | ||
} | ||
} |
5 changes: 2 additions & 3 deletions
5
src/Prometheus.Client.HttpRequestDurations/Tools/NormalizePath.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters