Skip to content

Commit

Permalink
[AzureMonitorExporter] Add Az.Namespace to Dependency Type. (Azure#35645
Browse files Browse the repository at this point in the history
)

* Add Az.Namespace as Dependency Type.

* Fix UI

* Fix tests

* Comment
  • Loading branch information
rajkumar-rangaraj authored Apr 18, 2023
1 parent 187395b commit bab3bbc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ public RemoteDependencyData(int version, Activity activity, ref ActivityTagsProc
break;
}

if (activity.Kind == ActivityKind.Internal && activity.Parent != null)
if (activity.Kind == ActivityKind.Internal)
{
Type = "InProc";
}
else
{
// The Azure SDK sets az.namespace with its resource provider information.
// When ActivityKind is not internal and az.namespace is present, set the value of Type to az.namespace.
Type = activityTagsProcessor.UnMappedTags.GetAzNameSpace() ?? Type;
}

Properties = new ChangeTrackingDictionary<string, string>();
Measurements = new ChangeTrackingDictionary<string, double>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,5 +382,10 @@ internal static string GetDefaultDbPort(string? dbSystem)

return "Unknown";
}

internal static string? GetAzNameSpace(this AzMonList tagObjects)
{
return AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeAzureNameSpace)?.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,33 @@ public void ValidateDBDependencyType(string dbSystem)
}

[Fact]
public void DependencyTypeisSetToInProcForInternalSpanWithParent()
public void DependencyTypeisSetToInProcForInternalSpan()
{
using ActivitySource activitySource = new ActivitySource(ActivitySourceName);
using var parentActivity = activitySource.StartActivity("ParentActivity", ActivityKind.Internal);
using var childActivity = activitySource.StartActivity("ChildActivity", ActivityKind.Internal);
using var activity = activitySource.StartActivity("Activity", ActivityKind.Internal);

Assert.NotNull(parentActivity);
var activityTagsProcessorParent = TraceHelper.EnumerateActivityTags(parentActivity);
Assert.NotNull(activity);
var activityTagsProcessor = TraceHelper.EnumerateActivityTags(activity);

var remoteDependencyDataTypeForParent = new RemoteDependencyData(2, parentActivity, ref activityTagsProcessorParent).Type;
var remoteDependencyDataType = new RemoteDependencyData(2, activity, ref activityTagsProcessor).Type;

Assert.Null(remoteDependencyDataTypeForParent);
Assert.Equal("InProc", remoteDependencyDataType);
}

Assert.NotNull(childActivity);
var activityTagsProcessorChild = TraceHelper.EnumerateActivityTags(childActivity);
[Fact]
public void DependencyTypeisSetToAzNamespaceValueForNonInternalSpan()
{
using ActivitySource activitySource = new ActivitySource(ActivitySourceName);
using var activity = activitySource.StartActivity("Activity", ActivityKind.Client);
activity?.AddTag("az.namespace", "DemoAzureResource");

var remoteDependencyDataTypeForChild = new RemoteDependencyData(2, childActivity, ref activityTagsProcessorChild).Type;
Assert.NotNull(activity);
var activityTagsProcessor = TraceHelper.EnumerateActivityTags(activity);

var remoteDependencyData = new RemoteDependencyData(2, activity, ref activityTagsProcessor);

Assert.Equal("InProc", remoteDependencyDataTypeForChild);
Assert.Equal("DemoAzureResource", remoteDependencyData.Type);
Assert.Equal("DemoAzureResource", remoteDependencyData.Properties["az.namespace"]);
}

[Fact]
Expand Down

0 comments on commit bab3bbc

Please sign in to comment.