Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
abaranch committed Apr 28, 2016
2 parents 0110215 + 1a58675 commit a118ff2
Show file tree
Hide file tree
Showing 26 changed files with 169 additions and 639 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

This changelog will be used to generate documentation on [release notes page](http://azure.microsoft.com/en-us/documentation/articles/app-insights-release-notes-dotnet/).

## Version 2.1.0-beta4
- [Bug fix](https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/76)

## Version 2.1.0-beta3
- Support partial success (206) from the Application Insights backend. Before this change SDK may have lost data because some items of the batch were accepted and some items of the batch were asked to be retried (because of burst throttling or intermittent issues).
- Bug fixes
Expand Down Expand Up @@ -76,7 +79,7 @@ item is being filtered out.

## Version 1.2.3
- Bug fixes.
- Telemetry item will be serialized to Debug Ouput even when Instrumentaiton Key was not set.
- Telemetry item will be serialized to Debug Ouput even when Instrumentation Key was not set.

## Version 1.2
- First version shipped from github
Expand Down
2 changes: 1 addition & 1 deletion GlobalStaticVersion.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<SemanticVersionMajor>2</SemanticVersionMajor>
<SemanticVersionMinor>1</SemanticVersionMinor>
<SemanticVersionPatch>0</SemanticVersionPatch>
<PreReleaseMilestone>beta3</PreReleaseMilestone>
<PreReleaseMilestone>beta4</PreReleaseMilestone>
<!--
Date when Semantic Version was changed.
Update for every public release.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,241 +4,150 @@
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Linq;

using Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.VisualStudio.TestTools.UnitTesting;

/// <summary>
/// Tests the rich payload event source tracking.
/// </summary>
[TestClass]

public class RichPayloadEventSourceTest
{
/// <summary>
/// Tests tracking request telemetry.
/// </summary>
[TestMethod]
public void RichPayloadEventSourceRequestSentTest()
{
var client = new TelemetryClient();
client.InstrumentationKey = Guid.NewGuid().ToString();

using (var listener = new Microsoft.ApplicationInsights.TestFramework.TestEventListener())
{
listener.EnableEvents(RichPayloadEventSource.Log.EventSourceInternal, EventLevel.Verbose, RichPayloadEventSource.Keywords.Requests);

var item = new RequestTelemetry("TestRequest", DateTimeOffset.Now, TimeSpan.FromMilliseconds(10), "200", true);
item.Context.Properties.Add("property1", "value1");
item.Context.User.Id = "testUserId";
item.Context.Operation.Id = Guid.NewGuid().ToString();

client.TrackRequest(item);

var actualEvent = listener.Messages.FirstOrDefault();

Assert.IsNotNull(actualEvent);
Assert.AreEqual(client.InstrumentationKey, actualEvent.Payload[0]);

object[] tags = actualEvent.Payload[1] as object[];
Assert.AreEqual("ai.user.id", ((Dictionary<string, object>)(tags[0]))["Key"]);
Assert.AreEqual("testUserId", ((Dictionary<string, object>)(tags[0]))["Value"]);

Assert.AreEqual("ai.operation.id", ((Dictionary<string, object>)(tags[1]))["Key"]);
Assert.AreEqual(item.Context.Operation.Id, ((Dictionary<string, object>)(tags[1]))["Value"]);

Assert.IsNotNull(actualEvent.Payload[2]);
}
this.DoTracking(
RichPayloadEventSource.Keywords.Requests,
new RequestTelemetry("TestRequest", DateTimeOffset.Now, TimeSpan.FromMilliseconds(10), "200", true),
(client, item) => { client.TrackRequest((RequestTelemetry)item); });
}

/// <summary>
/// Tests tracking trace telemetry.
/// </summary>
[TestMethod]
public void RichPayloadEventSourceTraceSentTest()
{
var client = new TelemetryClient();
client.InstrumentationKey = Guid.NewGuid().ToString();

using (var listener = new Microsoft.ApplicationInsights.TestFramework.TestEventListener())
{
listener.EnableEvents(RichPayloadEventSource.Log.EventSourceInternal, EventLevel.Verbose, RichPayloadEventSource.Keywords.Traces);

var item = new TraceTelemetry("TestTrace", SeverityLevel.Information);
item.Context.Properties.Add("property1", "value1");
item.Context.User.Id = "testUserId";
item.Context.Operation.Id = Guid.NewGuid().ToString();

client.TrackTrace(item);

var actualEvent = listener.Messages.FirstOrDefault();

Assert.IsNotNull(actualEvent);
Assert.AreEqual(client.InstrumentationKey, actualEvent.Payload[0]);

object[] tags = actualEvent.Payload[1] as object[];
Assert.AreEqual("ai.user.id", ((Dictionary<string, object>)(tags[0]))["Key"]);
Assert.AreEqual("testUserId", ((Dictionary<string, object>)(tags[0]))["Value"]);

Assert.AreEqual("ai.operation.id", ((Dictionary<string, object>)(tags[1]))["Key"]);
Assert.AreEqual(item.Context.Operation.Id, ((Dictionary<string, object>)(tags[1]))["Value"]);

Assert.IsNotNull(actualEvent.Payload[2]);
}
this.DoTracking(
RichPayloadEventSource.Keywords.Traces,
new TraceTelemetry("TestTrace", SeverityLevel.Information),
(client, item) => { client.TrackTrace((TraceTelemetry)item); });
}

/// <summary>
/// Tests tracking event telemetry.
/// </summary>
[TestMethod]
public void RichPayloadEventSourceEventSentTest()
{
var client = new TelemetryClient();
client.InstrumentationKey = Guid.NewGuid().ToString();

using (var listener = new Microsoft.ApplicationInsights.TestFramework.TestEventListener())
{
listener.EnableEvents(RichPayloadEventSource.Log.EventSourceInternal, EventLevel.Verbose, RichPayloadEventSource.Keywords.Events);

var item = new EventTelemetry("TestEvent");
item.Context.Properties.Add("property1", "value1");
item.Context.User.Id = "testUserId";
item.Context.Operation.Id = Guid.NewGuid().ToString();

client.TrackEvent(item);

var actualEvent = listener.Messages.FirstOrDefault();

Assert.IsNotNull(actualEvent);
Assert.AreEqual(client.InstrumentationKey, actualEvent.Payload[0]);

object[] tags = actualEvent.Payload[1] as object[];
Assert.AreEqual("ai.user.id", ((Dictionary<string, object>)(tags[0]))["Key"]);
Assert.AreEqual("testUserId", ((Dictionary<string, object>)(tags[0]))["Value"]);

Assert.AreEqual("ai.operation.id", ((Dictionary<string, object>)(tags[1]))["Key"]);
Assert.AreEqual(item.Context.Operation.Id, ((Dictionary<string, object>)(tags[1]))["Value"]);

Assert.IsNotNull(actualEvent.Payload[2]);
}
this.DoTracking(
RichPayloadEventSource.Keywords.Events,
new EventTelemetry("TestEvent"),
(client, item) => { client.TrackEvent((EventTelemetry)item); });
}

/// <summary>
/// Tests tracking exception telemetry.
/// </summary>
[TestMethod]
public void RichPayloadEventSourceExceptionSentTest()
{
var client = new TelemetryClient();
client.InstrumentationKey = Guid.NewGuid().ToString();

using (var listener = new Microsoft.ApplicationInsights.TestFramework.TestEventListener())
{
listener.EnableEvents(RichPayloadEventSource.Log.EventSourceInternal, EventLevel.Verbose, RichPayloadEventSource.Keywords.Exceptions);

var item = new ExceptionTelemetry(new SystemException("Test"));
item.Context.Properties.Add("property1", "value1");
item.Context.User.Id = "testUserId";
item.Context.Operation.Id = Guid.NewGuid().ToString();

client.TrackException(item);

var actualEvent = listener.Messages.FirstOrDefault();

Assert.IsNotNull(actualEvent);
Assert.AreEqual(client.InstrumentationKey, actualEvent.Payload[0]);

object[] tags = actualEvent.Payload[1] as object[];
Assert.AreEqual("ai.user.id", ((Dictionary<string, object>)(tags[0]))["Key"]);
Assert.AreEqual("testUserId", ((Dictionary<string, object>)(tags[0]))["Value"]);

Assert.AreEqual("ai.operation.id", ((Dictionary<string, object>)(tags[1]))["Key"]);
Assert.AreEqual(item.Context.Operation.Id, ((Dictionary<string, object>)(tags[1]))["Value"]);

Assert.IsNotNull(actualEvent.Payload[2]);
}
this.DoTracking(
RichPayloadEventSource.Keywords.Exceptions,
new ExceptionTelemetry(new SystemException("Test")),
(client, item) => { client.TrackException((ExceptionTelemetry)item); });
}

/// <summary>
/// Tests tracking metric telemetry.
/// </summary>
[TestMethod]
public void RichPayloadEventSourceMetricSentTest()
{
var client = new TelemetryClient();
client.InstrumentationKey = Guid.NewGuid().ToString();

using (var listener = new Microsoft.ApplicationInsights.TestFramework.TestEventListener())
{
listener.EnableEvents(RichPayloadEventSource.Log.EventSourceInternal, EventLevel.Verbose, RichPayloadEventSource.Keywords.Metrics);

var item = new MetricTelemetry("TestMetric", 1);
item.Context.Properties.Add("property1", "value1");
item.Context.User.Id = "testUserId";
item.Context.Operation.Id = Guid.NewGuid().ToString();

client.TrackMetric(item);

var actualEvent = listener.Messages.FirstOrDefault();

Assert.IsNotNull(actualEvent);
Assert.AreEqual(client.InstrumentationKey, actualEvent.Payload[0]);

object[] tags = actualEvent.Payload[1] as object[];
Assert.AreEqual("ai.user.id", ((Dictionary<string, object>)(tags[0]))["Key"]);
Assert.AreEqual("testUserId", ((Dictionary<string, object>)(tags[0]))["Value"]);

Assert.AreEqual("ai.operation.id", ((Dictionary<string, object>)(tags[1]))["Key"]);
Assert.AreEqual(item.Context.Operation.Id, ((Dictionary<string, object>)(tags[1]))["Value"]);

Assert.IsNotNull(actualEvent.Payload[2]);
}
this.DoTracking(
RichPayloadEventSource.Keywords.Metrics,
new MetricTelemetry("TestMetric", 1),
(client, item) => { client.TrackMetric((MetricTelemetry)item); });
}

/// <summary>
/// Tests tracking dependency telemetry.
/// </summary>
[TestMethod]
public void RichPayloadEventSourceDependencySentTest()
{
var client = new TelemetryClient();
client.InstrumentationKey = Guid.NewGuid().ToString();

using (var listener = new Microsoft.ApplicationInsights.TestFramework.TestEventListener())
{
listener.EnableEvents(RichPayloadEventSource.Log.EventSourceInternal, EventLevel.Verbose, RichPayloadEventSource.Keywords.Dependencies);

var item = new DependencyTelemetry("TestDependency", "TestCommand", DateTimeOffset.Now, TimeSpan.Zero, true);
item.Context.Properties.Add("property1", "value1");
item.Context.User.Id = "testUserId";
item.Context.Operation.Id = Guid.NewGuid().ToString();

client.TrackDependency(item);

var actualEvent = listener.Messages.FirstOrDefault();

Assert.IsNotNull(actualEvent);
Assert.AreEqual(client.InstrumentationKey, actualEvent.Payload[0]);

object[] tags = actualEvent.Payload[1] as object[];
Assert.AreEqual("ai.user.id", ((Dictionary<string, object>)(tags[0]))["Key"]);
Assert.AreEqual("testUserId", ((Dictionary<string, object>)(tags[0]))["Value"]);

Assert.AreEqual("ai.operation.id", ((Dictionary<string, object>)(tags[1]))["Key"]);
Assert.AreEqual(item.Context.Operation.Id, ((Dictionary<string, object>)(tags[1]))["Value"]);

Assert.IsNotNull(actualEvent.Payload[2]);
}
this.DoTracking(
RichPayloadEventSource.Keywords.Dependencies,
new DependencyTelemetry("TestDependency", "TestCommand", DateTimeOffset.Now, TimeSpan.Zero, true),
(client, item) => { client.TrackDependency((DependencyTelemetry)item); });
}

/// <summary>
/// Tests tracking page view telemetry.
/// </summary>
[TestMethod]
public void RichPayloadEventSourcePageViewSentTest()
{
this.DoTracking(
RichPayloadEventSource.Keywords.PageViews,
new PageViewTelemetry("TestPage"),
(client, item) => { client.TrackPageView((PageViewTelemetry)item); });
}

/// <summary>
/// Helper method to setup shared context and call the desired tracking for testing.
/// </summary>
/// <param name="keywords">The event keywords to enable.</param>
/// <param name="item">The telemetry item to track.</param>
/// <param name="track">The tracking callback to execute.</param>
private void DoTracking(EventKeywords keywords, ITelemetry item, Action<TelemetryClient, ITelemetry> track)
{
var client = new TelemetryClient();
client.InstrumentationKey = Guid.NewGuid().ToString();

using (var listener = new Microsoft.ApplicationInsights.TestFramework.TestEventListener())
{
listener.EnableEvents(RichPayloadEventSource.Log.EventSourceInternal, EventLevel.Verbose, RichPayloadEventSource.Keywords.PageViews);
listener.EnableEvents(RichPayloadEventSource.Log.EventSourceInternal, EventLevel.Verbose, keywords);

var item = new PageViewTelemetry("TestPage");
item.Context.Properties.Add("property1", "value1");
item.Context.User.Id = "testUserId";
item.Context.Operation.Id = Guid.NewGuid().ToString();

client.TrackPageView(item);
track(client, item);

var actualEvent = listener.Messages.FirstOrDefault();

Assert.IsNotNull(actualEvent);
Assert.AreEqual(client.InstrumentationKey, actualEvent.Payload[0]);

int keysFound = 0;
object[] tags = actualEvent.Payload[1] as object[];
Assert.AreEqual("ai.user.id", ((Dictionary<string, object>)(tags[0]))["Key"]);
Assert.AreEqual("testUserId", ((Dictionary<string, object>)(tags[0]))["Value"]);

Assert.AreEqual("ai.operation.id", ((Dictionary<string, object>)(tags[1]))["Key"]);
Assert.AreEqual(item.Context.Operation.Id, ((Dictionary<string, object>)(tags[1]))["Value"]);

foreach (object tagObject in tags)
{
Dictionary<string, object> tag = (Dictionary<string, object>)tagObject;
Assert.IsNotNull(tag);
string key = (string)tag["Key"];
object value = tag["Value"];
if (!string.IsNullOrWhiteSpace(key))
{
if (key == "ai.user.id")
{
Assert.AreEqual("testUserId", value);
++keysFound;
}
else if (key == "ai.operation.id")
{
Assert.AreEqual(item.Context.Operation.Id, value);
++keysFound;
}
}
}

Assert.AreEqual(2, keysFound);
Assert.IsNotNull(actualEvent.Payload[2]);
}
}
Expand Down
1 change: 0 additions & 1 deletion Test/CoreSDK.Test/Shared/Core.Shared.Tests.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Extensibility\Implementation\SessionContextTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensibility\Implementation\SeverityLevelExtensionsTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensibility\Implementation\SnapshottingCollectionTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensibility\Implementation\SnapshottingDictionaryTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensibility\Implementation\SnapshottingListTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensibility\Implementation\TagsTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensibility\Implementation\TaskTimerTest.cs" />
Expand Down
15 changes: 9 additions & 6 deletions Test/CoreSDK.Test/Shared/DataContracts/EventTelemetryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,17 @@ public void SanitizeWillTrimAppropriateFields()
Assert.Equal(new string('Z', Property.MaxEventNameLength), telemetry.Name);

Assert.Equal(2, telemetry.Properties.Count);
Assert.Equal(new string('X', Property.MaxDictionaryNameLength), telemetry.Properties.Keys.ToArray()[0]);
Assert.Equal(new string('X', Property.MaxValueLength), telemetry.Properties.Values.ToArray()[0]);
Assert.Equal(new string('X', Property.MaxDictionaryNameLength - 3) + "001", telemetry.Properties.Keys.ToArray()[1]);
Assert.Equal(new string('X', Property.MaxValueLength), telemetry.Properties.Values.ToArray()[1]);
string[] keys = telemetry.Properties.Keys.OrderBy(s => s).ToArray();
string[] values = telemetry.Properties.Values.OrderBy(s => s).ToArray();
Assert.Equal(new string('X', Property.MaxDictionaryNameLength), keys[1]);
Assert.Equal(new string('X', Property.MaxValueLength), values[1]);
Assert.Equal(new string('X', Property.MaxDictionaryNameLength - 3) + "001", keys[0]);
Assert.Equal(new string('X', Property.MaxValueLength), values[0]);

Assert.Equal(2, telemetry.Metrics.Count);
Assert.Equal(new string('Y', Property.MaxDictionaryNameLength), telemetry.Metrics.Keys.ToArray()[0]);
Assert.Equal(new string('Y', Property.MaxDictionaryNameLength - 3) + "001", telemetry.Metrics.Keys.ToArray()[1]);
keys = telemetry.Metrics.Keys.OrderBy(s => s).ToArray();
Assert.Equal(new string('Y', Property.MaxDictionaryNameLength), keys[1]);
Assert.Equal(new string('Y', Property.MaxDictionaryNameLength - 3) + "001", keys[0]);
}

[TestMethod]
Expand Down
Loading

0 comments on commit a118ff2

Please sign in to comment.