Skip to content

Commit

Permalink
Don't suppress, but support internal spans
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Nov 16, 2022
1 parent 8b74858 commit 1a58e53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ public override bool IsEventEnabled(string evnt, object arg1, object arg2)

public override void OnEvent(KeyValuePair<string, object> 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)
Expand All @@ -74,12 +74,6 @@ public override void OnEvent(KeyValuePair<string, object> 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<Activity> activityLinks)
{
Expand All @@ -97,10 +91,6 @@ public override void OnEvent(KeyValuePair<string, object> 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);

Expand All @@ -114,12 +104,7 @@ public override void OnEvent(KeyValuePair<string, object> 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
Expand Down

0 comments on commit 1a58e53

Please sign in to comment.