public void TagObjects_Diff_DataTypes()
        {
            var monitorTags = new AzureMonitorConverter.TagEnumerationState
            {
                PartBTags = AzMonList.Initialize(),
                PartCTags = AzMonList.Initialize()
            };

            IEnumerable <KeyValuePair <string, object> > tagObjects = new Dictionary <string, object>
            {
                ["intKey"]    = 1,
                ["doubleKey"] = 1.1,
                ["stringKey"] = "test",
                ["boolKey"]   = true,
                ["objectKey"] = new Test(),
                ["arrayKey"]  = new int[] { 1, 2, 3 }
            };

            using var activity = CreateTestActivity(tagObjects);
            activity.EnumerateTags(ref monitorTags);

            Assert.Equal(PartBType.Unknown, monitorTags.activityType);
            Assert.Empty(monitorTags.PartBTags);
            Assert.Equal(6, monitorTags.PartCTags.Length);

            Assert.Equal(1, AzMonList.GetTagValue(ref monitorTags.PartCTags, "intKey"));
            Assert.Equal(1.1, AzMonList.GetTagValue(ref monitorTags.PartCTags, "doubleKey"));
            Assert.Equal("test", AzMonList.GetTagValue(ref monitorTags.PartCTags, "stringKey"));
            Assert.Equal(true, AzMonList.GetTagValue(ref monitorTags.PartCTags, "boolKey"));
            Assert.Equal("Microsoft.OpenTelemetry.Exporter.AzureMonitor.Tests.TagsTests+Test", AzMonList.GetTagValue(ref monitorTags.PartCTags, "objectKey").ToString());
            Assert.Equal("1,2,3", AzMonList.GetTagValue(ref monitorTags.PartCTags, "arrayKey"));
        }
        public void TagObjects_NullItem()
        {
            var monitorTags = new AzureMonitorConverter.TagEnumerationState
            {
                PartBTags = AzMonList.Initialize(),
                PartCTags = AzMonList.Initialize()
            };

            IEnumerable <KeyValuePair <string, object> > tagObjects = new Dictionary <string, object>
            {
                ["key1"] = null,
                ["key2"] = new string[] { "test", null },
                ["key3"] = new string[] { null, null }
            };

            using var activity = CreateTestActivity(tagObjects);
            activity.EnumerateTags(ref monitorTags);

            Assert.Equal(PartBType.Unknown, monitorTags.activityType);
            Assert.Empty(monitorTags.PartBTags);
            Assert.Equal(2, monitorTags.PartCTags.Length);
            Assert.Null(AzMonList.GetTagValue(ref monitorTags.PartCTags, "key1"));
            Assert.Equal("test", AzMonList.GetTagValue(ref monitorTags.PartCTags, "key2"));
            Assert.Equal(string.Empty, AzMonList.GetTagValue(ref monitorTags.PartCTags, "key3"));
        }
        public void TagObjects_ObjectArray()
        {
            var monitorTags = new AzureMonitorConverter.TagEnumerationState
            {
                PartBTags = AzMonList.Initialize(),
                PartCTags = AzMonList.Initialize()
            };

            IEnumerable <KeyValuePair <string, object> > tagObjects = new Dictionary <string, object>
            {
                ["objArray"] = new Test[] { new Test(), new Test(), new Test()
                                            {
                                                TestProperty = 0
                                            } },
            };

            using var activity = CreateTestActivity(tagObjects);
            activity.EnumerateTags(ref monitorTags);

            Assert.Equal(PartBType.Unknown, monitorTags.activityType);
            Assert.Empty(monitorTags.PartBTags);
            Assert.Single(monitorTags.PartCTags);

            Assert.Equal("Microsoft.OpenTelemetry.Exporter.AzureMonitor.Tests.TagsTests+Test,Microsoft.OpenTelemetry.Exporter.AzureMonitor.Tests.TagsTests+Test,Microsoft.OpenTelemetry.Exporter.AzureMonitor.Tests.TagsTests+Test", AzMonList.GetTagValue(ref monitorTags.PartCTags, "objArray"));
        }
        public void TagObjects_PartB_PartC()
        {
            var monitorTags = new AzureMonitorConverter.TagEnumerationState
            {
                PartBTags = AzMonList.Initialize(),
                PartCTags = AzMonList.Initialize()
            };

            IEnumerable <KeyValuePair <string, object> > tagObjects = new Dictionary <string, object>
            {
                [SemanticConventions.AttributeHttpScheme]   = "https",
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = "8888",
                ["somekey"] = "value"
            };

            using var activity = CreateTestActivity(tagObjects);
            activity.EnumerateTags(ref monitorTags);

            Assert.Equal(PartBType.Http, monitorTags.activityType);
            Assert.Equal(3, monitorTags.PartBTags.Length);
            Assert.Single(monitorTags.PartCTags);

            Assert.Equal("https", AzMonList.GetTagValue(ref monitorTags.PartBTags, SemanticConventions.AttributeHttpScheme));
            Assert.Equal("localhost", AzMonList.GetTagValue(ref monitorTags.PartBTags, SemanticConventions.AttributeHttpHost));
            Assert.Equal("8888", AzMonList.GetTagValue(ref monitorTags.PartBTags, SemanticConventions.AttributeHttpHostPort));

            Assert.Equal("value", AzMonList.GetTagValue(ref monitorTags.PartCTags, "somekey"));
        }
        public void TagObjects_Empty()
        {
            var monitorTags = new AzureMonitorConverter.TagEnumerationState
            {
                PartBTags = AzMonList.Initialize(),
                PartCTags = AzMonList.Initialize()
            };

            using var activity = CreateTestActivity(new Dictionary <string, object>());
            activity.EnumerateTags(ref monitorTags);

            Assert.Equal(PartBType.Unknown, monitorTags.activityType);
            Assert.Empty(monitorTags.PartBTags);
            Assert.Empty(monitorTags.PartCTags);
        }
        public void TagObjects_PartC()
        {
            var monitorTags = new AzureMonitorConverter.TagEnumerationState
            {
                PartBTags = AzMonList.Initialize(),
                PartCTags = AzMonList.Initialize()
            };

            IEnumerable <KeyValuePair <string, object> > tagObjects = new Dictionary <string, object> {
                ["somekey"] = "value"
            };;

            using var activity = CreateTestActivity(tagObjects);
            activity.EnumerateTags(ref monitorTags);

            Assert.Equal(PartBType.Unknown, monitorTags.activityType);
            Assert.Empty(monitorTags.PartBTags);
            Assert.Equal("value", AzMonList.GetTagValue(ref monitorTags.PartCTags, "somekey"));
        }
