c# - 为什么 TrackValue 支持 10 个维度值而 GetMetric 只支持 4 个维度名称?

标签 c# .net-core azure-application-insights

在 Microsoft.ApplicationInsights 命名空间中,Metric 类包含最多支持 10 个维度值的 TrackValue 方法,但 TelemetryClient 类具有最多支持 4 个维度名称的 GetMetric 方法。

我的应用程序想要跟踪一个指标的 6 个维度值,但 GetMetric 方法仅支持 4 个维度名称。在我的场景中,第 5 维和第 6 维名称是什么?

我编写了一个小型 .Net Core 应用程序,将指标发送到 ApplicationInsights。当 GetMetric 调用中的维度名称数量与 TrackValue 调用中的维度值数量匹配时,TrackValue 调用成功。但是,当维度名称的数量与维度值的数量不匹配时,TrackValue 方法会抛出 System.ArgumentException 并显示一条消息“尝试通过指定 6 个维度来获取指标系列,但该指标有 4 个维度。 ”

TelemetryClient tc = new TelemetryClient();
tc.InstrumentationKey = "AppInsight Instrumentation Key";

var itemMetric = tc.GetMetric("Item", "Amount", "Source", "Locale", "PaymentType");
itemMetric.TrackValue(1.0d, "25", "web", "en-US", "CC", "USD", "US");

对 TrackValue 的调用会引发代码上方详述的 System.ArgumentException。

有没有办法为指标指定 4 个以上的维度名称,以便 TrackValue 调用成功?

最佳答案

您可以利用 MetricIdentifierGetMetric()具有 4+ 维的方式如下:

MetricIdentifier id = new MetricIdentifier("namespace", "name", "dim1", "dim2", "dim3", "dim4", "dim5");
Metric myMetric = client.GetMetric(id);

现有的重载只是用有限的维度覆盖最流行的情况的便捷方法。

关于c# - 为什么 TrackValue 支持 10 个维度值而 GetMetric 只支持 4 个维度名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55634634/

相关文章:

c# - c# Windows 服务中的数据库查询 - 执行无提示地失败

c# - boolean/boolean 值、字符串/字符串等之间的区别

c# - 更改单个 ASP.NET Core Controller 的 JSON 序列化设置

.net-core - 使用appsettings.json配置Kestrel监听端口Dotnet Core 2预览2

azure - 使用 VSTS 的 ASP.NET Core Web API 的 CI/CD

.net - Azure应用程序洞察请求响应统计与客户端的实际页面响应时间

azure - 如何在azure中监控容器应用指标

C# StructLayout/FieldOffset 和数组中的索引

azure - Azure 应用程序网关和 Azure Application Insights 之间的关联

c# - 为#C gRPC 使用具有通用名称的 TLS 凭据