Exemplo n.º 1
0
        public RemoteDependencyData(int version, Activity activity, ref TagEnumerationState monitorTags) : base(version)
        {
            string httpUrl = null;
            string dependencyName;

            if (monitorTags.activityType == OperationType.Http)
            {
                httpUrl        = monitorTags.MappedTags.GetDependencyUrl();
                dependencyName = monitorTags.MappedTags.GetHttpDependencyName(httpUrl) ?? activity.DisplayName;
            }
            else
            {
                dependencyName = activity.DisplayName;
            }

            Name     = dependencyName;
            Id       = activity.Context.SpanId.ToHexString();
            Duration = activity.Duration.ToString("c", CultureInfo.InvariantCulture);
            Success  = activity.GetStatus().StatusCode != StatusCode.Error;

            switch (monitorTags.activityType)
            {
            case OperationType.Http:
                Data       = httpUrl;
                Target     = monitorTags.MappedTags.GetDependencyTarget(OperationType.Http);
                Type       = "Http";
                ResultCode = AzMonList.GetTagValue(ref monitorTags.MappedTags, SemanticConventions.AttributeHttpStatusCode)?.ToString() ?? "0";
                break;

            case OperationType.Db:
                var depDataAndType = AzMonList.GetTagValues(ref monitorTags.MappedTags, SemanticConventions.AttributeDbStatement, SemanticConventions.AttributeDbSystem);
                Data   = depDataAndType[0]?.ToString();
                Target = monitorTags.MappedTags.GetDbDependencyTarget();
                Type   = s_sqlDbs.Contains(depDataAndType[1]?.ToString()) ? "SQL" : depDataAndType[1]?.ToString();
                break;

            case OperationType.Rpc:
                var depInfo = AzMonList.GetTagValues(ref monitorTags.MappedTags, SemanticConventions.AttributeRpcService, SemanticConventions.AttributeRpcSystem, SemanticConventions.AttributeRpcStatus);
                Data       = depInfo[0]?.ToString();
                Type       = depInfo[1]?.ToString();
                ResultCode = depInfo[2]?.ToString();
                break;

            case OperationType.Messaging:
                depDataAndType = AzMonList.GetTagValues(ref monitorTags.MappedTags, SemanticConventions.AttributeMessagingUrl, SemanticConventions.AttributeMessagingSystem);
                Data           = depDataAndType[0]?.ToString();
                Type           = depDataAndType[1]?.ToString();
                break;
            }

            if (activity.Kind == ActivityKind.Internal && activity.Parent != null)
            {
                Type = "InProc";
            }

            Properties   = new ChangeTrackingDictionary <string, string>();
            Measurements = new ChangeTrackingDictionary <string, double>();

            TraceHelper.AddActivityLinksToProperties(activity.Links, ref monitorTags.UnMappedTags);
            TraceHelper.AddPropertiesToTelemetry(Properties, ref monitorTags.UnMappedTags);
        }
Exemplo n.º 2
0
        public void TagObjects_Diff_DataTypes()
        {
            var monitorTags = new TagEnumerationState
            {
                MappedTags   = AzMonList.Initialize(),
                UnMappedTags = 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);
            monitorTags.ForEach(activity.TagObjects);

            Assert.Equal(OperationType.Unknown, monitorTags.activityType);
            Assert.Empty(monitorTags.MappedTags);
            Assert.Equal(6, monitorTags.UnMappedTags.Length);

            Assert.Equal(1, AzMonList.GetTagValue(ref monitorTags.UnMappedTags, "intKey"));
            Assert.Equal(1.1, AzMonList.GetTagValue(ref monitorTags.UnMappedTags, "doubleKey"));
            Assert.Equal("test", AzMonList.GetTagValue(ref monitorTags.UnMappedTags, "stringKey"));
            Assert.Equal(true, AzMonList.GetTagValue(ref monitorTags.UnMappedTags, "boolKey"));
            Assert.Equal("Azure.Monitor.OpenTelemetry.Exporter.Tests.TagsTests+Test", AzMonList.GetTagValue(ref monitorTags.UnMappedTags, "objectKey").ToString());
            Assert.Equal("1,2,3", AzMonList.GetTagValue(ref monitorTags.UnMappedTags, "arrayKey"));
        }
Exemplo n.º 3
0
        public void TagObjects_ObjectArray()
        {
            var monitorTags = new TagEnumerationState
            {
                MappedTags   = AzMonList.Initialize(),
                UnMappedTags = 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);
            monitorTags.ForEach(activity.TagObjects);

            Assert.Equal(OperationType.Unknown, monitorTags.activityType);
            Assert.Empty(monitorTags.MappedTags);
            Assert.Single(monitorTags.UnMappedTags);

            Assert.Equal("Azure.Monitor.OpenTelemetry.Exporter.Tests.TagsTests+Test,Azure.Monitor.OpenTelemetry.Exporter.Tests.TagsTests+Test,Azure.Monitor.OpenTelemetry.Exporter.Tests.TagsTests+Test", AzMonList.GetTagValue(ref monitorTags.UnMappedTags, "objArray"));
        }
Exemplo n.º 4
0
 public void GetTagValueNonemptyAzMonList()
 {
     object _ = AzMonList.GetTagValue(ref AzMonList_Items, SemanticConventions.AttributeHttpHost);
 }
Exemplo n.º 5
0
 public void GetTagValueNonemptyAzMonList()
 {
     AzMonList.GetTagValue(ref _azMonList_Items, "somekey");
 }
Exemplo n.º 6
0
 public void GetTagValueEmptyAzMonList()
 {
     AzMonList.GetTagValue(ref _azMonList_No_Item, SemanticConventions.AttributeHttpHost);
 }