Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExporterSettings"/> class.
        /// Direct use in tests only.
        /// </summary>
        /// <param name="source">The <see cref="IConfigurationSource"/> to use when retrieving configuration values.</param>
        public ExporterSettings(IConfigurationSource source)
        {
            ValidationWarnings = new List <string>();

            // Get values from the config
            var endpointUrl = source?.GetString(ConfigurationKeys.EndpointUrl);

            var tracesPipeName = source?.GetString(ConfigurationKeys.TracesPipeName);

            var tracesPipeTimeoutMs = source?.GetInt32(ConfigurationKeys.TracesPipeTimeoutMs) ?? 0;

            var agentPort = source?.GetInt32(ConfigurationKeys.AgentPort);

            var ingestRealm = source?.GetString(ConfigurationKeys.IngestRealm) ??
                              LocalIngestRealm;

            var dogStatsdPort   = source?.GetInt32(ConfigurationKeys.DogStatsdPort) ?? 0;
            var metricsPipeName = source?.GetString(ConfigurationKeys.MetricsPipeName);

            ConfigureTraceTransport(endpointUrl, tracesPipeName, agentPort, ingestRealm);

            MetricsExporter = source.GetTypedValue <MetricsExporterType>(ConfigurationKeys.MetricsExporter);
            if (MetricsExporter == MetricsExporterType.SignalFx)
            {
                MetricsEndpointUrl = source.SafeReadUri(
                    key: ConfigurationKeys.MetricsEndpointUrl,
                    defaultTo: GetConfiguredMetricsEndpoint(ingestRealm),
                    out _);
            }
            else
            {
                ConfigureStatsdMetricsTransport(endpointUrl, dogStatsdPort, metricsPipeName);
            }

            ConfigureLogsTransport(source);

            TracesPipeTimeoutMs = tracesPipeTimeoutMs > 0 ? tracesPipeTimeoutMs : 500;
            PartialFlushEnabled = source?.GetBool(ConfigurationKeys.PartialFlushEnabled) ?? false;

            PartialFlushMinSpans = source.SafeReadInt32(
                key: ConfigurationKeys.PartialFlushMinSpans,
                defaultTo: 500,
                validators: (val) => val > 0);
            SyncExport = source?.GetBool(ConfigurationKeys.TraceSyncExport) ?? false;

            var stringProfileExportFormat = source?.GetString(ConfigurationKeys.AlwaysOnProfiler.ExportFormat);

            if (string.IsNullOrEmpty(stringProfileExportFormat))
            {
                ProfilerExportFormat = ProfilerExportFormat.Pprof;
            }
            else if (Enum.TryParse(stringProfileExportFormat, out ProfilerExportFormat profilerExportFormat))
            {
                ProfilerExportFormat = profilerExportFormat;
            }
            else
            {
                Log.Logger.Warning("Unknown {0} passed: {1}, using {2} as a default", ConfigurationKeys.AlwaysOnProfiler.ExportFormat, stringProfileExportFormat, ProfilerExportFormat.Pprof);
                ProfilerExportFormat = ProfilerExportFormat.Pprof;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TracerSettings"/> class
        /// using the specified <see cref="IConfigurationSource"/> to initialize values.
        /// </summary>
        /// <param name="source">The <see cref="IConfigurationSource"/> to use when retrieving configuration values.</param>
        public TracerSettings(IConfigurationSource source)
        {
            Environment = source?.GetString(ConfigurationKeys.Environment);

            ServiceName = source?.GetString(ConfigurationKeys.ServiceName);

            ServiceVersion = source?.GetString(ConfigurationKeys.ServiceVersion);

            SignalFxAccessToken = source?.GetString(ConfigurationKeys.SignalFxAccessToken);

            TraceEnabled = source?.GetBool(ConfigurationKeys.TraceEnabled) ??
                           // default value
                           true;

            if (AzureAppServices.Metadata.IsRelevant && AzureAppServices.Metadata.IsUnsafeToTrace)
            {
                TraceEnabled = false;
            }

            DisabledIntegrationNames = new HashSet <string>(source.GetStrings(ConfigurationKeys.DisabledIntegrations), StringComparer.OrdinalIgnoreCase);

            Integrations = new IntegrationSettingsCollection(source);

            ExporterSettings = new ExporterSettings(source);

#pragma warning disable 618 // App analytics is deprecated, but still used
            AnalyticsEnabled = source?.GetBool(ConfigurationKeys.GlobalAnalyticsEnabled) ??
                            // default value
                               false;
#pragma warning restore 618

            MaxTracesSubmittedPerSecond = source?.GetInt32(ConfigurationKeys.TraceRateLimit) ??
                                          // default value
                                          100;

            GlobalTags = source?.GetDictionary(ConfigurationKeys.GlobalTags) ??
                         // default value (empty)
                         new ConcurrentDictionary <string, string>();

            // Filter out tags with empty keys or empty values, and trim whitespace
            GlobalTags = GlobalTags.Where(kvp => !string.IsNullOrWhiteSpace(kvp.Key) && !string.IsNullOrWhiteSpace(kvp.Value))
                         .ToDictionary(kvp => kvp.Key.Trim(), kvp => kvp.Value.Trim());

            var inputHeaderTags = source?.GetDictionary(ConfigurationKeys.HeaderTags, allowOptionalMappings: true) ??
                                  // default value (empty)
                                  new Dictionary <string, string>();

            var headerTagsNormalizationFixEnabled = source?.GetBool(ConfigurationKeys.FeatureFlags.HeaderTagsNormalizationFixEnabled) ?? true;
            // Filter out tags with empty keys or empty values, and trim whitespaces
            HeaderTags = InitializeHeaderTags(inputHeaderTags, headerTagsNormalizationFixEnabled);

            var serviceNameMappings = source?.GetDictionary(ConfigurationKeys.ServiceNameMappings)
                                      ?.Where(kvp => !string.IsNullOrWhiteSpace(kvp.Key) && !string.IsNullOrWhiteSpace(kvp.Value))
                                      ?.ToDictionary(kvp => kvp.Key.Trim(), kvp => kvp.Value.Trim());

            ServiceNameMappings = new ServiceNames(serviceNameMappings);

            TracerMetricsEnabled = source?.GetBool(ConfigurationKeys.TracerMetricsEnabled) ??
                                   // default value
                                   false;

            TagRedisCommands = source?.GetBool(ConfigurationKeys.TagRedisCommands) ??
                               // default value
                               true;

            RuntimeMetricsEnabled = source?.GetBool(ConfigurationKeys.RuntimeMetricsEnabled) ??
                                    false;

            CustomSamplingRules = source?.GetString(ConfigurationKeys.CustomSamplingRules);

            GlobalSamplingRate = source?.GetDouble(ConfigurationKeys.GlobalSamplingRate);

            StartupDiagnosticLogEnabled = source?.GetBool(ConfigurationKeys.StartupDiagnosticLogEnabled) ??
                                          // default value
                                          true;

            Exporter = source.GetTypedValue <ExporterType>(ConfigurationKeys.Exporter);

            Convention = source.GetTypedValue <ConventionType>(ConfigurationKeys.Convention);

            var urlSubstringSkips = source?.GetString(ConfigurationKeys.HttpClientExcludedUrlSubstrings) ??
                                    // default value
                                    (AzureAppServices.Metadata.IsRelevant ? AzureAppServices.Metadata.DefaultHttpClientExclusions : null);

            if (urlSubstringSkips != null)
            {
                HttpClientExcludedUrlSubstrings = TrimSplitString(urlSubstringSkips.ToUpperInvariant(), ',').ToArray();
            }

            var httpServerErrorStatusCodes = source?.GetString(ConfigurationKeys.HttpServerErrorStatusCodes) ??
                                             // Default value
                                             "500-599";

            HttpServerErrorStatusCodes = ParseHttpCodesToArray(httpServerErrorStatusCodes);

            var httpClientErrorStatusCodes = source?.GetString(ConfigurationKeys.HttpClientErrorStatusCodes) ??
                                             // Default value
                                             "400-599";
            HttpClientErrorStatusCodes = ParseHttpCodesToArray(httpClientErrorStatusCodes);

            TraceBufferSize = source?.GetInt32(ConfigurationKeys.BufferSize)
                              ?? 1024 * 1024 * 10; // 10MB

            TraceBatchInterval = source?.GetInt32(ConfigurationKeys.SerializationBatchInterval)
                                 ?? 100;

            RecordedValueMaxLength = source.SafeReadInt32(
                key: ConfigurationKeys.RecordedValueMaxLength,
                defaultTo: DefaultRecordedValueMaxLength,
                validators: (value) => value >= 0);

            RouteTemplateResourceNamesEnabled = source?.GetBool(ConfigurationKeys.FeatureFlags.RouteTemplateResourceNamesEnabled)
                                                ?? true;

            TraceResponseHeaderEnabled = source?.GetBool(ConfigurationKeys.TraceResponseHeaderEnabled)
                                         ?? true;
            ExpandRouteTemplatesEnabled = source?.GetBool(ConfigurationKeys.ExpandRouteTemplatesEnabled)
                                          // disabled by default if route template resource names enabled
                                          ?? !RouteTemplateResourceNamesEnabled;

            KafkaCreateConsumerScopeEnabled = source?.GetBool(ConfigurationKeys.KafkaCreateConsumerScopeEnabled)
                                              ?? true; // default

            TagMongoCommands = source?.GetBool(ConfigurationKeys.TagMongoCommands) ?? true;

            DelayWcfInstrumentationEnabled = source?.GetBool(ConfigurationKeys.FeatureFlags.DelayWcfInstrumentationEnabled)
                                             ?? false;

            PropagationStyleInject = TrimSplitString(source?.GetString(ConfigurationKeys.Propagators) ?? $"{nameof(Propagators.ContextPropagators.Names.B3)},{nameof(Propagators.ContextPropagators.Names.W3C)}", ',').ToArray();

            PropagationStyleExtract = PropagationStyleInject;

            TagElasticsearchQueries = source?.GetBool(ConfigurationKeys.TagElasticsearchQueries) ?? true;

            // If you change this, change environment_variables.h too
            ThreadSamplingEnabled = source?.GetBool(ConfigurationKeys.AlwaysOnProfiler.Enabled) ?? false;
            ThreadSamplingPeriod  = GetThreadSamplingPeriod(source);

            LogSubmissionSettings = new DirectLogSubmissionSettings(source);

            TraceMethods = source?.GetString(ConfigurationKeys.TraceMethods) ??
                           // Default value
                           string.Empty;

            var grpcTags = source?.GetDictionary(ConfigurationKeys.GrpcTags, allowOptionalMappings: true) ??
                           // default value (empty)
                           new Dictionary <string, string>();

            // Filter out tags with empty keys or empty values, and trim whitespaces
            GrpcTags = InitializeHeaderTags(grpcTags, headerTagsNormalizationFixEnabled: true);

            IsActivityListenerEnabled = source?.GetBool(ConfigurationKeys.FeatureFlags.ActivityListenerEnabled) ??
                                        // default value
                                        false;

            if (IsActivityListenerEnabled)
            {
                // If the activities support is activated, we must enable W3C propagators
                if (!Array.Exists(PropagationStyleExtract, key => string.Equals(key, nameof(Propagators.ContextPropagators.Names.W3C), StringComparison.OrdinalIgnoreCase)))
                {
                    PropagationStyleExtract = PropagationStyleExtract.Concat(nameof(Propagators.ContextPropagators.Names.W3C));
                }

                if (!Array.Exists(PropagationStyleInject, key => string.Equals(key, nameof(Propagators.ContextPropagators.Names.W3C), StringComparison.OrdinalIgnoreCase)))
                {
                    PropagationStyleInject = PropagationStyleInject.Concat(nameof(Propagators.ContextPropagators.Names.W3C));
                }
            }
        }