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

Make W3C Correlation default and leverage native W3C support from new System.Diagnostics.DiagnosticSource Activity #958

Merged
merged 34 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bb75b72
wip 1
cijothomas Aug 21, 2019
557c43a
wip test1
cijothomas Aug 21, 2019
e55927c
aspnet 1.xx modified for w3c
cijothomas Aug 21, 2019
8e9d63b
unit testing
cijothomas Aug 22, 2019
0035667
update base sdk to private signed version
cijothomas Aug 22, 2019
4aa138c
fixes
cijothomas Aug 22, 2019
bc2faa7
fix tests
cijothomas Aug 22, 2019
a1ada4b
read trace state correct
cijothomas Aug 22, 2019
5e5209e
fix tests
cijothomas Aug 22, 2019
32e8ae6
new test
cijothomas Aug 22, 2019
9fd5ca5
more tst
cijothomas Aug 22, 2019
3f02039
config change and test
cijothomas Aug 23, 2019
47bf080
fix review comments
cijothomas Aug 26, 2019
2071a53
make legacyrootid from operationid if possible
cijothomas Aug 26, 2019
536b792
fix 956
cijothomas Aug 26, 2019
03ea036
fix webapi20 functional tests
cijothomas Aug 26, 2019
cb2de3a
reorder
cijothomas Aug 26, 2019
343ac9a
order
cijothomas Aug 26, 2019
1ae760b
ignore dep tests
cijothomas Aug 27, 2019
7e4279f
ignore more dep tests
cijothomas Aug 27, 2019
b5eade0
ignore dep tests in mvc1.0
cijothomas Aug 27, 2019
2f1427a
disable dep collection required tests
cijothomas Aug 27, 2019
e535282
Revert "disable dep collection required tests"
cijothomas Aug 27, 2019
a0abc0a
revert
cijothomas Aug 27, 2019
9d10126
merge conflict resolve
cijothomas Aug 27, 2019
8b15054
bump to beta3
cijothomas Aug 27, 2019
0d6be75
read cor context for w3c
cijothomas Aug 27, 2019
0604e73
func test with correlation header if either w3c or reqid is presnt
cijothomas Aug 27, 2019
34d51b9
fix review comments and whitespace issue
cijothomas Aug 27, 2019
7533468
conflict resolve
cijothomas Aug 27, 2019
26a407e
add event log events for correlation
cijothomas Aug 27, 2019
28ee89d
add langversion to 7.2
cijothomas Aug 27, 2019
2e3dded
modify linux ci to not test 1.xx tests. it cannot use language versio…
cijothomas Aug 27, 2019
a95a5c9
build and test netcoreapp20 in non windows
cijothomas Aug 27, 2019
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
20 changes: 5 additions & 15 deletions .vsts/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,27 @@ steps:
arguments: "--configuration Release"

- task: DotNetCoreCLI@1
displayName: Test 2.0
displayName: Functional Tests 2.0
continueOnError: true
inputs:
command: "test"
projects: "test/**/*Tests20.csproj"
arguments: "--configuration Release -l trx"

- task: DotNetCoreInstaller@0
displayName: install dotnet core 1.1.5
inputs:
version: "1.1.5"

- task: DotNetCoreCLI@1
displayName: Test 1.1.5
displayName: Unit Tests
continueOnError: true
inputs:
command: "test"
projects: "test/**/*Tests.csproj"
arguments: "--configuration Release -l trx --filter Category!=WindowsOnly"
projects: "test/**/*AspNetCore.Tests.csproj"
arguments: "--configuration Release -l trx"


- task: PublishTestResults@2
inputs:
testRunner: "VSTest"
testResultsFiles: "**/*.trx"

- task: DotNetCoreInstaller@0
displayName: install dotnet core 2.1.500
inputs:
version: "2.1.500"

