Esempio n. 1
0
        internal static RpcTraceContext GetRpcTraceContext(string activityId, string traceStateString, IEnumerable <KeyValuePair <string, string> > tags, ILogger logger)
        {
            RpcTraceContext traceContext = new RpcTraceContext
            {
                TraceParent = activityId ?? string.Empty,
                TraceState  = traceStateString ?? string.Empty,
            };

            foreach (KeyValuePair <string, string> tag in tags ?? Enumerable.Empty <KeyValuePair <string, string> >())
            {
                if (string.IsNullOrEmpty(tag.Value))
                {
                    logger?.LogDebug($"Excluding {tag.Key} from being added to TraceContext.Attributes since it's value is null/empty");
                }
                else
                {
                    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;
                }
            }

            return(traceContext);
        }
Esempio n. 2
0
        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"), 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);

            Assert.Equal(traceparent ?? string.Empty, traceContext.TraceParent);
            Assert.Equal(tracestate ?? string.Empty, traceContext.TraceState);

            if (attributes != null)
            {
                Assert.True(expectedAttributes.SequenceEqual(traceContext.Attributes));
            }
            else
            {
                Assert.Equal(0, traceContext.Attributes.Count);
            }
        }
Esempio n. 3
0
        internal static RpcTraceContext GetRpcTraceContext(string activityId, string traceStateString, IEnumerable <KeyValuePair <string, string> > tags, ILogger logger)
        {
            RpcTraceContext traceContext = new RpcTraceContext
            {
                TraceParent = activityId ?? string.Empty,
                TraceState  = traceStateString ?? string.Empty,
            };

            foreach (KeyValuePair <string, string> tag in tags ?? Enumerable.Empty <KeyValuePair <string, string> >())
            {
                if (string.IsNullOrEmpty(tag.Value))
                {
                    logger?.LogDebug($"Excluding {tag.Key} from being added to TraceContext.Attributes since it's value is null/empty");
                }
                else
                {
                    traceContext.Attributes.Add(tag.Key, tag.Value);
                }
            }

            return(traceContext);
        }