Skip to content

Commit

Permalink
Merge pull request #1216 from microsoft/develop
Browse files Browse the repository at this point in the history
merge develop to master (prep 2.11 stable)
  • Loading branch information
TimothyMothra authored Sep 20, 2019
2 parents f93523a + 900fa6f commit de4e53d
Show file tree
Hide file tree
Showing 18 changed files with 293 additions and 72 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

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


## Version 2.11.0
- Upgrade to System.Diagnostics.DiagnosticSource v4.6
- [Fix: StartOperation(Activity) does not check for Ids compatibility](https://github.com/microsoft/ApplicationInsights-dotnet/pull/1213)

## Version 2.11.0-beta2
- [Fix: Emit warning if user sets both Sampling IncludedTypes and ExcludedTypes. Excluded will take precedence.](https://github.com/microsoft/ApplicationInsights-dotnet/issues/1166)
- [Minor perf improvement by reading Actity.Tag only if required.](https://github.com/microsoft/ApplicationInsights-dotnet/pull/1170)
Expand Down
4 changes: 4 additions & 0 deletions Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<ChecksumAlgorithm>SHA256</ChecksumAlgorithm>
</PropertyGroup>

<PropertyGroup>
<LangVersion>7.1</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
Expand Down
2 changes: 1 addition & 1 deletion GlobalStaticVersion.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<SemanticVersionMinor>11</SemanticVersionMinor>
<SemanticVersionPatch>0</SemanticVersionPatch>
<!--Valid values: beta1, beta2, EMPTY for stable -->
<PreReleaseMilestone>beta2</PreReleaseMilestone>
<PreReleaseMilestone></PreReleaseMilestone>
<!--
Date when Semantic Version was changed.
Update for every public release.
Expand Down
3 changes: 2 additions & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<!-- This file belongs into the EnlistmentRoot folder next to EnlistmentRoot.marker. -->
<!-- See the comments in Directory.Build.props for explanations. -->
<packageSources>
<clear/>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="Net Core Feed" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/3.0.100-rc2-014277/nuget/v3/index.json" />
</packageSources>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="CompareNETObjects" Version="4.59.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0-preview7.19362.9" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
<PackageReference Include="Moq" Version="4.10.0" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="CompareNETObjects" Version="4.59.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0-preview7.19362.9" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
<PackageReference Include="Moq" Version="4.10.0" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,21 @@ public void InitializeWithActivityRecorded()
currentActivity.Stop();
}

[TestMethod]
public void InitializeWithActivityRecordedOperationIdSet()
{
var currentActivity = new Activity("test");
currentActivity.ActivityTraceFlags |= ActivityTraceFlags.Recorded;
currentActivity.Start();
var request = new RequestTelemetry();
request.Context.Operation.Id = ActivityTraceId.CreateRandom().ToHexString();

(new OperationCorrelationTelemetryInitializer()).Initialize(request);

Assert.AreEqual(SamplingDecision.SampledIn, request.ProactiveSamplingDecision);
currentActivity.Stop();
}

[TestMethod]
public void InitializeWithActivityNotRecorded()
{
Expand Down Expand Up @@ -413,5 +428,22 @@ public void InitializeOnActivityWithTracestateNotOperationTelemetry()
// does not throw
(new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
}

[TestMethod]
public void InitializeOnActivityWithTracestateAndOperationIdSet()
{
Activity parent = new Activity("parent")
{
TraceStateString = "some=state"
};
parent.Start();

var telemetry = new DependencyTelemetry();
telemetry.Context.Operation.Id = ActivityTraceId.CreateRandom().ToHexString();
(new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);

Assert.IsTrue(telemetry.Properties.ContainsKey("tracestate"));
Assert.AreEqual("some=state", telemetry.Properties["tracestate"]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void TestCleanup()
[TestMethod]
public void BasicStartOperationWithActivity()
{
var activity = new Activity("name").SetParentId("parentId").AddBaggage("b1", "v1").AddTag("t1", "v1");
var activity = new Activity("name").AddBaggage("b1", "v1").AddTag("t1", "v1");

RequestTelemetry telemetry;
using (var operation = this.telemetryClient.StartOperation<RequestTelemetry>(activity))
Expand All @@ -64,6 +64,87 @@ public void BasicStartOperationWithActivity()
Assert.AreEqual(telemetry, this.sendItems.Single());
}

[TestMethod]
public void StartOperationWithActivity_LegacyId1()
{
var activity = new Activity("name")
.SetParentId("parentId")
.AddBaggage("b1", "v1")
.AddTag("t1", "v1");

activity.ActivityTraceFlags = ActivityTraceFlags.Recorded;
activity.TraceStateString = "state=some";

RequestTelemetry telemetry;
using (var operation = this.telemetryClient.StartOperation<RequestTelemetry>(activity))
{
telemetry = operation.Telemetry;
Assert.AreEqual(activity, Activity.Current);
Assert.IsNotNull(activity.Id);
}

this.ValidateTelemetry(telemetry, activity, true, "parentId");
Assert.IsTrue(telemetry.Properties.TryGetValue("ai_legacyRootId", out var legacyRoot));
Assert.AreEqual("parentId", legacyRoot);

Assert.AreEqual(telemetry, this.sendItems.Single());
}

[TestMethod]
public void StartOperationWithActivity_LegacyId2()
{
var activity = new Activity("name")
.SetParentId("|parentId.123.")
.AddBaggage("b1", "v1")
.AddTag("t1", "v1");

activity.ActivityTraceFlags = ActivityTraceFlags.Recorded;
activity.TraceStateString = "state=some";

RequestTelemetry telemetry;
using (var operation = this.telemetryClient.StartOperation<RequestTelemetry>(activity))
{
telemetry = operation.Telemetry;
Assert.AreEqual(activity, Activity.Current);
Assert.IsNotNull(activity.Id);
}

this.ValidateTelemetry(telemetry, activity, true, "|parentId.123.");

Assert.IsTrue(telemetry.Properties.TryGetValue("ai_legacyRootId", out var legacyRoot));
Assert.AreEqual("parentId", legacyRoot);
Assert.AreEqual(telemetry, this.sendItems.Single());
}

[TestMethod]
public void StartOperationWithActivity_LegacyIdCompatible()
{
var activity = new Activity("name")
.SetParentId("|00112233445566778899aabbccddeeff.123.")
.AddBaggage("b1", "v1")
.AddTag("t1", "v1");

activity.ActivityTraceFlags = ActivityTraceFlags.Recorded;
activity.TraceStateString = "state=some";

RequestTelemetry telemetry;
Activity newActivity = null;
using (var operation = this.telemetryClient.StartOperation<RequestTelemetry>(activity))
{
telemetry = operation.Telemetry;
newActivity = Activity.Current;
Assert.AreNotEqual(activity, newActivity);
Assert.IsNotNull(newActivity?.Id);
}

this.ValidateTelemetry(telemetry, newActivity, true, "|00112233445566778899aabbccddeeff.123.");
Assert.AreEqual("00112233445566778899aabbccddeeff", telemetry.Context.Operation.Id);

Assert.IsFalse(telemetry.Properties.ContainsKey("ai_legacyRootId"));

Assert.AreEqual(telemetry, this.sendItems.Single());
}

[TestMethod]
public void BasicStartOperationWithActivityInScopeOfUnrelatedActivity()
{
Expand All @@ -80,7 +161,7 @@ public void BasicStartOperationWithActivityInScopeOfUnrelatedActivity()
Assert.IsNotNull(activity.Id);
}

this.ValidateTelemetry(telemetry, activity);
this.ValidateTelemetry(telemetry, activity, true, "parentId");

Assert.AreEqual(telemetry, this.sendItems.Single());
Assert.AreEqual(outerActivity, Activity.Current);
Expand All @@ -99,7 +180,11 @@ public void BasicStartOperationWithStartedActivityInScopeOfUnrelatedActivity()

// this is not right to give started Activity to StartOperation, but nothing terrible should happen
// except it won't be possible to restore original context after StartOperation completes
var activity = new Activity("name").SetParentId("parentId").AddBaggage("b1", "v1").AddTag("t1", "v1").Start();
var activity = new Activity("name")
.SetParentId(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom())
.AddBaggage("b1", "v1")
.AddTag("t1", "v1")
.Start();

RequestTelemetry telemetry;
using (var operation = this.telemetryClient.StartOperation<RequestTelemetry>(activity))
Expand All @@ -119,7 +204,6 @@ public void BasicStartOperationWithStartedActivityInScopeOfUnrelatedActivity()
Assert.IsNotNull(request);
Assert.AreEqual(activity.TraceId.ToHexString(), request.Context.Operation.Id);
Assert.AreEqual($"|{activity.TraceId.ToHexString()}.{activity.SpanId.ToHexString()}.", request.Id);
Assert.AreEqual("parentId", request.Context.Operation.ParentId);
}

/// <summary>
Expand All @@ -128,7 +212,7 @@ public void BasicStartOperationWithStartedActivityInScopeOfUnrelatedActivity()
[TestMethod]
public void InvalidStartOperationWithStartedActivity()
{
var activity = new Activity("name").SetParentId("parentId").AddBaggage("b1", "v1").AddTag("t1", "v1").Start();
var activity = new Activity("name").AddBaggage("b1", "v1").AddTag("t1", "v1").Start();

DependencyTelemetry telemetry;
using (var operation = this.telemetryClient.StartOperation<DependencyTelemetry>(activity))
Expand All @@ -150,12 +234,12 @@ public void StartOperationSynchronousInScopeOfOtherUnrelatedActivity()
// nested operation processing.
// E.g. Background Activity is tracking high-level operation "get 5 messages from the queue and process them all"
// In this case, each message processing has it's own correlation scope, passed in the message (i.e. Parent Activity is external)
// The requirement is that backgorund Activity must survive each message processing.
// The requirement is that background Activity must survive each message processing.

var backgroundActivity = new Activity("background").Start();

//since ParentId is set on the activity, it won't be child of the parentActivity
var activity = new Activity("name").SetParentId("parentId");
var activity = new Activity("name").SetParentId(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom());

// in order to keep parentActivity, StartOperation and StopOperation(or dispose)
// must be called
Expand Down Expand Up @@ -184,7 +268,7 @@ public async Task StartOperationAsyncInScopeOfOtherUnrelatedActivity()
var activity = new Activity("name").SetParentId("parentId");
RequestTelemetry telemetry = await ProcessWithStartOperationAsync<RequestTelemetry>(activity, null);

this.ValidateTelemetry(telemetry, activity);
this.ValidateTelemetry(telemetry, activity, true, "parentId");
Assert.AreEqual(telemetry, this.sendItems.Single());

// after processing is done and chile activity is finished,
Expand Down Expand Up @@ -332,20 +416,34 @@ private async Task ProcessAsync(Activity activity, Activity parentActivity)
return telemetry;
}

private void ValidateTelemetry<T>(T telemetry, Activity activity, bool isW3C = true) where T : OperationTelemetry
private void ValidateTelemetry<T>(T telemetry, Activity activity, bool isW3C = true, string legacyParentId = null) where T : OperationTelemetry
{
Assert.AreEqual(activity.OperationName, telemetry.Name);
Assert.AreEqual(
isW3C
? W3CUtilities.FormatTelemetryId(activity.TraceId.ToHexString(), activity.SpanId.ToHexString())
: activity.Id, telemetry.Id);

if (isW3C)
{
Assert.AreEqual(W3CUtilities.FormatTelemetryId(activity.TraceId.ToHexString(), activity.SpanId.ToHexString()), telemetry.Id);
if (activity.ParentSpanId != default && activity.ParentSpanId.ToHexString() != "0000000000000000")
{
Assert.AreEqual(
W3CUtilities.FormatTelemetryId(activity.TraceId.ToHexString(),
activity.ParentSpanId.ToHexString()), telemetry.Context.Operation.ParentId);
}
else
{
Assert.AreEqual(legacyParentId, telemetry.Context.Operation.ParentId);
}

Assert.AreEqual(activity.TraceId.ToHexString(), telemetry.Context.Operation.Id);
}
else
{
Assert.AreEqual(activity.Id, telemetry.Id);
Assert.AreEqual(activity.ParentId, telemetry.Context.Operation.ParentId);
Assert.AreEqual(activity.RootId, telemetry.Context.Operation.Id);
}

Assert.AreEqual(activity.ParentId, telemetry.Context.Operation.ParentId);
Assert.AreEqual(activity.RootId, telemetry.Context.Operation.Id);

foreach (var baggage in activity.Baggage)
{
Expand All @@ -358,6 +456,18 @@ private void ValidateTelemetry<T>(T telemetry, Activity activity, bool isW3C = t
Assert.IsTrue(telemetry.Properties.ContainsKey(tag.Key));
Assert.AreEqual(tag.Value, telemetry.Properties[tag.Key]);
}

if (activity.TraceStateString != null)
{
Assert.IsTrue(telemetry.Properties.TryGetValue("tracestate", out var tracestate));
Assert.AreEqual(activity.TraceStateString, tracestate);
}
else
{
Assert.IsFalse(telemetry.Properties.ContainsKey("tracestate"));
}

Assert.AreEqual(activity.Recorded ? SamplingDecision.SampledIn : SamplingDecision.None, (telemetry as ISupportAdvancedSampling).ProactiveSamplingDecision);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<PackageReference Include="System.Collections.Immutable" Version="1.3.1" />
<Reference Include="System.ComponentModel.Composition" />
<PackageReference Include="System.Console" Version="4.3.0" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0-preview7.19362.9" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
<PackageReference Include="System.Diagnostics.FileVersionInfo" Version="4.3.0" />
<PackageReference Include="System.Diagnostics.StackTrace" Version="4.3.0" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="CompareNETObjects" Version="4.59.0" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0-preview7.19362.9" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Net.Security" Version="4.3.2" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="CompareNETObjects" Version="4.59.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0-preview7.19362.9" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="CompareNETObjects" Version="4.59.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0-preview7.19362.9" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
<ProjectReference Include="..\..\..\src\ServerTelemetryChannel\TelemetryChannel.csproj">
<Project>{3273d899-d9b3-44fe-b3ab-578e18b2ef90}</Project>
<Name>TelemetryChannel</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<PackageReference Include="System.Security.AccessControl" Version="4.3.0" />
<PackageReference Include="CompareNETObjects" Version="4.59.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0-preview7.19362.9" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
<PackageReference Include="System.Net.Security" Version="4.3.2" />
<ProjectReference Include="..\..\..\src\ServerTelemetryChannel\TelemetryChannel.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="CompareNETObjects" Version="4.59.0" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0-preview7.19362.9" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
<ProjectReference Include="..\..\..\src\ServerTelemetryChannel\TelemetryChannel.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="CompareNETObjects" Version="4.59.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0-preview7.19362.9" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
<PackageReference Include="Castle.Core" Version="4.4.0" />
<ProjectReference Include="..\..\..\src\ServerTelemetryChannel\TelemetryChannel.csproj" />
<EmbeddedResource Include="..\..\..\src\ServerTelemetryChannel\ApplicationInsights.config.install.xdt">
Expand Down
Loading

0 comments on commit de4e53d

Please sign in to comment.