Skip to content

Commit

Permalink
Overwrite duplicate tags in TraceContext (Azure#5055)
Browse files Browse the repository at this point in the history
Addressed case where there can be duplicate tags.
  • Loading branch information
yojagad authored Oct 10, 2019
1 parent 2407574 commit 4dbdc6d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Script.Description;
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;
using Microsoft.Azure.WebJobs.Script.OutOfProc;
using Microsoft.Extensions.Logging;

namespace Microsoft.Azure.WebJobs.Script.Rpc
Expand Down Expand Up @@ -61,7 +60,11 @@ internal static RpcTraceContext GetRpcTraceContext(string activityId, string tra
}
else
{
traceContext.Attributes.Add(tag.Key, tag.Value);
if (traceContext.Attributes.ContainsKey(tag.Key))
{
logger?.LogWarning($"Overwriting '{tag.Key}' with existing value '{traceContext.Attributes[tag.Key]}' with '{tag.Value}'");
}
traceContext.Attributes[tag.Key] = tag.Value;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ public class ScriptInvocationContextExtensionsTests
[InlineData(null, null, null)]
public void TestGetRpcTraceContext_WithExpectedValues(string traceparent, string tracestate, IEnumerable<KeyValuePair<string, string>> attributes)
{
IEnumerable<KeyValuePair<string, string>> expectedAttributes = null;
if (!string.IsNullOrEmpty(traceparent))
{
attributes = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("key1", "value1") };
attributes = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("key1", "value1"), new KeyValuePair<string, string>("key1", "value2") };
expectedAttributes = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("key1", "value2") };
}

RpcTraceContext traceContext = ScriptInvocationContextExtensions.GetRpcTraceContext(traceparent, tracestate, attributes, NullLogger.Instance);
Expand All @@ -31,7 +33,7 @@ public void TestGetRpcTraceContext_WithExpectedValues(string traceparent, string

if (attributes != null)
{
Assert.True(attributes.SequenceEqual(traceContext.Attributes));
Assert.True(expectedAttributes.SequenceEqual(traceContext.Attributes));
}
else
{
Expand Down

0 comments on commit 4dbdc6d

Please sign in to comment.