From 4b1500e7749b7f0c64eeca920ccc90ee72b223a3 Mon Sep 17 00:00:00 2001 From: Sourabh Jain Date: Tue, 1 Nov 2022 19:55:32 +0530 Subject: [PATCH] add test --- .../Tracing/OpenTelemetryListener.cs | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/OpenTelemetryListener.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/OpenTelemetryListener.cs index e8e53b6ff1..fa05f5eeec 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/OpenTelemetryListener.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/OpenTelemetryListener.cs @@ -136,10 +136,10 @@ private void RecordAttributes(string name, IEnumerable"); + OpenTelemetryListener.AssertData(name, tags); + foreach (KeyValuePair tag in tags) { - this.ValidateData(name, tag); - builder .Append("") .Append(tag.Key) @@ -149,7 +149,43 @@ private void RecordAttributes(string name, IEnumerable tag) + private static void AssertData(string name, IEnumerable> tags) + { + IList allowedAttributes = new List + { + "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 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 tag) { IList exceptionsForContainerAttribute = new List {