< Summary

Class:Azure.Messaging.ServiceBus.Diagnostics.EntityScopeFactory
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Diagnostics\EntityScopeFactory.cs
Covered lines:20
Uncovered lines:6
Coverable lines:26
Total lines:90
Line coverage:76.9% (20 of 26)
Covered branches:7
Total branches:12
Branch coverage:58.3% (7 of 12)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get__scopeFactory()-100%100%
.ctor(...)-100%100%
TryExtractDiagnosticId(...)-0%0%
CreateScope(...)-92.86%87.5%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Collections.Generic;
 5using System.Threading.Tasks;
 6using Azure.Core.Pipeline;
 7
 8namespace Azure.Messaging.ServiceBus.Diagnostics
 9{
 10    /// <summary>
 11    ///   Enables diagnostics instrumentation to be applied to <see cref="ServiceBusMessage" />
 12    ///   instances.
 13    /// </summary>
 14    ///
 15    internal class EntityScopeFactory
 16    {
 17        /// <summary>The namespace used for the Service Bus diagnostic scope.</summary>
 18        public const string DiagnosticNamespace = "Azure.Messaging.ServiceBus";
 19
 20        /// <summary>The namespace used for the Azure Resource Manager provider namespace.</summary>
 21        private const string _resourceProviderNamespace = "Microsoft.ServiceBus";
 22        private readonly string _entityPath;
 23        private readonly string _fullyQualifiedNamespace;
 24
 25        /// <summary>
 26        ///   The client diagnostics instance responsible for managing scope.
 27        /// </summary>
 28        ///
 9429        private static DiagnosticScopeFactory _scopeFactory { get; } = new DiagnosticScopeFactory(DiagnosticNamespace, _
 30
 12231        public EntityScopeFactory(
 12232            string entityPath,
 12233            string fullyQualifiedNamespace)
 34        {
 12235            _entityPath = entityPath;
 12236            _fullyQualifiedNamespace = fullyQualifiedNamespace;
 12237        }
 38
 39        /// <summary>
 40        ///   Extracts a diagnostic id from a message's properties.
 41        /// </summary>
 42        ///
 43        /// <param name="properties">The properties holding the diagnostic id.</param>
 44        /// <param name="id">The value of the diagnostics identifier assigned to the event. </param>
 45        ///
 46        /// <returns><c>true</c> if the event was contained the diagnostic id; otherwise, <c>false</c>.</returns>
 47        ///
 48        public static bool TryExtractDiagnosticId(IDictionary<string, object> properties, out string id)
 49        {
 050            id = null;
 51
 052            if (properties.TryGetValue(DiagnosticProperty.DiagnosticIdAttribute, out var objectId) && objectId is string
 53            {
 054                id = stringId;
 055                return true;
 56            }
 57
 058            return false;
 59        }
 60
 61        public DiagnosticScope CreateScope(
 62            string activityName,
 63            string kindAttribute = default,
 64            string lockToken = default,
 65            string sessionId = default,
 66            int? requestedMessageCount = default)
 67        {
 9268            DiagnosticScope scope = _scopeFactory.CreateScope(activityName);
 9269            scope.AddAttribute(DiagnosticProperty.KindAttribute, kindAttribute ?? DiagnosticProperty.ClientKind);
 9270            scope.AddAttribute(
 9271                DiagnosticProperty.ServiceContextAttribute,
 9272                DiagnosticProperty.ServiceBusServiceContext);
 9273            scope.AddAttribute(DiagnosticProperty.EntityAttribute, _entityPath);
 9274            scope.AddAttribute(DiagnosticProperty.EndpointAttribute, _fullyQualifiedNamespace);
 9275            if (lockToken != null)
 76            {
 2077                scope.AddAttribute(DiagnosticProperty.LockTokensAttribute, lockToken);
 78            }
 9279            if (sessionId != null)
 80            {
 081                scope.AddAttribute(DiagnosticProperty.SessionIdAttribute, sessionId);
 82            }
 9283            if (requestedMessageCount != null)
 84            {
 2085                scope.AddAttribute(DiagnosticProperty.RequestedMessageCountAttribute, requestedMessageCount);
 86            }
 9287            return scope;
 88        }
 89    }
 90}