Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sourabh1007 committed Nov 1, 2022
1 parent e7b53b4 commit 4b1500e
Showing 1 changed file with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ private void RecordAttributes(string name, IEnumerable<KeyValuePair<string, stri
.Append(name)
.Append("</OPERATION>");

OpenTelemetryListener.AssertData(name, tags);

foreach (KeyValuePair<string, string> tag in tags)
{
this.ValidateData(name, tag);

builder
.Append("<ATTRIBUTE-KEY>")
.Append(tag.Key)
Expand All @@ -149,7 +149,43 @@ private void RecordAttributes(string name, IEnumerable<KeyValuePair<string, stri
this.GeneratedActivities.Add(builder.ToString());
}

private void ValidateData(string name, KeyValuePair<string, string> tag)
private static void AssertData(string name, IEnumerable<KeyValuePair<string, string>> tags)
{
IList<string> allowedAttributes = new List<string>
{
"db.system",
"db.name",
"db.operation",
"net.peer.name",
"db.cosmosdb.client_id",
"db.cosmosdb.hashed_machine_id",
"db.cosmosdb.user_agent",
"db.cosmosdb.connection_mode",
"db.cosmosdb.operation_type",
"db.cosmosdb.container",
"db.cosmosdb.request_content_length_bytes",
"db.cosmosdb.response_content_length_bytes",
"db.cosmosdb.status_code",
"db.cosmosdb.sub_status_code",
"db.cosmosdb.request_charge",
"db.cosmosdb.regions_contacted",
"db.cosmosdb.retry_count",
"db.cosmosdb.item_count",
"db.cosmosdb.request_diagnostics",
"exception.type",
"exception.message",
"exception.stacktrace"
};

foreach (KeyValuePair<string, string> tag in tags)
{
Assert.IsTrue(allowedAttributes.Contains(tag.Key), $"{tag.Key} is not allowed for {name}");

OpenTelemetryListener.AssertDatabaseAndContainerName(name, tag);
}
}

private static void AssertDatabaseAndContainerName(string name, KeyValuePair<string, string> tag)
{
IList<string> exceptionsForContainerAttribute = new List<string>
{
Expand Down

0 comments on commit 4b1500e

Please sign in to comment.