我们的ASP.NET MVC应用程序包含一些URI路径参数,例如:
在Application Insights中,上面的URI变为操作名称
GET /api/query/14hes1017ceimgS2ESsIec
我们不希望这样的数百万个独特的操作;它只是一种为所有人提供服务的代码方法(见下文)。我们想在像
这样的操作名称下滚动它们GET /api/query/{path}
以下是代码方法 - 我认为App Insights可以检测到URI包含查询参数......但它没有。
[Route("api/query/{hash}")]
public HttpResponseMessage Get(string hash)
{
...
答案 0 :(得分:5)
Application Insights没有检测到您的Operation Name的后缀是参数的原因是因为SDK没有查看您的代码,并且出于所有实际目的,这是一个有效的URI。
获得您想要的两个选项:
ITelemetryProcessor
(可以找到详细说明here),并自行从操作名称中删除后缀哈希答案 1 :(得分:2)
我用这个硬编码OperationNameMunger
(使用these docs获取灵感)攻击它。
我在ApplicationInsights.config
之后直接将其连接到OperationNameTelemetryInitializer
。
using System.Text.RegularExpressions;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
namespace My.Namespace
{
public class OperationNameMunger : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
var existingOpName = telemetry.Context?.Operation?.Name;
if (existingOpName == null)
return;
const string matchesInterestingOps = "^([A-Z]+ /api/query/)[^ ]+$";
var match = Regex.Match(existingOpName, matchesInterestingOps);
if (match.Success)
{
telemetry.Context.Operation.Name = match.Groups[1].Value + "{hash}";
}
}
}
}
答案 2 :(得分:0)