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;
            }
        }