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

Report intermediate requests for lost and restored Activity#898

Merged
lmolkova merged 5 commits intodevelopfrom
lmolkova/ActivityPost
May 3, 2018
Merged

Report intermediate requests for lost and restored Activity#898
lmolkova merged 5 commits intodevelopfrom
lmolkova/ActivityPost

Conversation

@lmolkova
Copy link
Copy Markdown

@lmolkova lmolkova commented May 1, 2018

Fix Issue #797 for the case when .NET 4.7.1 is installed on the machine (Azure WebApps case).

  1. When request processing starts, Microsoft.AspNet.TelemetryCorrelation module creates a new Activity and fires Start Event. ApplicationInsights receives this event and creates RequestTelmetery.
    RequestTelemetry gets all correlation Ids from the Activity module created. (Nothing has changed here)

  2. Right before the ASP.NET (or WCF) phase in request processing, the module checks if Activity was lost (it happens in some cases including POST requests). In versions 1.0.0-1.0.1 TelemetryCorrelation module attempted to restore an Activity by creating a child one and did not notify AI about it.

It resulted in following E2E viewer behavior:
image

As the request is a grand-parent of dependency, and nothing has reported in the middle, a correct correlation between them is not possible.

  1. With TelemetryCorrelation version 1.0.3, the module improves its ability to restore the Activity by using new 4.7.1. OnExecuteRequestStep ASP.NET API, see Restore Activity with OnExecuteRequestStep where available aspnet/Microsoft.AspNet.TelemetryCorrelation#24
    It also sens a new event about such activity, so we can track intermediate request and build better UI .

image

This is temporary view, until dotnet/corefx#29208 is released along with .NET Core 2.2. At this point, TelemetryCorrelation will be able to assign Activity.Current and dependency would be a direct child of the request.

  • I ran Unit Tests locally.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated with one line description of the fix, and a link to the original issue.

Next steps (not part of this PR):

  • when .NET 4.7.1 is not installed,detect issue and report heartbeat property

<dependency id="Microsoft.ApplicationInsights" version="[$coresdkversion$]" />
<dependency id="Microsoft.ApplicationInsights.WindowsServer" version="$version$" />
<dependency id="Microsoft.AspNet.TelemetryCorrelation" version="1.0.1" />
<dependency id="Microsoft.AspNet.TelemetryCorrelation" version="1.0.2" />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nuspec and packages config should be aligned on the required version of this package

Copy link
Copy Markdown
Contributor

@SergeyKanzhelev SergeyKanzhelev left a comment

Choose a reason for hiding this comment

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

Will this logic work when TelemetryCorrelation will be fixed? I mean when customer updates TelemetryCorrelation http module, but does not upgrade Application Insights?

@lmolkova
Copy link
Copy Markdown
Author

lmolkova commented May 1, 2018

Will this logic work when TelemetryCorrelation will be fixed? I mean when customer updates TelemetryCorrelation http module, but does not upgrade Application Insights?

Yes, when TelemetryCorrelation will start setting Activity.Current (instead of creating child Activity), ApplicaitonInsights without any change would pick it up.
TelemteryCorrelaiton will stop sending the 'restored activity' event, i.e. AppInsights handler would be effectively no-op

Copy link
Copy Markdown
Contributor

@SergeyKanzhelev SergeyKanzhelev left a comment

Choose a reason for hiding this comment

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

LGTM

@lmolkova
Copy link
Copy Markdown
Author

lmolkova commented May 1, 2018

@MS-TimothyMothra @cijothomas could you please have a look?

@lmolkova lmolkova force-pushed the lmolkova/ActivityPost branch from d0a7df9 to 41813f9 Compare May 2, 2018 18:53
string restoredActivityId = null;
using (var httpClient = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, string.Format($"http://{Apps[TestConstants.WebApiName].ipAddress}/api/values"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a comment above this line to indicate that this Post request will trigger a StartOperation in the testapp. (to make it clear how dependeny item is produced by not making an actual http outbound request)

set BuildRoot=%~dp0..\bin\Release\
set VSTestPath=%PROGRAMFILES(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe

CALL "%VSTestPath%" "%BuildRoot%Test\E2ETests\E2ETests\DependencyCollectionTests.dll" /TestCaseFilter:"TestCategory=Core20" /logger:trx
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

did you intend to make this change? or accidently checked in!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

oh, did not intend to remove those

intermediateRequest.Context.Operation.Id = activity.RootId;
intermediateRequest.Context.Operation.ParentId = activity.ParentId;
intermediateRequest.ResponseCode = null;
intermediateRequest.Properties.Add("AI internal", "Execute request handler step");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

this is a hint to users that it is some kind of technical, internal AI stuff that leaked into their telemetry, rather than a real request.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants