示例#1
0
        public void ValidateSameKey()
        {
            var spanAttribute = new SpanAttributes();

            spanAttribute.Add("key", "value1");
            spanAttribute.Add("key", "value2");
            Assert.Equal("value2", spanAttribute.Attributes["key"]);
        }
        public void NotEquality_WithAttributes()
        {
            var tag1  = new SpanAttributes();
            var tag2  = this.tags;
            var link1 = new Link(this.spanContext, tag1);
            var link2 = new Link(this.spanContext, tag2);

            Assert.NotEqual(link1, link2);
            Assert.True(link1 != link2);
        }
        public void ValidateConstructorWithList()
        {
            var spanAttributes = new SpanAttributes(
                new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("Span attribute int", 1),
                new KeyValuePair <string, object>("Span attribute string", "str"),
            });

            Assert.Equal(2, spanAttributes.Attributes.Count);
        }
示例#4
0
        public void ValidateAddMethods()
        {
            var spanAttribute = new SpanAttributes();

            spanAttribute.Add("key_string", "string");
            spanAttribute.Add("key_a_string", new string[] { "string" });

            spanAttribute.Add("key_double", 1.01);
            spanAttribute.Add("key_a_double", new double[] { 1.01 });

            spanAttribute.Add("key_bool", true);
            spanAttribute.Add("key_a_bool", new bool[] { true });

            spanAttribute.Add("key_long", 1);
            spanAttribute.Add("key_a_long", new long[] { 1 });

            Assert.Equal(8, spanAttribute.Attributes.Count);
        }
        public LinkTest()
        {
            this.spanContext = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None);

            this.attributesMap.Add("MyAttributeKey0", "MyStringAttribute");
            this.attributesMap.Add("MyAttributeKey1", 10L);
            this.attributesMap.Add("MyAttributeKey2", true);
            this.attributesMap.Add("MyAttributeKey3", 0.005);
            this.attributesMap.Add("MyAttributeKey4", new long[] { 1, 2 });
            this.attributesMap.Add("MyAttributeKey5", new string[] { "a", "b" });
            this.attributesMap.Add("MyAttributeKey6", new bool[] { true, false });
            this.attributesMap.Add("MyAttributeKey7", new double[] { 0.1, -0.1 });
            this.tags = new SpanAttributes();
            this.tags.Add("MyAttributeKey0", "MyStringAttribute");
            this.tags.Add("MyAttributeKey1", 10L);
            this.tags.Add("MyAttributeKey2", true);
            this.tags.Add("MyAttributeKey3", 0.005);
            this.tags.Add("MyAttributeKey4", new long[] { 1, 2 });
            this.tags.Add("MyAttributeKey5", new string[] { "a", "b" });
            this.tags.Add("MyAttributeKey6", new bool[] { true, false });
            this.tags.Add("MyAttributeKey7", new double[] { 0.1, -0.1 });
        }
示例#6
0
        /// <inheritdoc/>
        public global::OpenTracing.ISpan Log(DateTimeOffset timestamp, IEnumerable <KeyValuePair <string, object> > fields)
        {
            if (fields is null)
            {
                throw new ArgumentNullException(nameof(fields));
            }

            var payload   = ConvertToEventPayload(fields);
            var eventName = payload.Item1;

            var spanAttributes = new SpanAttributes();

            foreach (var field in payload.Item2)
            {
                switch (field.Value)
                {
                case long value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case long[] value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case bool value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case bool[] value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case double value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case double[] value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case string value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case string[] value:
                    spanAttributes.Add(field.Key, value);
                    break;

                default:
                    break;
                }
            }

            if (timestamp == DateTimeOffset.MinValue)
            {
                this.Span.AddEvent(eventName, spanAttributes);
            }
            else
            {
                this.Span.AddEvent(eventName, timestamp, spanAttributes);
            }

            return(this);
        }
示例#7
0
        /// <inheritdoc/>
        public ISpan Log(DateTimeOffset timestamp, IEnumerable <KeyValuePair <string, object> > fields)
        {
            Guard.ThrowIfNull(fields);

            var payload   = ConvertToEventPayload(fields);
            var eventName = payload.Item1;

            var spanAttributes = new SpanAttributes();

            foreach (var field in payload.Item2)
            {
                switch (field.Value)
                {
                case long value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case long[] value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case bool value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case bool[] value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case double value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case double[] value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case string value:
                    spanAttributes.Add(field.Key, value);
                    break;

                case string[] value:
                    spanAttributes.Add(field.Key, value);
                    break;

                default:
                    break;
                }
            }

            if (timestamp == DateTimeOffset.MinValue)
            {
                this.Span.AddEvent(eventName, spanAttributes);
            }
            else
            {
                this.Span.AddEvent(eventName, timestamp, spanAttributes);
            }

            return(this);
        }
示例#8
0
        public void ValidateNullKey()
        {
            var spanAttribute = new SpanAttributes();

            Assert.Throws <ArgumentNullException>(() => spanAttribute.Add(null, "null key"));
        }
示例#9
0
        public void ValidateConstructor()
        {
            var spanAttribute = new SpanAttributes();

            Assert.Empty(spanAttribute.Attributes);
        }