Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom properties in full documents for QuickPulse - up to 10 from 3, consistent selection #2341

Merged
merged 1 commit into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## VNext
- [Change Self-Diagnostics to include datetimestamp in filename](https://github.com/microsoft/ApplicationInsights-dotnet/pull/2325)
- [AAD: Add logging to AuthenticationTransmissionPolicy](https://github.com/microsoft/ApplicationInsights-dotnet/pull/2319)
- [QuickPulse: Bump the number of custom dimensions included into full documents for QuickPulse from 3 to 10, make the selection consistent]

## Version 2.18.0-beta3
- [Enable the self diagnostics and fix a NullReferenceException bug](https://github.com/microsoft/ApplicationInsights-dotnet/pull/2302)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,11 @@ public void QuickPulseTelemetryProcessorCollectsFullTelemetryItemsAndDistributes
Success = false,
ResponseCode = "500",
Duration = TimeSpan.FromSeconds(1),
Properties = { { "Prop1", "Val1" }, { "Prop2", "Val2" }, { "Prop3", "Val3" }, { "Prop4", "Val4" } },
Properties =
{
{"Prop1", "Val1"}, {"Prop5", "Val5"}, {"Prop10", "Val10"}, {"Prop8", "Val8"}, {"Prop3", "Val3"}, {"Prop7", "Val7"}, {"Prop6", "Val6"}, {"Prop9", "Val9"},
{"Prop4", "Val4"}, {"Prop11", "Val11"}, {"Prop2", "Val2"}
},
Context = { InstrumentationKey = instrumentationKey }
};

Expand All @@ -591,27 +595,44 @@ public void QuickPulseTelemetryProcessorCollectsFullTelemetryItemsAndDistributes
Name = Guid.NewGuid().ToString(),
Success = false,
Duration = TimeSpan.FromSeconds(1),
Properties = { { "Prop1", "Val1" }, { "Prop2", "Val2" }, { "Prop3", "Val3" }, { "Prop4", "Val4" }, { "ErrorMessage", "EMValue" } },
Properties =
{
{"Prop1", "Val1"}, {"Prop5", "Val5"}, {"Prop10", "Val10"}, {"Prop8", "Val8"}, {"ErrorMessage", "EMValue"}, {"Prop3", "Val3"}, {"Prop7", "Val7"},
{"Prop6", "Val6"}, {"Prop9", "Val9"},
{"Prop4", "Val4"}, {"Prop11", "Val11"}, {"Prop2", "Val2"}
},
Context = { InstrumentationKey = instrumentationKey }
};

var exception = new ExceptionTelemetry(new ArgumentNullException())
{
Properties = { { "Prop1", "Val1" }, { "Prop2", "Val2" }, { "Prop3", "Val3" }, { "Prop4", "Val4" } },
Properties =
{
{"Prop1", "Val1"}, {"Prop5", "Val5"}, {"Prop10", "Val10"}, {"Prop8", "Val8"}, {"Prop3", "Val3"}, {"Prop7", "Val7"}, {"Prop6", "Val6"}, {"Prop9", "Val9"},
{"Prop4", "Val4"}, {"Prop11", "Val11"}, {"Prop2", "Val2"}
},
Context = { InstrumentationKey = instrumentationKey }
};

var @event = new EventTelemetry()
{
Name = "Event1",
Properties = { { "Prop1", "Val1" }, { "Prop2", "Val2" }, { "Prop3", "Val3" }, { "Prop4", "Val4" } },
Properties =
{
{"Prop1", "Val1"}, {"Prop5", "Val5"}, {"Prop10", "Val10"}, {"Prop8", "Val8"}, {"Prop3", "Val3"}, {"Prop7", "Val7"}, {"Prop6", "Val6"}, {"Prop9", "Val9"},
{"Prop4", "Val4"}, {"Prop11", "Val11"}, {"Prop2", "Val2"}
},
Context = { InstrumentationKey = instrumentationKey }
};

var trace = new TraceTelemetry()
{
Message = "Trace1",
Properties = { { "Prop1", "Val1" }, { "Prop2", "Val2" }, { "Prop3", "Val3" }, { "Prop4", "Val4" } },
Properties =
{
{"Prop1", "Val1"}, {"Prop5", "Val5"}, {"Prop10", "Val10"}, {"Prop8", "Val8"}, {"Prop3", "Val3"}, {"Prop7", "Val7"}, {"Prop6", "Val6"}, {"Prop9", "Val9"},
{"Prop4", "Val4"}, {"Prop11", "Val11"}, {"Prop2", "Val2"}
},
Context = { InstrumentationKey = instrumentationKey }
};

Expand All @@ -624,19 +645,28 @@ public void QuickPulseTelemetryProcessorCollectsFullTelemetryItemsAndDistributes
// ASSERT
var collectedTelemetry = accumulatorManager.CurrentDataAccumulator.TelemetryDocuments.ToArray().Reverse().ToArray();

var expectedProperties =
new Dictionary<string, string>()
{
{"Prop1", "Val1"}, {"Prop10", "Val10"}, {"Prop11", "Val11"}, {"Prop2", "Val2"}, {"Prop3", "Val3"}, {"Prop4", "Val4"}, {"Prop5", "Val5"}, {"Prop6", "Val6"},
{"Prop7", "Val7"}, {"Prop8", "Val8"}
}.ToArray();

Assert.IsFalse(accumulatorManager.CurrentDataAccumulator.GlobalDocumentQuotaReached);

Assert.AreEqual(5, accumulatorManager.CurrentDataAccumulator.TelemetryDocuments.Count);

Assert.AreEqual(TelemetryDocumentType.Request, Enum.Parse(typeof(TelemetryDocumentType), collectedTelemetry[0].DocumentType));
Assert.AreEqual(request.Name, ((RequestTelemetryDocument)collectedTelemetry[0]).Name);
Assert.AreEqual(3, collectedTelemetry[0].Properties.Length);
Assert.AreEqual(10, collectedTelemetry[0].Properties.Length);
CollectionAssert.AreEqual(expectedProperties, collectedTelemetry[0].Properties);
Assert.AreEqual("StreamRequestsAndDependenciesAndExceptions", collectedTelemetry[0].DocumentStreamIds.Single());
Assert.IsTrue(collectedTelemetry[0].Properties.ToList().TrueForAll(pair => pair.Key.Contains("Prop") && pair.Value.Contains("Val")));

Assert.AreEqual(TelemetryDocumentType.RemoteDependency, Enum.Parse(typeof(TelemetryDocumentType), collectedTelemetry[1].DocumentType));
Assert.AreEqual(dependency.Name, ((DependencyTelemetryDocument)collectedTelemetry[1]).Name);
Assert.AreEqual(3 + 1, collectedTelemetry[1].Properties.Length);
Assert.AreEqual(10 + 1, collectedTelemetry[1].Properties.Length);
CollectionAssert.AreEqual(expectedProperties.Concat(new[] {new KeyValuePair<string, string>("ErrorMessage", "EMValue")}).ToArray(), collectedTelemetry[1].Properties);
Assert.AreEqual("StreamRequestsAndDependenciesAndExceptions", collectedTelemetry[1].DocumentStreamIds.Single());
Assert.IsTrue(
collectedTelemetry[1].Properties.ToList()
Expand All @@ -645,21 +675,24 @@ public void QuickPulseTelemetryProcessorCollectsFullTelemetryItemsAndDistributes

Assert.AreEqual(TelemetryDocumentType.Exception, Enum.Parse(typeof(TelemetryDocumentType), collectedTelemetry[2].DocumentType));
Assert.AreEqual(exception.Exception.ToString(), ((ExceptionTelemetryDocument)collectedTelemetry[2]).Exception);
Assert.AreEqual(3, collectedTelemetry[2].Properties.Length);
Assert.AreEqual(10, collectedTelemetry[2].Properties.Length);
CollectionAssert.AreEqual(expectedProperties, collectedTelemetry[2].Properties);
Assert.AreEqual(2, collectedTelemetry[2].DocumentStreamIds.Length);
Assert.AreEqual("StreamRequestsAndDependenciesAndExceptions", collectedTelemetry[2].DocumentStreamIds.First());
Assert.AreEqual("StreamExceptionsEventsTraces", collectedTelemetry[2].DocumentStreamIds.Last());
Assert.IsTrue(collectedTelemetry[2].Properties.ToList().TrueForAll(pair => (pair.Key.Contains("Prop") && pair.Value.Contains("Val"))));

Assert.AreEqual(TelemetryDocumentType.Event, Enum.Parse(typeof(TelemetryDocumentType), collectedTelemetry[3].DocumentType));
Assert.AreEqual(@event.Name, ((EventTelemetryDocument)collectedTelemetry[3]).Name);
Assert.AreEqual(3, collectedTelemetry[3].Properties.Length);
Assert.AreEqual(10, collectedTelemetry[3].Properties.Length);
CollectionAssert.AreEqual(expectedProperties, collectedTelemetry[3].Properties);
Assert.AreEqual("StreamExceptionsEventsTraces", collectedTelemetry[3].DocumentStreamIds.Single());
Assert.IsTrue(collectedTelemetry[3].Properties.ToList().TrueForAll(pair => (pair.Key.Contains("Prop") && pair.Value.Contains("Val"))));

Assert.AreEqual(TelemetryDocumentType.Trace, Enum.Parse(typeof(TelemetryDocumentType), collectedTelemetry[4].DocumentType));
Assert.AreEqual(trace.Message, ((TraceTelemetryDocument)collectedTelemetry[4]).Message);
Assert.AreEqual(3, collectedTelemetry[4].Properties.Length);
Assert.AreEqual(10, collectedTelemetry[4].Properties.Length);
CollectionAssert.AreEqual(expectedProperties, collectedTelemetry[4].Properties);
Assert.AreEqual("StreamExceptionsEventsTraces", collectedTelemetry[4].DocumentStreamIds.Single());
Assert.IsTrue(collectedTelemetry[4].Properties.ToList().TrueForAll(pair => (pair.Key.Contains("Prop") && pair.Value.Contains("Val"))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class QuickPulseTelemetryProcessor : ITelemetryProcessor, ITelemetryModul

private const int MaxFieldLength = 32768;

private const int MaxPropertyCount = 3;
private const int MaxPropertyCount = 10;

private const string SpecialDependencyPropertyName = "ErrorMessage";

Expand Down Expand Up @@ -376,7 +376,7 @@ private static KeyValuePair<string, string>[] GetProperties(ISupportProperties t
properties = new Dictionary<string, string>(MaxPropertyCount + 1);

foreach (var prop in
telemetry.Properties.Where(p => !string.Equals(p.Key, specialPropertyName, StringComparison.Ordinal)).Take(MaxPropertyCount))
telemetry.Properties.Where(p => !string.Equals(p.Key, specialPropertyName, StringComparison.Ordinal)).OrderBy(p => p.Key, StringComparer.Ordinal).Take(MaxPropertyCount))
{
string truncatedKey = TruncateValue(prop.Key);

Expand Down