Skip to content

Commit 1d4bbd6

Browse files
author
Liudmila Molkova
committed
Don't suppress, but support internal spans
1 parent 8b74858 commit 1d4bbd6

File tree

2 files changed

+10
-62
lines changed

2 files changed

+10
-62
lines changed

WEB/Src/DependencyCollector/DependencyCollector.Tests/Implementation/AzureSdkDiagnosticListenerTest.cs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,42 +1398,7 @@ public void AzureCosmosDbSpansAreCollectedWithExtraAttributes()
13981398
}
13991399

14001400
[TestMethod]
1401-
public void AzureCosmosDbClientSpansSuppressNestedOperations()
1402-
{
1403-
using (var listener = new DiagnosticListener("Azure.Cosmos"))
1404-
using (var module = new DependencyTrackingTelemetryModule())
1405-
{
1406-
module.Initialize(this.configuration);
1407-
1408-
Activity sendActivity = new Activity("Azure.Cosmos.ReadItems")
1409-
.AddTag("kind", "client")
1410-
.AddTag("net.peer.name", "my.documents.azure.com")
1411-
.AddTag("db.name", "database")
1412-
.AddTag("db.operation", "ReadItems")
1413-
.AddTag("db.cosmosdb.container", "container")
1414-
.AddTag("az.namespace", "Microsoft.DocumentDB");
1415-
1416-
listener.StartActivity(sendActivity, null);
1417-
sendActivity.AddTag("db.cosmosdb.status_code", "200");
1418-
1419-
Assert.IsTrue(SdkInternalOperationsMonitor.IsEntered());
1420-
listener.StopActivity(sendActivity, null);
1421-
Assert.IsFalse(SdkInternalOperationsMonitor.IsEntered());
1422-
1423-
var telemetry = this.sentItems.Last();
1424-
DependencyTelemetry dependency = telemetry as DependencyTelemetry;
1425-
Assert.AreEqual("container | ReadItems", dependency.Name);
1426-
Assert.AreEqual("my.documents.azure.com | database", dependency.Target);
1427-
Assert.AreEqual("200", dependency.ResultCode);
1428-
Assert.AreEqual("Microsoft.DocumentDB", dependency.Type);
1429-
Assert.AreEqual("database", dependency.Properties["db.name"]);
1430-
Assert.AreEqual("ReadItems", dependency.Properties["db.operation"]);
1431-
Assert.AreEqual("my.documents.azure.com", dependency.Properties["net.peer.name"]);
1432-
}
1433-
}
1434-
1435-
[TestMethod]
1436-
public void AzureCosmosDbInternalSpansDontSuppressNestedOperations()
1401+
public void AzureCosmosDbInternalSpansHaveInProcType()
14371402
{
14381403
using (var listener = new DiagnosticListener("Azure.Cosmos"))
14391404
using (var module = new DependencyTrackingTelemetryModule())
@@ -1450,8 +1415,6 @@ public void AzureCosmosDbInternalSpansDontSuppressNestedOperations()
14501415

14511416
listener.StartActivity(sendActivity, null);
14521417
sendActivity.AddTag("db.cosmosdb.status_code", "200");
1453-
1454-
Assert.IsFalse(SdkInternalOperationsMonitor.IsEntered());
14551418
listener.StopActivity(sendActivity, null);
14561419

14571420
var telemetry = this.sentItems.Last();

WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticsEventHandler.cs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ public override void OnEvent(KeyValuePair<string, object> evnt, DiagnosticListen
4343
{
4444
try
4545
{
46+
if (SdkInternalOperationsMonitor.IsEntered())
47+
{
48+
// Because we support AAD, we must to check if an internal operation is being caught here (type = "InProc | Microsoft.AAD").
49+
return;
50+
}
51+
4652
var currentActivity = Activity.Current;
4753
if (evnt.Key.EndsWith(".Start", StringComparison.Ordinal))
4854
{
49-
if (SdkInternalOperationsMonitor.IsEntered())
50-
{
51-
// Because we support AAD, we must to check if an internal operation is being caught here (type = "InProc | Microsoft.AAD").
52-
return;
53-
}
54-
5555
OperationTelemetry telemetry = null;
5656

5757
foreach (var tag in currentActivity.Tags)
@@ -73,12 +73,6 @@ public override void OnEvent(KeyValuePair<string, object> evnt, DiagnosticListen
7373
if (IsMessagingDependency(type))
7474
{
7575
SetMessagingProperties(currentActivity, telemetry);
76-
}
77-
else if (type == ClientCosmosDbDependencyType)
78-
{
79-
// client Cosmos spans come from new Cosmos SDK in Direct (TCP) mode. SDK might occasionally do
80-
// nested HTTP calls, but we'll suppress them because they are rare and break app-map
81-
SdkInternalOperationsMonitor.Enter();
8276
}
8377

8478
if (this.linksPropertyFetcher.Fetch(evnt.Value) is IEnumerable<Activity> activityLinks)
@@ -96,11 +90,7 @@ public override void OnEvent(KeyValuePair<string, object> evnt, DiagnosticListen
9690
}
9791
else if (evnt.Key.EndsWith(".Stop", StringComparison.Ordinal))
9892
{
99-
var telemetry = this.operationHolder.Get(currentActivity)?.Item1;
100-
if (telemetry == null)
101-
{
102-
return;
103-
}
93+
var telemetry = this.operationHolder.Get(currentActivity).Item1;
10494

10595
this.SetCommonProperties(evnt.Key, evnt.Value, currentActivity, telemetry);
10696

@@ -114,16 +104,11 @@ public override void OnEvent(KeyValuePair<string, object> evnt, DiagnosticListen
114104
dependency.SetOperationDetail(evnt.Value.GetType().FullName, evnt.Value);
115105
}
116106
}
117-
else if (dependency.Type == ClientCosmosDbDependencyType)
118-
{
119-
SdkInternalOperationsMonitor.Exit();
120-
SetCosmosDbProperties(currentActivity, dependency);
121-
}
122-
else if (dependency.Type == InternalCosmosDbDependencyType)
107+
else if (dependency.Type == ClientCosmosDbDependencyType || dependency.Type == InternalCosmosDbDependencyType)
123108
{
124109
// Internal cosmos spans come from SDK in Gateway mode - they are
125110
// logical operations. AppMap then uses HTTP spans to build cosmos node and
126-
// metrics on it
111+
// metrics on the edge
127112
SetCosmosDbProperties(currentActivity, dependency);
128113
}
129114
}

0 commit comments

Comments
 (0)