Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Commit c2929a9

Browse files
authored
Revert "Make W3C Correlation default and leverage native W3C support from new System.Diagnostics.DiagnosticSource Activity (#958)" (#962)
This reverts commit b0ae600.
1 parent b0ae600 commit c2929a9

File tree

39 files changed

+1165
-1364
lines changed

39 files changed

+1165
-1364
lines changed

.vsts/linux-build.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,37 @@ steps:
2121
arguments: "--configuration Release"
2222

2323
- task: DotNetCoreCLI@1
24-
displayName: Functional Tests 2.0
24+
displayName: Test 2.0
2525
continueOnError: true
2626
inputs:
2727
command: "test"
2828
projects: "test/**/*Tests20.csproj"
2929
arguments: "--configuration Release -l trx"
3030

31+
- task: DotNetCoreInstaller@0
32+
displayName: install dotnet core 1.1.5
33+
inputs:
34+
version: "1.1.5"
35+
3136
- task: DotNetCoreCLI@1
32-
displayName: Unit Tests
37+
displayName: Test 1.1.5
3338
continueOnError: true
3439
inputs:
3540
command: "test"
36-
projects: "test/**/*AspNetCore.Tests.csproj"
37-
arguments: "--configuration Release -l trx"
41+
projects: "test/**/*Tests.csproj"
42+
arguments: "--configuration Release -l trx --filter Category!=WindowsOnly"
3843

3944

4045
- task: PublishTestResults@2
4146
inputs:
4247
testRunner: "VSTest"
4348
testResultsFiles: "**/*.trx"
4449

50+
- task: DotNetCoreInstaller@0
51+
displayName: install dotnet core 2.1.500
52+
inputs:
53+
version: "2.1.500"
54+
4555
- task: DotNetCoreCLI@1
4656
displayName: Package Nuget
4757
inputs:
@@ -53,4 +63,4 @@ steps:
5363
inputs:
5464
PathtoPublish: "$(build.artifactstagingdirectory)"
5565
ArtifactName: "drop"
56-
ArtifactType: "Container"
66+
ArtifactType: "Container"

CHANGELOG.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
# Changelog
22

3-
## Version 2.8.0-beta3
4-
- [Make W3C Correlation default and leverage native W3C support from Activity.](https://github.com/microsoft/ApplicationInsights-aspnetcore/pull/958)
5-
- [Fixes Azure Functions performance degradation when W3C enabled.](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/900)
6-
- [Fix: AppId is never set is Response Headers.](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/956)
7-
83
## Version 2.8.0-beta2
94
- [Fix MVCBeforeAction property fetcher to work with .NET Core 3.0 changes.](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/936)
105
- [Catch generic exception from DiagnosticSourceListeners and log instead of failing user request.](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/957)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
namespace Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners
2+
{
3+
#if NET451 || NET46
4+
using System.Runtime.Remoting;
5+
using System.Runtime.Remoting.Messaging;
6+
#else
7+
using System.Threading;
8+
#endif
9+
10+
/// <summary>
11+
/// Represents ambient data that is local to a given asynchronous control flow, such as an asynchronous method.
12+
/// </summary>
13+
/// <typeparam name="T">The type of the ambient data. </typeparam>
14+
internal class ContextData<T>
15+
{
16+
#if NET451 || NET46
17+
private static readonly string Key = typeof(ContextData<T>).FullName;
18+
19+
/// <summary>
20+
/// Gets or sets the value of the ambient data.
21+
/// </summary>
22+
/// <returns>The value of the ambient data. </returns>
23+
public T Value
24+
{
25+
get
26+
{
27+
var handle = CallContext.LogicalGetData(Key) as ObjectHandle;
28+
return handle != null ? (T)handle.Unwrap() : default(T);
29+
}
30+
31+
set
32+
{
33+
CallContext.LogicalSetData(Key, new ObjectHandle(value));
34+
}
35+
}
36+
#else
37+
private readonly AsyncLocal<T> storage = new AsyncLocal<T>();
38+
39+
/// <summary>
40+
/// Gets or sets the value of the ambient data.
41+
/// </summary>
42+
/// <returns>The value of the ambient data. </returns>
43+
public T Value
44+
{
45+
get { return this.storage.Value; }
46+
set { this.storage.Value = value; }
47+
}
48+
#endif
49+
}
50+
}

src/Microsoft.ApplicationInsights.AspNetCore/DiagnosticListeners/Implementation/HeadersUtilities.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public static StringValues SetHeaderKeyValue(string[] currentHeaders, string key
7272
/// Http Headers only allow Printable US-ASCII characters.
7373
/// Remove all other characters.
7474
/// </summary>
75-
/// <returns>sanitized string.</returns>
7675
public static string SanitizeString(string input)
7776
{
7877
if (string.IsNullOrWhiteSpace(input))

src/Microsoft.ApplicationInsights.AspNetCore/DiagnosticListeners/Implementation/HostingDiagnosticListener.cs

Lines changed: 339 additions & 392 deletions
Large diffs are not rendered by default.

src/Microsoft.ApplicationInsights.AspNetCore/DiagnosticListeners/Implementation/MvcDiagnosticsListener.cs

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ namespace Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners
99
using Microsoft.AspNetCore.Http;
1010

1111
/// <summary>
12-
/// <see cref="IApplicationInsightDiagnosticListener"/> implementation that listens for events specific to AspNetCore Mvc layer.
12+
/// <see cref="IApplicationInsightDiagnosticListener"/> implementation that listens for evens specific to AspNetCore Mvc layer
1313
/// </summary>
1414
[Obsolete("This class was merged with HostingDiagnosticsListener to optimize Diagnostics Source subscription performance")]
1515
public class MvcDiagnosticsListener : IApplicationInsightDiagnosticListener
1616
{
17+
/// <inheritdoc />
18+
public string ListenerName { get; } = "Microsoft.AspNetCore";
19+
1720
private readonly PropertyFetcher httpContextFetcher = new PropertyFetcher("httpContext");
1821
private readonly PropertyFetcher routeDataFetcher = new PropertyFetcher("routeData");
1922
private readonly PropertyFetcher routeValuesFetcher = new PropertyFetcher("Values");
2023

21-
/// <inheritdoc />
22-
public string ListenerName { get; } = "Microsoft.AspNetCore";
23-
2424
/// <summary>
25-
/// Diagnostic event handler method for 'Microsoft.AspNetCore.Mvc.BeforeAction' event.
25+
/// Diagnostic event handler method for 'Microsoft.AspNetCore.Mvc.BeforeAction' event
2626
/// </summary>
2727
public void OnBeforeAction(HttpContext httpContext, IDictionary<string, object> routeValues)
2828
{
@@ -40,49 +40,6 @@ public void OnBeforeAction(HttpContext httpContext, IDictionary<string, object>
4040
}
4141
}
4242

43-
/// <inheritdoc />
44-
public void OnSubscribe()
45-
{
46-
}
47-
48-
/// <inheritdoc />
49-
public void OnNext(KeyValuePair<string, object> value)
50-
{
51-
try
52-
{
53-
if (value.Key == "Microsoft.AspNetCore.Mvc.BeforeAction")
54-
{
55-
var context = this.httpContextFetcher.Fetch(value.Value) as HttpContext;
56-
var routeData = this.routeDataFetcher.Fetch(value.Value);
57-
var routeValues = this.routeValuesFetcher.Fetch(routeData) as IDictionary<string, object>;
58-
59-
if (context != null && routeValues != null)
60-
{
61-
this.OnBeforeAction(context, routeValues);
62-
}
63-
}
64-
}
65-
catch (Exception ex)
66-
{
67-
AspNetCoreEventSource.Instance.DiagnosticListenerWarning("MvcDiagnosticsListener", value.Key, ex.Message);
68-
}
69-
}
70-
71-
/// <inheritdoc />
72-
public void OnError(Exception error)
73-
{
74-
}
75-
76-
/// <inheritdoc />
77-
public void OnCompleted()
78-
{
79-
}
80-
81-
/// <inheritdoc />
82-
public void Dispose()
83-
{
84-
}
85-
8643
private string GetNameFromRouteContext(IDictionary<string, object> routeValues)
8744
{
8845
string name = null;
@@ -138,5 +95,48 @@ private string GetNameFromRouteContext(IDictionary<string, object> routeValues)
13895

13996
return name;
14097
}
98+
99+
/// <inheritdoc />
100+
public void OnSubscribe()
101+
{
102+
}
103+
104+
/// <inheritdoc />
105+
public void OnNext(KeyValuePair<string, object> value)
106+
{
107+
try
108+
{
109+
if (value.Key == "Microsoft.AspNetCore.Mvc.BeforeAction")
110+
{
111+
var context = this.httpContextFetcher.Fetch(value.Value) as HttpContext;
112+
var routeData = routeDataFetcher.Fetch(value.Value);
113+
var routeValues = routeValuesFetcher.Fetch(routeData) as IDictionary<string, object>;
114+
115+
if (context != null && routeValues != null)
116+
{
117+
this.OnBeforeAction(context, routeValues);
118+
}
119+
}
120+
}
121+
catch (Exception ex)
122+
{
123+
AspNetCoreEventSource.Instance.DiagnosticListenerWarning("MvcDiagnosticsListener", value.Key, ex.Message);
124+
}
125+
}
126+
127+
/// <inheritdoc />
128+
public void OnError(Exception error)
129+
{
130+
}
131+
132+
/// <inheritdoc />
133+
public void OnCompleted()
134+
{
135+
}
136+
137+
/// <inheritdoc />
138+
public void Dispose()
139+
{
140+
}
141141
}
142142
}

src/Microsoft.ApplicationInsights.AspNetCore/DiagnosticListeners/Implementation/RequestResponseHeaders.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,5 @@ internal static class RequestResponseHeaders
2929
/// Correlation-Context header.
3030
/// </summary>
3131
public const string CorrelationContextHeader = "Correlation-Context";
32-
33-
//
34-
// Summary:
35-
// W3C traceparent header name.
36-
public const string TraceParentHeader = "traceparent";
37-
//
38-
// Summary:
39-
// W3C tracestate header name.
40-
public const string TraceStateHeader = "tracestate";
4132
}
4233
}

src/Microsoft.ApplicationInsights.AspNetCore/Extensibility/Implementation/Tracing/AspNetCoreEventSource.cs

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -111,27 +111,18 @@ public void LogHostingDiagnosticListenerOnHttpRequestInStartActivityNull(string
111111
this.WriteEvent(9, this.ApplicationName);
112112
}
113113

114-
/// <summary>
115-
/// Logs an event when a TelemetryModule is not found to configure.
116-
/// </summary>
117114
[Event(11, Message = "Unable to configure module {0} as it is not found in service collection.", Level = EventLevel.Warning, Keywords = Keywords.Diagnostics)]
118115
public void UnableToFindModuleToConfigure(string moduleType, string appDomainName = "Incorrect")
119116
{
120117
this.WriteEvent(11, moduleType, this.ApplicationName);
121118
}
122119

123-
/// <summary>
124-
/// Logs an event when QuickPulseTelemetryModule is not found in service collection.
125-
/// </summary>
126120
[Event(12, Message = "Unable to find QuickPulseTelemetryModule in service collection. LiveMetrics feature will not be available. Please add QuickPulseTelemetryModule to services collection in the ConfigureServices method of your application Startup class.", Level = EventLevel.Error, Keywords = Keywords.Diagnostics)]
127121
public void UnableToFindQuickPulseModuleInDI(string appDomainName = "Incorrect")
128122
{
129123
this.WriteEvent(12, this.ApplicationName);
130124
}
131125

132-
/// <summary>
133-
/// Logs an event when telemetry is not tracked as the Listener is not active.
134-
/// </summary>
135126
[Event(
136127
13,
137128
Keywords = Keywords.Diagnostics,
@@ -142,9 +133,6 @@ public void NotActiveListenerNoTracking(string evntName, string activityId, stri
142133
this.WriteEvent(13, evntName, activityId, this.ApplicationName);
143134
}
144135

145-
/// <summary>
146-
/// Logs an event for when generic error occur within the SDK.
147-
/// </summary>
148136
[Event(
149137
14,
150138
Keywords = Keywords.Diagnostics,
@@ -155,9 +143,6 @@ public void LogError(string errorMessage, string appDomainName = "Incorrect")
155143
this.WriteEvent(14, errorMessage, this.ApplicationName);
156144
}
157145

158-
/// <summary>
159-
/// Logs an event when RequestTrackingModule failed to initialize.
160-
/// </summary>
161146
[Event(
162147
15,
163148
Keywords = Keywords.Diagnostics,
@@ -168,9 +153,6 @@ public void RequestTrackingModuleInitializationFailed(string errorMessage, strin
168153
this.WriteEvent(15, errorMessage, this.ApplicationName);
169154
}
170155

171-
/// <summary>
172-
/// Logs an event when any error occurs within DiagnosticListener callback.
173-
/// </summary>
174156
[Event(
175157
16,
176158
Keywords = Keywords.Diagnostics,
@@ -181,9 +163,6 @@ public void DiagnosticListenerWarning(string callback, string errorMessage, stri
181163
this.WriteEvent(16, callback, errorMessage, this.ApplicationName);
182164
}
183165

184-
/// <summary>
185-
/// Logs an event when TelemetryConfiguration configure has failed.
186-
/// </summary>
187166
[Event(
188167
17,
189168
Keywords = Keywords.Diagnostics,
@@ -193,10 +172,7 @@ public void TelemetryConfigurationSetupFailure(string errorMessage, string appDo
193172
{
194173
this.WriteEvent(17, errorMessage, this.ApplicationName);
195174
}
196-
197-
/// <summary>
198-
/// Logs an event when a telemetry item is sampled out at head.
199-
/// </summary>
175+
200176
[Event(
201177
18,
202178
Keywords = Keywords.Diagnostics,
@@ -207,42 +183,6 @@ public void TelemetryItemWasSampledOutAtHead(string operationId, string appDomai
207183
this.WriteEvent(18, operationId, this.ApplicationName);
208184
}
209185

210-
/// <summary>
211-
/// Logs an informational event from Hosting listeners.
212-
/// </summary>
213-
[Event(
214-
19,
215-
Message = "Hosting Major Version: '{0}'. Informational Message: '{1}'.",
216-
Level = EventLevel.Informational)]
217-
public void HostingListenerInformational(string hostingVersion, string message, string appDomainName = "Incorrect")
218-
{
219-
this.WriteEvent(19, hostingVersion, message, this.ApplicationName);
220-
}
221-
222-
/// <summary>
223-
/// Logs a verbose event.
224-
/// </summary>
225-
[Event(
226-
20,
227-
Message = "Message: '{0}'.",
228-
Level = EventLevel.Verbose)]
229-
public void HostingListenerVerboe(string message, string appDomainName = "Incorrect")
230-
{
231-
this.WriteEvent(20, message, this.ApplicationName);
232-
}
233-
234-
/// <summary>
235-
/// Logs an event for RequestTelemetry created.
236-
/// </summary>
237-
[Event(
238-
21,
239-
Message = "RequestTelemetry created. CorrelationFormat: '{0}', RequestID: '{1}', OperationId : '{2}' ",
240-
Level = EventLevel.Informational)]
241-
public void RequestTelemetryCreated(string correlationFormat, string requestId, string requestOperationId, string appDomainName = "Incorrect")
242-
{
243-
this.WriteEvent(21, correlationFormat, requestId, requestOperationId, this.ApplicationName);
244-
}
245-
246186
/// <summary>
247187
/// Keywords for the AspNetEventSource.
248188
/// </summary>

0 commit comments

Comments
 (0)