-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dependency correlation is broken after upgrade to .NET SDK 2.5 #706
Comments
@older @MS-TimothyMothra |
Calls are tracked but they are not correlated. Azure functions runtime collects requests, but doesn't automatically collect dependencies so it has to be done manually according to the document I linked. Also application version property is lost (maybe others as well, but I haven't checked). Anyway, this is fixed with simple NuGet downgrade from 2.5 back to 2.4 so this is either intended breaking change which went undocumented or it is a bug in 2.5. |
@older Could you please also share the requests and dependency examples preferably in Analytics. Just query Thanks a lot! |
You won't see this problem with requests, as requests are logged by azure functions runtime. But dependencies are logged with custom C# code. I exported 2 requests and 2 dependencies to CSV, hope this helps. |
the problem you described earlier is correlation issues between requests and dependencies, but this comment
makes me wonder if I understood you correctly. Thanks for providing requests and dependencies. Another dependency you've provided tracked by AI SDK 2.5 does not have operation_Id or parentId. I've been able to repro the issue. Apparently, Azure Functions do not use our Activity/DiagnosticSource approach and instead ask to set operation context on telemetry client private static TelemetryClient telemetry =
new TelemetryClient() { InstrumentationKey = key };
[FunctionName("HttpTrigger2")]
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]
HttpRequestMessage req, ExecutionContext context, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
!!! telemetry.Context.Operation.Id = context.InvocationId.ToString();
!!! telemetry.Context.Operation.Name = "cs-http";
telemetry.TrackDependency("Test Dependency", "swapi.co/api/planets/1/", start, DateTime.UtcNow - start, true); This is error-prone approach as telemetry client may track multiple requests in parallel and context is shared between them. Telemetry client is reused and may accidentally track telemetry with wrong id. So even in 2.4 correlation in Azure functions is not reliable Now, what's wrong in 2.5? @MS-TimothyMothra do you know if anything was changed around TelemetryClient.Context ? Workaround (suitable for 2.4 and 2.5)Set context on the telemetry, not the telemetry client! Do it for all telemetry reported: Traces, events, and metrics if applicable var dependency = new DependencyTelemetry
{
Name = "Test Dependency",
Target = "swapi.co/api/planets/1/",
StartTime = start,
Duration = DateTime.UtcNow - start,
Success = true
};
dependency.Context.Operation.Id = context.InvocationId.ToString();
dependency.Context.Operation.ParentId = context.InvocationId.ToString();
dependency.Context.Operation.Name = "cs-http";
if (!String.IsNullOrEmpty(name))
{
dependency.Context.User.Id = name;
}
telemetry.TrackDependency(dependency ); |
I meant you won't see the problem with requests because in this case I have no control over the way requests are reported. Thanks for the workaround, will try it tomorrow. |
Today we released Microsoft.ApplicationInsights (v2.5.1) and Microsoft.ApplicationInsights.Web (v2.5.1) with this fix. |
Repro Steps
Actual Behavior
This is what I get with ApplicationInsights 2.5:
Expected Behavior
Screenshot using ApplicationInsights 2.4:
Version Info
SDK Version : 2.5
.NET Version : 4.6.1
How Application was onboarded with SDK(VisualStudio/StatusMonitor/Azure Extension) : Visual Studio
OS : Windows
Hosting Info (IIS/Azure WebApps/ etc) : Azure
The text was updated successfully, but these errors were encountered: