Skip to content
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

Support internal and client spans from cosmos db #2712

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -1546,7 +1578,7 @@ private class ApplicationInsightsLink
class CosmosDbEventSource : EventSource
{
private CosmosDbEventSource()
: base("Azure.Cosmos_foo")
: base("Azure-Cosmos-Operation-Request-Diagnostics")
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ":");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -102,8 +104,11 @@ public override void OnEvent(KeyValuePair<string, object> evnt, DiagnosticListen
dependency.SetOperationDetail(evnt.Value.GetType().FullName, evnt.Value);
}
}
else if (dependency.Type == CosmosDBResourceProviderNs)
else if (dependency.Type == ClientCosmosDbDependencyType || dependency.Type == InternalCosmosDbDependencyType)
lmolkova marked this conversation as resolved.
Show resolved Hide resolved
{
// 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);
}
}
Expand Down