< Summary

Class:Azure.Messaging.ServiceBus.Diagnostics.DiagnosticExtensions
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Diagnostics\DiagnosticExtensions.cs
Covered lines:19
Uncovered lines:14
Coverable lines:33
Total lines:93
Line coverage:57.5% (19 of 33)
Covered branches:5
Total branches:16
Branch coverage:31.2% (5 of 16)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
GetAsciiString(...)-0%0%
SetMessageTags(...)-50%100%
SetMessageTags(...)-75%100%
SetMessageTags(...)-80%75%
SetMessageData(...)-100%100%
SetMessageData(...)-100%100%
AddLinkedDiagnostics(...)-50%25%
AddLinkedDiagnostics(...)-50%25%
AddLinkedDiagnostics(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Diagnostics\DiagnosticExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Text;
 6using Azure.Core.Pipeline;
 7using System.Linq;
 8using System.Collections.Generic;
 9
 10namespace Azure.Messaging.ServiceBus.Diagnostics
 11{
 12    internal static class DiagnosticExtensions
 13    {
 14        public static string GetAsciiString(this ArraySegment<byte> arraySegment)
 15        {
 016            return arraySegment.Array == null ? string.Empty : Encoding.ASCII.GetString(arraySegment.Array, arraySegment
 17        }
 18
 19        public static void SetMessageTags(this DiagnosticScope scope, IEnumerable<ServiceBusReceivedMessage> messages)
 20        {
 21            // set the message Ids on the scope
 022            var messageIds = messages.Where(m => m.MessageId != null).Select(m => m.MessageId).ToArray();
 023            var sessionIds = messages.Where(m => m.SessionId != null).Select(m => m.SessionId).Distinct().ToArray();
 2024            scope.SetMessageTags(messageIds, sessionIds);
 2025        }
 26
 27        private static void SetMessageTags(this DiagnosticScope scope, IEnumerable<ServiceBusMessage> messages)
 28        {
 5029            var messageIds = messages.Where(m => m.MessageId != null).Select(m => m.MessageId).ToArray();
 030            var sessionIds = messages.Where(m => m.SessionId != null).Select(m => m.SessionId).Distinct().ToArray();
 1431            scope.SetMessageTags(messageIds, sessionIds);
 1432        }
 33
 34        private static void SetMessageTags(this DiagnosticScope scope, string[] messageIds, string[] sessionIds)
 35        {
 36            // set the message Ids on the scope
 3437            if (messageIds.Any())
 38            {
 1039                scope.AddAttribute(DiagnosticProperty.MessageIdAttribute, string.Join(",", messageIds));
 40            }
 41
 42            // set any session Ids on the scope
 3443            if (sessionIds.Any())
 44            {
 045                scope.AddAttribute(DiagnosticProperty.SessionIdAttribute, string.Join(",", sessionIds));
 46            }
 3447        }
 48
 49        public static void SetMessageData(this DiagnosticScope scope, IEnumerable<ServiceBusReceivedMessage> messages)
 50        {
 2051            scope.AddLinkedDiagnostics(messages);
 2052            scope.SetMessageTags(messages);
 2053        }
 54
 55        public static void SetMessageData(this DiagnosticScope scope, IEnumerable<ServiceBusMessage> messages)
 56        {
 1457            scope.AddLinkedDiagnostics(messages);
 1458            scope.SetMessageTags(messages);
 1459        }
 60
 61        private static void AddLinkedDiagnostics(this DiagnosticScope scope, IEnumerable<ServiceBusReceivedMessage> mess
 62        {
 2063            if (scope.IsEnabled)
 64            {
 065                foreach (ServiceBusReceivedMessage message in messages)
 66                {
 067                    AddLinkedDiagnostics(scope, message.SentMessage.Properties);
 68                }
 69            }
 2070        }
 71
 72        private static void AddLinkedDiagnostics(this DiagnosticScope scope, IEnumerable<ServiceBusMessage> messages)
 73        {
 1474            if (scope.IsEnabled)
 75            {
 076                foreach (ServiceBusMessage message in messages)
 77                {
 078                    AddLinkedDiagnostics(scope, message.Properties);
 79                }
 80            }
 1481        }
 82
 83        private static void AddLinkedDiagnostics(this DiagnosticScope scope, IDictionary<string, object> properties)
 84        {
 085            if (EntityScopeFactory.TryExtractDiagnosticId(
 086                properties,
 087                out string diagnosticId))
 88            {
 089                scope.AddLink(diagnosticId);
 90            }
 091        }
 92    }
 93}