< Summary

Class:Azure.Core.DiagnosticsOptions
Assembly:Azure.Core
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\DiagnosticsOptions.cs
Covered lines:50
Uncovered lines:2
Coverable lines:52
Total lines:128
Line coverage:96.1% (50 of 52)
Covered branches:18
Total branches:20
Branch coverage:90% (18 of 20)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-100%100%
get_IsLoggingEnabled()-100%100%
get_IsDistributedTracingEnabled()-100%100%
get_IsTelemetryEnabled()-100%100%
get_IsLoggingContentEnabled()-100%100%
get_LoggedContentSizeLimit()-0%100%
get_LoggedHeaderNames()-100%100%
get_LoggedQueryParameters()-100%100%
get_ApplicationId()-100%100%
set_ApplicationId(...)-100%100%
get_DefaultApplicationId()-100%100%
EnvironmentVariableToBool(...)-85.71%75%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\DiagnosticsOptions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Runtime.InteropServices;
 7
 8namespace Azure.Core
 9{
 10    /// <summary>
 11    /// Exposes client options related to logging, telemetry and distributed tracing.
 12    /// </summary>
 13    public class DiagnosticsOptions
 14    {
 15        private const int MaxApplicationIdLength = 24;
 16
 17        private string? _applicationId;
 18
 9619        internal DiagnosticsOptions()
 20        {
 9621            IsTelemetryEnabled = !EnvironmentVariableToBool(Environment.GetEnvironmentVariable("AZURE_TELEMETRY_DISABLED
 9622            IsDistributedTracingEnabled = !EnvironmentVariableToBool(Environment.GetEnvironmentVariable("AZURE_TRACING_D
 9623            ApplicationId = DefaultApplicationId;
 9624            LoggedHeaderNames = new List<string>()
 9625            {
 9626                "x-ms-client-request-id",
 9627                "x-ms-return-client-request-id",
 9628                "traceparent",
 9629
 9630                "Accept",
 9631                "Cache-Control",
 9632                "Connection",
 9633                "Content-Length",
 9634                "Content-Type",
 9635                "Date",
 9636                "ETag",
 9637                "Expires",
 9638                "If-Match",
 9639                "If-Modified-Since",
 9640                "If-None-Match",
 9641                "If-Unmodified-Since",
 9642                "Last-Modified",
 9643                "Pragma",
 9644                "Request-Id",
 9645                "Retry-After",
 9646                "Server",
 9647                "Transfer-Encoding",
 9648                "User-Agent"
 9649            };
 9650            LoggedQueryParameters = new List<string>();
 9651        }
 52
 53        /// <summary>
 54        /// Get or sets value indicating whether HTTP pipeline logging is enabled.
 55        /// </summary>
 15456        public bool IsLoggingEnabled { get; set; } = true;
 57
 58        /// <summary>
 59        /// Gets or sets value indicating whether distributed tracing spans are going to be created for this clients met
 60        /// </summary>
 26061        public bool IsDistributedTracingEnabled { get; set; } = true;
 62
 63        /// <summary>
 64        /// Gets or sets value indicating whether the "User-Agent" header containing <see cref="ApplicationId"/>, client
 65        /// and <see cref="RuntimeInformation.OSDescription"/> should be sent.
 66        /// The default value can be controlled process wide by setting <c>AZURE_TELEMETRY_DISABLED</c> to <c>true</c>, 
 67        /// </summary>
 15868        public bool IsTelemetryEnabled { get; set; }
 69
 70        /// <summary>
 71        /// Gets or sets value indicating if request or response content should be logged.
 72        /// </summary>
 6073        public bool IsLoggingContentEnabled { get; set; }
 74
 75        /// <summary>
 76        /// Gets or sets value indicating maximum size of content to log in bytes. Defaults to 4096.
 77        /// </summary>
 078        public int LoggedContentSizeLimit { get; set; } = 4 * 1024;
 79
 80        /// <summary>
 81        /// Gets a list of headers names that are not redacted during logging.
 82        /// </summary>
 9283        public IList<string> LoggedHeaderNames { get; }
 84
 85        /// <summary>
 86        /// Gets a list of query parameter names that are not redacted during logging.
 87        /// </summary>
 8288        public IList<string> LoggedQueryParameters { get; }
 89
 90        /// <summary>
 91        /// Gets or sets the value sent a the first part of "User-Agent" headers for all requests issues by this client.
 92        /// </summary>
 93        public string? ApplicationId
 94        {
 6095            get => _applicationId;
 96            set
 97            {
 10098                if (value != null && value.Length > MaxApplicationIdLength)
 99                {
 2100                    throw new ArgumentOutOfRangeException(nameof(value), $"{nameof(ApplicationId)} must be shorter than 
 101                }
 98102                _applicationId = value;
 98103            }
 104        }
 105
 106        /// <summary>
 107        /// Gets or sets the default application id. Default application id would be set on all instances.
 108        /// </summary>
 100109        public static string? DefaultApplicationId { get; set; }
 110
 111        private static bool? EnvironmentVariableToBool(string value)
 112        {
 192113            if (string.Equals("true", value, StringComparison.OrdinalIgnoreCase) ||
 192114                string.Equals("1", value, StringComparison.OrdinalIgnoreCase))
 115            {
 12116                return true;
 117            }
 118
 180119            if (string.Equals("false", value, StringComparison.OrdinalIgnoreCase) ||
 180120                string.Equals("0", value, StringComparison.OrdinalIgnoreCase))
 121            {
 0122                return false;
 123            }
 124
 180125            return null;
 126        }
 127    }
 128}