- task: DotNetCoreCLI@1
displayName: Package Nuget
inputs:
Expand All @@ -63,4 +53,4 @@ steps:
inputs:
PathtoPublish: "$(build.artifactstagingdirectory)"
ArtifactName: "drop"
ArtifactType: "Container"
ArtifactType: "Container"
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Version 2.8.0-beta3
- [Make W3C Correlation default and leverage native W3C support from Activity.](https://github.com/microsoft/ApplicationInsights-aspnetcore/pull/958)
- [Fixes Azure Functions performance degradation when W3C enabled.](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/900)
- [Fix: AppId is never set is Response Headers.](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/956)

## Version 2.8.0-beta2
- [Fix MVCBeforeAction property fetcher to work with .NET Core 3.0 changes.](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/936)
- [Catch generic exception from DiagnosticSourceListeners and log instead of failing user request.](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/957)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public static StringValues SetHeaderKeyValue(string[] currentHeaders, string key
/// Http Headers only allow Printable US-ASCII characters.
/// Remove all other characters.
/// </summary>
/// <returns>sanitized string.</returns>
public static string SanitizeString(string input)
{
if (string.IsNullOrWhiteSpace(input))
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ namespace Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners
using Microsoft.AspNetCore.Http;

/// <summary>
/// <see cref="IApplicationInsightDiagnosticListener"/> implementation that listens for evens specific to AspNetCore Mvc layer
/// <see cref="IApplicationInsightDiagnosticListener"/> implementation that listens for events specific to AspNetCore Mvc layer.
/// </summary>
[Obsolete("This class was merged with HostingDiagnosticsListener to optimize Diagnostics Source subscription performance")]
public class MvcDiagnosticsListener : IApplicationInsightDiagnosticListener
{
/// <inheritdoc />
public string ListenerName { get; } = "Microsoft.AspNetCore";

private readonly PropertyFetcher httpContextFetcher = new PropertyFetcher("httpContext");
private readonly PropertyFetcher routeDataFetcher = new PropertyFetcher("routeData");
private readonly PropertyFetcher routeValuesFetcher = new PropertyFetcher("Values");

/// <inheritdoc />
public string ListenerName { get; } = "Microsoft.AspNetCore";

/// <summary>
/// Diagnostic event handler method for 'Microsoft.AspNetCore.Mvc.BeforeAction' event
/// Diagnostic event handler method for 'Microsoft.AspNetCore.Mvc.BeforeAction' event.
/// </summary>
public void OnBeforeAction(HttpContext httpContext, IDictionary<string, object> routeValues)
{
Expand All @@ -40,6 +40,49 @@ public void OnBeforeAction(HttpContext httpContext, IDictionary<string, object>
}
}

/// <inheritdoc />
public void OnSubscribe()
{
}

/// <inheritdoc />
public void OnNext(KeyValuePair<string, object> value)
{
try
{
if (value.Key == "Microsoft.AspNetCore.Mvc.BeforeAction")
{
var context = this.httpContextFetcher.Fetch(value.Value) as HttpContext;
var routeData = this.routeDataFetcher.Fetch(value.Value);
var routeValues = this.routeValuesFetcher.Fetch(routeData) as IDictionary<string, object>;

if (context != null && routeValues != null)
{
this.OnBeforeAction(context, routeValues);
}
}
}
catch (Exception ex)
{
AspNetCoreEventSource.Instance.DiagnosticListenerWarning("MvcDiagnosticsListener", value.Key, ex.Message);
}
}

/// <inheritdoc />
public void OnError(Exception error)
{
}

/// <inheritdoc />
public void OnCompleted()
{
}

/// <inheritdoc />
public void Dispose()
{
}

private string GetNameFromRouteContext(IDictionary<string, object> routeValues)
{
string name = null;
Expand Down Expand Up @@ -95,48 +138,5 @@ private string GetNameFromRouteContext(IDictionary<string, object> routeValues)

return name;
}

/// <inheritdoc />
public void OnSubscribe()
{
}

/// <inheritdoc />
public void OnNext(KeyValuePair<string, object> value)
{
try
{
if (value.Key == "Microsoft.AspNetCore.Mvc.BeforeAction")
{
var context = this.httpContextFetcher.Fetch(value.Value) as HttpContext;
var routeData = routeDataFetcher.Fetch(value.Value);
var routeValues = routeValuesFetcher.Fetch(routeData) as IDictionary<string, object>;

if (context != null && routeValues != null)
{
this.OnBeforeAction(context, routeValues);
}
}
}
catch (Exception ex)
{
AspNetCoreEventSource.Instance.DiagnosticListenerWarning("MvcDiagnosticsListener", value.Key, ex.Message);
}
}

/// <inheritdoc />
public void OnError(Exception error)
{
}

/// <inheritdoc />
public void OnCompleted()
{
}

/// <inheritdoc />
public void Dispose()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,14 @@ internal static class RequestResponseHeaders
/// Correlation-Context header.
/// </summary>
public const string CorrelationContextHeader = "Correlation-Context";

//
// Summary:
// W3C traceparent header name.
public const string TraceParentHeader = "traceparent";
//
// Summary:
// W3C tracestate header name.
public const string TraceStateHeader = "tracestate";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,27 @@ public void LogHostingDiagnosticListenerOnHttpRequestInStartActivityNull(string
this.WriteEvent(9, this.ApplicationName);
}

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

/// <summary>
/// Logs an event when QuickPulseTelemetryModule is not found in service collection.
/// </summary>
[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)]
public void UnableToFindQuickPulseModuleInDI(string appDomainName = "Incorrect")
{
this.WriteEvent(12, this.ApplicationName);
}

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

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

/// <summary>
/// Logs an event when RequestTrackingModule failed to initialize.
/// </summary>
[Event(
15,
Keywords = Keywords.Diagnostics,
Expand All @@ -153,6 +168,9 @@ public void RequestTrackingModuleInitializationFailed(string errorMessage, strin
this.WriteEvent(15, errorMessage, this.ApplicationName);
}

/// <summary>
/// Logs an event when any error occurs within DiagnosticListener callback.
/// </summary>
[Event(
16,
Keywords = Keywords.Diagnostics,
Expand All @@ -163,6 +181,9 @@ public void DiagnosticListenerWarning(string callback, string errorMessage, stri
this.WriteEvent(16, callback, errorMessage, this.ApplicationName);
}

/// <summary>
/// Logs an event when TelemetryConfiguration configure has failed.
/// </summary>
[Event(
17,
Keywords = Keywords.Diagnostics,
Expand All @@ -172,7 +193,10 @@ public void TelemetryConfigurationSetupFailure(string errorMessage, string appDo
{
this.WriteEvent(17, errorMessage, this.ApplicationName);
}


/// <summary>
/// Logs an event when a telemetry item is sampled out at head.
/// </summary>
[Event(
18,
Keywords = Keywords.Diagnostics,
Expand All @@ -183,6 +207,42 @@ public void TelemetryItemWasSampledOutAtHead(string operationId, string appDomai
this.WriteEvent(18, operationId, this.ApplicationName);
}

/// <summary>
/// Logs an informational event from Hosting listeners.
/// </summary>
[Event(
19,
Message = "Hosting Major Version: '{0}'. Informational Message: '{1}'.",
Level = EventLevel.Informational)]
public void HostingListenerInformational(string hostingVersion, string message, string appDomainName = "Incorrect")
{
this.WriteEvent(19, hostingVersion, message, this.ApplicationName);
}

/// <summary>
/// Logs a verbose event.
/// </summary>
[Event(
20,
Message = "Message: '{0}'.",
Level = EventLevel.Verbose)]
public void HostingListenerVerboe(string message, string appDomainName = "Incorrect")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void HostingListenerVerboe(string message, string appDomainName = "Incorrect")
public void HostingListenerVerbose(string message, string appDomainName = "Incorrect")

Also, do we really need both: Informational and verbose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address it next PR (for 3.0 support)

{
this.WriteEvent(20, message, this.ApplicationName);
}

/// <summary>
/// Logs an event for RequestTelemetry created.
/// </summary>
[Event(
21,
Message = "RequestTelemetry created. CorrelationFormat: '{0}', RequestID: '{1}', OperationId : '{2}' ",
Level = EventLevel.Informational)]
public void RequestTelemetryCreated(string correlationFormat, string requestId, string requestOperationId, string appDomainName = "Incorrect")
{
this.WriteEvent(21, correlationFormat, requestId, requestOperationId, this.ApplicationName);
}

/// <summary>
/// Keywords for the AspNetEventSource.
/// </summary>
Expand Down
Loading