Beispiel #7
0
        public void Setup()
        {
            monitorTags = new AzureMonitorConverter.TagEnumerationState
            {
                PartBTags = AzMonList.Initialize(),
                PartCTags = AzMonList.Initialize()
            };

            tagObjects     = new Dictionary <string, object>();
            NoItemActivity = CreateTestActivity();

            PartB_tagObjects = new Dictionary <string, object>
            {
                [SemanticConventions.AttributeNetHostIp]    = "127.0.0.1",
                [SemanticConventions.AttributeHttpScheme]   = "https",
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = "8888",
            };

            PartBActivity = CreateTestActivity(PartB_tagObjects);

            PartC_tagObjects = new Dictionary <string, object>
            {
                ["intKey"]    = 1,
                ["doubleKey"] = 1.1,
                ["stringKey"] = "test",
                ["boolKey"]   = true,
                ["arrayKey"]  = new int[] { 1, 2, 3 }
            };

            PartCActivity = CreateTestActivity(PartC_tagObjects);

            PartB_And_C_tagObjects = new Dictionary <string, object>
            {
                [SemanticConventions.AttributeHttpScheme]   = "https",
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = "8888",
                ["somekey"] = "value"
            };

            PartBAndCActivity = CreateTestActivity(PartB_And_C_tagObjects);
        }
        public void TagObjects_BooleanArray()
        {
            var monitorTags = new AzureMonitorConverter.TagEnumerationState
            {
                PartBTags = AzMonList.Initialize(),
                PartCTags = AzMonList.Initialize()
            };

            IEnumerable <KeyValuePair <string, object> > tagObjects = new Dictionary <string, object>
            {
                ["boolArray"] = new bool[] { true, false, true },
            };

            using var activity = CreateTestActivity(tagObjects);
            activity.EnumerateTags(ref monitorTags);

            Assert.Equal(PartBType.Unknown, monitorTags.activityType);
            Assert.Empty(monitorTags.PartBTags);
            Assert.Single(monitorTags.PartCTags);

            Assert.Equal("True,False,True", AzMonList.GetTagValue(ref monitorTags.PartCTags, "boolArray"));
        }
        public void TagObjects_StringArray()
        {
            var monitorTags = new AzureMonitorConverter.TagEnumerationState
            {
                PartBTags = AzMonList.Initialize(),
                PartCTags = AzMonList.Initialize()
            };

            IEnumerable <KeyValuePair <string, object> > tagObjects = new Dictionary <string, object>
            {
                ["strArray"] = new string[] { "test1", "test2", "test3" },
            };

            using var activity = CreateTestActivity(tagObjects);
            activity.EnumerateTags(ref monitorTags);

            Assert.Equal(PartBType.Unknown, monitorTags.activityType);
            Assert.Empty(monitorTags.PartBTags);
            Assert.Single(monitorTags.PartCTags);

            Assert.Equal("test1,test2,test3", AzMonList.GetTagValue(ref monitorTags.PartCTags, "strArray"));
        }