diff --git a/WEB/Src/DependencyCollector/DependencyCollector.Tests/Implementation/AzureSdkDiagnosticListenerTest.cs b/WEB/Src/DependencyCollector/DependencyCollector.Tests/Implementation/AzureSdkDiagnosticListenerTest.cs index b6593c011f..330440d239 100644 --- a/WEB/Src/DependencyCollector/DependencyCollector.Tests/Implementation/AzureSdkDiagnosticListenerTest.cs +++ b/WEB/Src/DependencyCollector/DependencyCollector.Tests/Implementation/AzureSdkDiagnosticListenerTest.cs @@ -1398,42 +1398,7 @@ public void AzureCosmosDbSpansAreCollectedWithExtraAttributes() } [TestMethod] - public void AzureCosmosDbClientSpansSuppressNestedOperations() - { - using (var listener = new DiagnosticListener("Azure.Cosmos")) - using (var module = new DependencyTrackingTelemetryModule()) - { - module.Initialize(this.configuration); - - Activity sendActivity = new Activity("Azure.Cosmos.ReadItems") - .AddTag("kind", "client") - .AddTag("net.peer.name", "my.documents.azure.com") - .AddTag("db.name", "database") - .AddTag("db.operation", "ReadItems") - .AddTag("db.cosmosdb.container", "container") - .AddTag("az.namespace", "Microsoft.DocumentDB"); - - listener.StartActivity(sendActivity, null); - sendActivity.AddTag("db.cosmosdb.status_code", "200"); - - Assert.IsTrue(SdkInternalOperationsMonitor.IsEntered()); - listener.StopActivity(sendActivity, null); - Assert.IsFalse(SdkInternalOperationsMonitor.IsEntered()); - - var telemetry = this.sentItems.Last(); - DependencyTelemetry dependency = telemetry as DependencyTelemetry; - Assert.AreEqual("container | ReadItems", dependency.Name); - Assert.AreEqual("my.documents.azure.com | database", dependency.Target); - Assert.AreEqual("200", dependency.ResultCode); - Assert.AreEqual("Microsoft.DocumentDB", dependency.Type); - Assert.AreEqual("database", dependency.Properties["db.name"]); - Assert.AreEqual("ReadItems", dependency.Properties["db.operation"]); - Assert.AreEqual("my.documents.azure.com", dependency.Properties["net.peer.name"]); - } - } - - [TestMethod] - public void AzureCosmosDbInternalSpansDontSuppressNestedOperations() + public void AzureCosmosDbInternalSpansHaveInProcType() { using (var listener = new DiagnosticListener("Azure.Cosmos")) using (var module = new DependencyTrackingTelemetryModule()) @@ -1450,8 +1415,6 @@ public void AzureCosmosDbInternalSpansDontSuppressNestedOperations() listener.StartActivity(sendActivity, null); sendActivity.AddTag("db.cosmosdb.status_code", "200"); - - Assert.IsFalse(SdkInternalOperationsMonitor.IsEntered()); listener.StopActivity(sendActivity, null); var telemetry = this.sentItems.Last(); diff --git a/WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticsEventHandler.cs b/WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticsEventHandler.cs index 9d20349831..be09945b65 100644 --- a/WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticsEventHandler.cs +++ b/WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticsEventHandler.cs @@ -41,17 +41,17 @@ public override bool IsEventEnabled(string evnt, object arg1, object arg2) public override void OnEvent(KeyValuePair evnt, DiagnosticListener diagnosticListener) { + if (SdkInternalOperationsMonitor.IsEntered()) + { + // Because we support AAD, we must to check if an internal operation is being caught here (type = "InProc | Microsoft.AAD"). + return; + } + try { var currentActivity = Activity.Current; if (evnt.Key.EndsWith(".Start", StringComparison.Ordinal)) { - if (SdkInternalOperationsMonitor.IsEntered()) - { - // Because we support AAD, we must to check if an internal operation is being caught here (type = "InProc | Microsoft.AAD"). - return; - } - OperationTelemetry telemetry = null; foreach (var tag in currentActivity.Tags) @@ -74,12 +74,6 @@ public override void OnEvent(KeyValuePair evnt, DiagnosticListen { SetMessagingProperties(currentActivity, telemetry); } - else if (type == ClientCosmosDbDependencyType) - { - // client Cosmos spans come from new Cosmos SDK in Direct (TCP) mode. SDK might occasionally do - // nested HTTP calls, but we'll suppress them because they are rare and break app-map - SdkInternalOperationsMonitor.Enter(); - } if (this.linksPropertyFetcher.Fetch(evnt.Value) is IEnumerable activityLinks) { @@ -97,10 +91,6 @@ public override void OnEvent(KeyValuePair evnt, DiagnosticListen else if (evnt.Key.EndsWith(".Stop", StringComparison.Ordinal)) { var telemetry = this.operationHolder.Get(currentActivity)?.Item1; - if (telemetry == null) - { - return; - } this.SetCommonProperties(evnt.Key, evnt.Value, currentActivity, telemetry); @@ -114,12 +104,7 @@ public override void OnEvent(KeyValuePair evnt, DiagnosticListen dependency.SetOperationDetail(evnt.Value.GetType().FullName, evnt.Value); } } - else if (dependency.Type == ClientCosmosDbDependencyType) - { - SdkInternalOperationsMonitor.Exit(); - SetCosmosDbProperties(currentActivity, dependency); - } - else if (dependency.Type == InternalCosmosDbDependencyType) + else if (dependency.Type == ClientCosmosDbDependencyType || dependency.Type == InternalCosmosDbDependencyType) { // Internal cosmos spans come from SDK in Gateway mode - they are // logical operations. AppMap then uses HTTP spans to build cosmos node and