在 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 调用成功?
最佳答案
您可以利用 MetricIdentifier
至 GetMetric()
具有 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/