为什么TrackValue支持10个维度值,但GetMetric仅支持4个维度名称?

时间:2019-04-11 14:13:56

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

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

我的应用程序希望跟踪一个度量标准的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。

是否可以为Metric指定4个以上的维名称,以便TrackValue调用成功?

1 个答案:

答案 0 :(得分:1)

您可以通过以下四种方式将MetricIdentifier应用于GetMetric()的4个以上维度:

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

现有的重载只是方便的方法,可以覆盖尺寸有限的大多数流行情况。