diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eae057c2..aba341d73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Version 2.9.0-beta1 - [Prevent duplicate dependency collection in multi-host apps](https://github.com/Microsoft/ApplicationInsights-aspnetcore/issues/621) - [Fix missing transactions Sql dependencies](https://github.com/Microsoft/ApplicationInsights-dotnet-server/pull/1031) +- [Fix: Do not stop Activity in the Stop events, set end time instead](https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/1038) ## Version 2.8.0-beta2 - [LiveMetrics (QuickPulse) TelemetryProcessor added automatically to the default ApplicationInsights.config are moved under the default telemetry sink.](https://github.com/Microsoft/ApplicationInsights-dotnet-server/pull/987) diff --git a/Src/DependencyCollector/Shared/HttpCoreDiagnosticSourceListener.cs b/Src/DependencyCollector/Shared/HttpCoreDiagnosticSourceListener.cs index 2f9440ddc..19caec074 100644 --- a/Src/DependencyCollector/Shared/HttpCoreDiagnosticSourceListener.cs +++ b/Src/DependencyCollector/Shared/HttpCoreDiagnosticSourceListener.cs @@ -379,10 +379,11 @@ internal void OnActivityStop(HttpResponseMessage response, HttpRequestMessage re this.client.Initialize(telemetry); - // If we started auxiliary Activity before to override the Id with W3C compatible one, now it's time to stop it + // If we started auxiliary Activity before to override the Id with W3C compatible one, + // now it's time to set end time on it if (currentActivity.Duration == TimeSpan.Zero) { - currentActivity.Stop(); + currentActivity.SetEndTime(DateTime.UtcNow); } telemetry.Timestamp = currentActivity.StartTimeUtc; diff --git a/Src/DependencyCollector/Shared/Implementation/EventHandlers/EventHubsDiagnosticsEventHandler.cs b/Src/DependencyCollector/Shared/Implementation/EventHandlers/EventHubsDiagnosticsEventHandler.cs index b0e2dec48..61c051aab 100644 --- a/Src/DependencyCollector/Shared/Implementation/EventHandlers/EventHubsDiagnosticsEventHandler.cs +++ b/Src/DependencyCollector/Shared/Implementation/EventHandlers/EventHubsDiagnosticsEventHandler.cs @@ -50,10 +50,11 @@ public override void OnEvent(KeyValuePair evnt, DiagnosticListen break; case "Microsoft.Azure.EventHubs.Send.Stop": case "Microsoft.Azure.EventHubs.Receive.Stop": - // If we started auxiliary Activity before to override the Id with W3C compatible one, now it's time to stop it + // If we started auxiliary Activity before to override the Id with W3C compatible one, + // now it's time to set end time on it if (currentActivity.Duration == TimeSpan.Zero) { - currentActivity.Stop(); + currentActivity.SetEndTime(DateTime.UtcNow); } this.OnDependency(evnt.Key, evnt.Value, currentActivity); diff --git a/Src/DependencyCollector/Shared/Implementation/EventHandlers/ServiceBusDiagnosticsEventHandler.cs b/Src/DependencyCollector/Shared/Implementation/EventHandlers/ServiceBusDiagnosticsEventHandler.cs index 3b39c5543..cd7983e20 100644 --- a/Src/DependencyCollector/Shared/Implementation/EventHandlers/ServiceBusDiagnosticsEventHandler.cs +++ b/Src/DependencyCollector/Shared/Implementation/EventHandlers/ServiceBusDiagnosticsEventHandler.cs @@ -34,10 +34,11 @@ public override void OnEvent(KeyValuePair evnt, DiagnosticListen { case "Microsoft.Azure.ServiceBus.ProcessSession.Stop": case "Microsoft.Azure.ServiceBus.Process.Stop": - // If we started auxiliary Activity before to override the Id with W3C compatible one, now it's time to stop it + // If we started auxiliary Activity before to override the Id with W3C compatible one, + // now it's time to set end time on it if (currentActivity.Duration == TimeSpan.Zero) { - currentActivity.Stop(); + currentActivity.SetEndTime(DateTime.UtcNow); } this.OnRequest(evnt.Key, evnt.Value, currentActivity); @@ -61,10 +62,11 @@ public override void OnEvent(KeyValuePair evnt, DiagnosticListen } else if (evnt.Key.EndsWith(TelemetryDiagnosticSourceListener.ActivityStopNameSuffix, StringComparison.Ordinal)) { - // If we started auxiliary Activity before to override the Id with W3C compatible one, now it's time to stop it + // If we started auxiliary Activity before to override the Id with W3C compatible one, + // now it's time to set end time on it if (currentActivity.Duration == TimeSpan.Zero) { - currentActivity.Stop(); + currentActivity.SetEndTime(DateTime.UtcNow); } this.OnDependency(evnt.Key, evnt.Value, currentActivity);