Skip to content

Commit de4e53d

Browse files
author
Timothy Mothra
authored
Merge pull request #1216 from microsoft/develop
merge develop to master (prep 2.11 stable)
2 parents f93523a + 900fa6f commit de4e53d

18 files changed

+293
-72
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

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

5+
6+
## Version 2.11.0
7+
- Upgrade to System.Diagnostics.DiagnosticSource v4.6
8+
- [Fix: StartOperation(Activity) does not check for Ids compatibility](https://github.com/microsoft/ApplicationInsights-dotnet/pull/1213)
9+
510
## Version 2.11.0-beta2
611
- [Fix: Emit warning if user sets both Sampling IncludedTypes and ExcludedTypes. Excluded will take precedence.](https://github.com/microsoft/ApplicationInsights-dotnet/issues/1166)
712
- [Minor perf improvement by reading Actity.Tag only if required.](https://github.com/microsoft/ApplicationInsights-dotnet/pull/1170)

Common.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
<ChecksumAlgorithm>SHA256</ChecksumAlgorithm>
1212
</PropertyGroup>
1313

14+
<PropertyGroup>
15+
<LangVersion>7.1</LangVersion>
16+
</PropertyGroup>
17+
1418
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
1519
<DebugSymbols>true</DebugSymbols>
1620
<DebugType>full</DebugType>

GlobalStaticVersion.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<SemanticVersionMinor>11</SemanticVersionMinor>
1010
<SemanticVersionPatch>0</SemanticVersionPatch>
1111
<!--Valid values: beta1, beta2, EMPTY for stable -->
12-
<PreReleaseMilestone>beta2</PreReleaseMilestone>
12+
<PreReleaseMilestone></PreReleaseMilestone>
1313
<!--
1414
Date when Semantic Version was changed.
1515
Update for every public release.

NuGet.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<!-- This file belongs into the EnlistmentRoot folder next to EnlistmentRoot.marker. -->
44
<!-- See the comments in Directory.Build.props for explanations. -->
55
<packageSources>
6-
<clear/>
6+
<clear />
77
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
8+
<add key="Net Core Feed" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/3.0.100-rc2-014277/nuget/v3/index.json" />
89
</packageSources>
910
</configuration>

Test/Microsoft.ApplicationInsights.Test/Net45/Microsoft.ApplicationInsights.Net45.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
3232
<PackageReference Include="CompareNETObjects" Version="4.59.0" />
3333
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
34-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0-preview7.19362.9" />
34+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
3535
<PackageReference Include="Moq" Version="4.10.0" />
3636
<Reference Include="Microsoft.CSharp" />
3737
<Reference Include="System" />

Test/Microsoft.ApplicationInsights.Test/Net46/Microsoft.ApplicationInsights.Net46.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
3232
<PackageReference Include="CompareNETObjects" Version="4.59.0" />
3333
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
34-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0-preview7.19362.9" />
34+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
3535
<PackageReference Include="Moq" Version="4.10.0" />
3636
<Reference Include="Microsoft.CSharp" />
3737
<Reference Include="System" />

Test/Microsoft.ApplicationInsights.Test/Shared/Extensibility/OperationCorrelationTelemetryInitializerTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,21 @@ public void InitializeWithActivityRecorded()
300300
currentActivity.Stop();
301301
}
302302

303+
[TestMethod]
304+
public void InitializeWithActivityRecordedOperationIdSet()
305+
{
306+
var currentActivity = new Activity("test");
307+
currentActivity.ActivityTraceFlags |= ActivityTraceFlags.Recorded;
308+
currentActivity.Start();
309+
var request = new RequestTelemetry();
310+
request.Context.Operation.Id = ActivityTraceId.CreateRandom().ToHexString();
311+
312+
(new OperationCorrelationTelemetryInitializer()).Initialize(request);
313+
314+
Assert.AreEqual(SamplingDecision.SampledIn, request.ProactiveSamplingDecision);
315+
currentActivity.Stop();
316+
}
317+
303318
[TestMethod]
304319
public void InitializeWithActivityNotRecorded()
305320
{
@@ -413,5 +428,22 @@ public void InitializeOnActivityWithTracestateNotOperationTelemetry()
413428
// does not throw
414429
(new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
415430
}
431+
432+
[TestMethod]
433+
public void InitializeOnActivityWithTracestateAndOperationIdSet()
434+
{
435+
Activity parent = new Activity("parent")
436+
{
437+
TraceStateString = "some=state"
438+
};
439+
parent.Start();
440+
441+
var telemetry = new DependencyTelemetry();
442+
telemetry.Context.Operation.Id = ActivityTraceId.CreateRandom().ToHexString();
443+
(new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
444+
445+
Assert.IsTrue(telemetry.Properties.ContainsKey("tracestate"));
446+
Assert.AreEqual("some=state", telemetry.Properties["tracestate"]);
447+
}
416448
}
417449
}

Test/Microsoft.ApplicationInsights.Test/Shared/StartOperationActivityTests.cs

Lines changed: 124 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void TestCleanup()
4949
[TestMethod]
5050
public void BasicStartOperationWithActivity()
5151
{
52-
var activity = new Activity("name").SetParentId("parentId").AddBaggage("b1", "v1").AddTag("t1", "v1");
52+
var activity = new Activity("name").AddBaggage("b1", "v1").AddTag("t1", "v1");
5353

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

67+
[TestMethod]
68+
public void StartOperationWithActivity_LegacyId1()
69+
{
70+
var activity = new Activity("name")
71+
.SetParentId("parentId")
72+
.AddBaggage("b1", "v1")
73+
.AddTag("t1", "v1");
74+
75+
activity.ActivityTraceFlags = ActivityTraceFlags.Recorded;
76+
activity.TraceStateString = "state=some";
77+
78+
RequestTelemetry telemetry;
79+
using (var operation = this.telemetryClient.StartOperation<RequestTelemetry>(activity))
80+
{
81+
telemetry = operation.Telemetry;
82+
Assert.AreEqual(activity, Activity.Current);
83+
Assert.IsNotNull(activity.Id);
84+
}
85+
86+
this.ValidateTelemetry(telemetry, activity, true, "parentId");
87+
Assert.IsTrue(telemetry.Properties.TryGetValue("ai_legacyRootId", out var legacyRoot));
88+
Assert.AreEqual("parentId", legacyRoot);
89+
90+
Assert.AreEqual(telemetry, this.sendItems.Single());
91+
}
92+
93+
[TestMethod]
94+
public void StartOperationWithActivity_LegacyId2()
95+
{
96+
var activity = new Activity("name")
97+
.SetParentId("|parentId.123.")
98+
.AddBaggage("b1", "v1")
99+
.AddTag("t1", "v1");
100+
101+
activity.ActivityTraceFlags = ActivityTraceFlags.Recorded;
102+
activity.TraceStateString = "state=some";
103+
104+
RequestTelemetry telemetry;
105+
using (var operation = this.telemetryClient.StartOperation<RequestTelemetry>(activity))
106+
{
107+
telemetry = operation.Telemetry;
108+
Assert.AreEqual(activity, Activity.Current);
109+
Assert.IsNotNull(activity.Id);
110+
}
111+
112+
this.ValidateTelemetry(telemetry, activity, true, "|parentId.123.");
113+
114+
Assert.IsTrue(telemetry.Properties.TryGetValue("ai_legacyRootId", out var legacyRoot));
115+
Assert.AreEqual("parentId", legacyRoot);
116+
Assert.AreEqual(telemetry, this.sendItems.Single());
117+
}
118+
119+
[TestMethod]
120+
public void StartOperationWithActivity_LegacyIdCompatible()
121+
{
122+
var activity = new Activity("name")
123+
.SetParentId("|00112233445566778899aabbccddeeff.123.")
124+
.AddBaggage("b1", "v1")
125+
.AddTag("t1", "v1");
126+
127+
activity.ActivityTraceFlags = ActivityTraceFlags.Recorded;
128+
activity.TraceStateString = "state=some";
129+
130+
RequestTelemetry telemetry;
131+
Activity newActivity = null;
132+
using (var operation = this.telemetryClient.StartOperation<RequestTelemetry>(activity))
133+
{
134+
telemetry = operation.Telemetry;
135+
newActivity = Activity.Current;
136+
Assert.AreNotEqual(activity, newActivity);
137+
Assert.IsNotNull(newActivity?.Id);
138+
}
139+
140+
this.ValidateTelemetry(telemetry, newActivity, true, "|00112233445566778899aabbccddeeff.123.");
141+
Assert.AreEqual("00112233445566778899aabbccddeeff", telemetry.Context.Operation.Id);
142+
143+
Assert.IsFalse(telemetry.Properties.ContainsKey("ai_legacyRootId"));
144+
145+
Assert.AreEqual(telemetry, this.sendItems.Single());
146+
}
147+
67148
[TestMethod]
68149
public void BasicStartOperationWithActivityInScopeOfUnrelatedActivity()
69150
{
@@ -80,7 +161,7 @@ public void BasicStartOperationWithActivityInScopeOfUnrelatedActivity()
80161
Assert.IsNotNull(activity.Id);
81162
}
82163

83-
this.ValidateTelemetry(telemetry, activity);
164+
this.ValidateTelemetry(telemetry, activity, true, "parentId");
84165

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

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

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

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

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

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

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

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

187-
this.ValidateTelemetry(telemetry, activity);
271+
this.ValidateTelemetry(telemetry, activity, true, "parentId");
188272
Assert.AreEqual(telemetry, this.sendItems.Single());
189273

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

335-
private void ValidateTelemetry<T>(T telemetry, Activity activity, bool isW3C = true) where T : OperationTelemetry
419+
private void ValidateTelemetry<T>(T telemetry, Activity activity, bool isW3C = true, string legacyParentId = null) where T : OperationTelemetry
336420
{
337421
Assert.AreEqual(activity.OperationName, telemetry.Name);
422+
Assert.AreEqual(
423+
isW3C
424+
? W3CUtilities.FormatTelemetryId(activity.TraceId.ToHexString(), activity.SpanId.ToHexString())
425+
: activity.Id, telemetry.Id);
426+
338427
if (isW3C)
339428
{
340-
Assert.AreEqual(W3CUtilities.FormatTelemetryId(activity.TraceId.ToHexString(), activity.SpanId.ToHexString()), telemetry.Id);
429+
if (activity.ParentSpanId != default && activity.ParentSpanId.ToHexString() != "0000000000000000")
430+
{
431+
Assert.AreEqual(
432+
W3CUtilities.FormatTelemetryId(activity.TraceId.ToHexString(),
433+
activity.ParentSpanId.ToHexString()), telemetry.Context.Operation.ParentId);
434+
}
435+
else
436+
{
437+
Assert.AreEqual(legacyParentId, telemetry.Context.Operation.ParentId);
438+
}
439+
440+
Assert.AreEqual(activity.TraceId.ToHexString(), telemetry.Context.Operation.Id);
341441
}
342442
else
343443
{
344-
Assert.AreEqual(activity.Id, telemetry.Id);
444+
Assert.AreEqual(activity.ParentId, telemetry.Context.Operation.ParentId);
445+
Assert.AreEqual(activity.RootId, telemetry.Context.Operation.Id);
345446
}
346-
347-
Assert.AreEqual(activity.ParentId, telemetry.Context.Operation.ParentId);
348-
Assert.AreEqual(activity.RootId, telemetry.Context.Operation.Id);
349447

350448
foreach (var baggage in activity.Baggage)
351449
{
@@ -358,6 +456,18 @@ private void ValidateTelemetry<T>(T telemetry, Activity activity, bool isW3C = t
358456
Assert.IsTrue(telemetry.Properties.ContainsKey(tag.Key));
359457
Assert.AreEqual(tag.Value, telemetry.Properties[tag.Key]);
360458
}
459+
460+
if (activity.TraceStateString != null)
461+
{
462+
Assert.IsTrue(telemetry.Properties.TryGetValue("tracestate", out var tracestate));
463+
Assert.AreEqual(activity.TraceStateString, tracestate);
464+
}
465+
else
466+
{
467+
Assert.IsFalse(telemetry.Properties.ContainsKey("tracestate"));
468+
}
469+
470+
Assert.AreEqual(activity.Recorded ? SamplingDecision.SampledIn : SamplingDecision.None, (telemetry as ISupportAdvancedSampling).ProactiveSamplingDecision);
361471
}
362472
}
363473
}

Test/Microsoft.ApplicationInsights.Test/Standalone/Microsoft.ApplicationInsights.Isolated.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<PackageReference Include="System.Collections.Immutable" Version="1.3.1" />
3737
<Reference Include="System.ComponentModel.Composition" />
3838
<PackageReference Include="System.Console" Version="4.3.0" />
39-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0-preview7.19362.9" />
39+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
4040
<PackageReference Include="System.Diagnostics.FileVersionInfo" Version="4.3.0" />
4141
<PackageReference Include="System.Diagnostics.StackTrace" Version="4.3.0" />
4242
<PackageReference Include="System.IO.Compression" Version="4.3.0" />

Test/Microsoft.ApplicationInsights.Test/netcoreapp11/Microsoft.ApplicationInsights.netcoreapp11.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
2626
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
2727
<PackageReference Include="CompareNETObjects" Version="4.59.0" />
28-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0-preview7.19362.9" />
28+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
2929
<PackageReference Include="System.Net.Http" Version="4.3.4" />
3030
<PackageReference Include="System.Net.Security" Version="4.3.2" />
3131
</ItemGroup>

0 commit comments

Comments
 (0)