diff --git a/CHANGELOG.md b/CHANGELOG.md index 022726459d..4e71feaa18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## VNext - [Upgrade System.Diagnostics.PerformanceCounter to version 6.0.0 to address CVE-2021-24112](https://github.com/microsoft/ApplicationInsights-dotnet/pull/2707) +- [Report internal dependencies from Cosmos SDK as InProc and align with Cosmos SDK EventSource changes](https://github.com/microsoft/ApplicationInsights-dotnet/pull/2712) ## Version 2.22.0-beta1 - Update endpoint redirect header name for QuickPulse module to v2 diff --git a/WEB/Src/DependencyCollector/DependencyCollector.Tests/Implementation/AzureSdkDiagnosticListenerTest.cs b/WEB/Src/DependencyCollector/DependencyCollector.Tests/Implementation/AzureSdkDiagnosticListenerTest.cs index 45ac1f3f45..067c70a669 100644 --- a/WEB/Src/DependencyCollector/DependencyCollector.Tests/Implementation/AzureSdkDiagnosticListenerTest.cs +++ b/WEB/Src/DependencyCollector/DependencyCollector.Tests/Implementation/AzureSdkDiagnosticListenerTest.cs @@ -1397,6 +1397,38 @@ public void AzureCosmosDbSpansAreCollectedWithExtraAttributes() } } + [TestMethod] + public void AzureCosmosDbInternalSpansHaveInProcType() + { + 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", "internal") + .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"); + listener.StopActivity(sendActivity, null); + + 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("InProc | 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"]); + } + } + #if !NET452 [TestMethod] public void AzureCosmosDbSpansAreCollectedWithLogs() @@ -1546,7 +1578,7 @@ private class ApplicationInsightsLink class CosmosDbEventSource : EventSource { private CosmosDbEventSource() - : base("Azure.Cosmos_foo") + : base("Azure-Cosmos-Operation-Request-Diagnostics") { } diff --git a/WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticListenerSubscriber.cs b/WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticListenerSubscriber.cs index 9aea384bfd..ac35c2a139 100644 --- a/WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticListenerSubscriber.cs +++ b/WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticListenerSubscriber.cs @@ -15,7 +15,7 @@ internal sealed class AzureSdkDiagnosticListenerSubscriber : DiagnosticSourceLis public AzureSdkDiagnosticListenerSubscriber(TelemetryConfiguration configuration) : base(configuration) { // listen to Cosmos EventSource only - other logs can be sent using ILogger - this.logsListener = new AzureSdkEventListener(this.Client, EventLevel.Informational, "Azure.Cosmos"); + this.logsListener = new AzureSdkEventListener(this.Client, EventLevel.Informational, "Azure-Cosmos-Operation-Request-Diagnostics"); this.Client.Context.GetInternalContext().SdkVersion = SdkVersionUtils.GetSdkVersion("rdd" + RddSource.DiagnosticSourceListenerAzure + ":"); } diff --git a/WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticsEventHandler.cs b/WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticsEventHandler.cs index 4923aec603..047ece9bcd 100644 --- a/WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticsEventHandler.cs +++ b/WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticsEventHandler.cs @@ -18,6 +18,8 @@ internal class AzureSdkDiagnosticsEventHandler : DiagnosticsEventHandlerBase // Microsoft.DocumentDB is an Azure Resource Provider namespace. We use it as a dependency span as-is // and portal will take care about visualizing it properly. private const string CosmosDBResourceProviderNs = "Microsoft.DocumentDB"; + private const string ClientCosmosDbDependencyType = CosmosDBResourceProviderNs; + private const string InternalCosmosDbDependencyType = "InProc | " + CosmosDBResourceProviderNs; #if NET452 private static readonly DateTimeOffset EpochStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); #endif @@ -102,8 +104,11 @@ public override void OnEvent(KeyValuePair evnt, DiagnosticListen dependency.SetOperationDetail(evnt.Value.GetType().FullName, evnt.Value); } } - else if (dependency.Type == CosmosDBResourceProviderNs) + 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 + // metrics on the edge SetCosmosDbProperties(currentActivity, dependency); } }