Exemple #1
0
        internal AgentComponents(
            IApmLogger logger,
            IConfigurationReader configurationReader,
            IPayloadSender payloadSender,
            IMetricsCollector metricsCollector,
            ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer,
            ICentralConfigFetcher centralConfigFetcher
            )
        {
            var tempLogger = logger ?? ConsoleLogger.LoggerOrDefault(configurationReader?.LogLevel);

            ConfigurationReader = configurationReader ?? new EnvironmentConfigurationReader(tempLogger);
            Logger  = logger ?? ConsoleLogger.LoggerOrDefault(ConfigurationReader.LogLevel);
            Service = Service.GetDefaultService(ConfigurationReader, Logger);

            var systemInfoHelper = new SystemInfoHelper(Logger);
            var system           = systemInfoHelper.ParseSystemInfo();

            ConfigStore = new ConfigStore(new ConfigSnapshotFromReader(ConfigurationReader, "local"), Logger);

            PayloadSender = payloadSender ?? new PayloadSenderV2(Logger, ConfigStore.CurrentSnapshot, Service, system);

            MetricsCollector = metricsCollector ?? new MetricsCollector(Logger, PayloadSender, ConfigurationReader);
            MetricsCollector.StartCollecting();

            CentralConfigFetcher = centralConfigFetcher ?? new CentralConfigFetcher(Logger, ConfigStore, Service);

            TracerInternal = new Tracer(Logger, Service, PayloadSender, ConfigStore,
                                        currentExecutionSegmentsContainer ?? new CurrentExecutionSegmentsContainer());
        }
        internal AgentComponents(
            IApmLogger logger,
            IConfigurationReader configurationReader,
            IPayloadSender payloadSender,
            IMetricsCollector metricsCollector,
            ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer,
            ICentralConfigFetcher centralConfigFetcher,
            IApmServerInfo apmServerInfo,
            BreakdownMetricsProvider breakdownMetricsProvider = null
            )
        {
            try
            {
                var tempLogger = logger ?? ConsoleLogger.LoggerOrDefault(configurationReader?.LogLevel);
                ConfigurationReader = configurationReader ?? new EnvironmentConfigurationReader(tempLogger);
                Logger  = logger ?? ConsoleLogger.LoggerOrDefault(ConfigurationReader.LogLevel);
                Service = Service.GetDefaultService(ConfigurationReader, Logger);

                var systemInfoHelper = new SystemInfoHelper(Logger);
                var system           = systemInfoHelper.ParseSystemInfo(ConfigurationReader.HostName);

                ConfigStore = new ConfigStore(new ConfigSnapshotFromReader(ConfigurationReader, "local"), Logger);

                ApmServerInfo = apmServerInfo ?? new ApmServerInfo();

                PayloadSender = payloadSender
                                ?? new PayloadSenderV2(Logger, ConfigStore.CurrentSnapshot, Service, system, ApmServerInfo,
                                                       isEnabled: ConfigurationReader.Enabled);

                HttpTraceConfiguration = new HttpTraceConfiguration();

                if (ConfigurationReader.Enabled)
                {
                    breakdownMetricsProvider ??= new BreakdownMetricsProvider(Logger);

                    CentralConfigFetcher = centralConfigFetcher ?? new CentralConfigFetcher(Logger, ConfigStore, Service);
                    MetricsCollector     = metricsCollector ?? new MetricsCollector(Logger, PayloadSender, ConfigStore, breakdownMetricsProvider);
                    MetricsCollector.StartCollecting();
                }
                else
                {
                    Logger.Info()?.Log("The Elastic APM .NET Agent is disabled - the agent won't capture traces and metrics.");
                }

                TracerInternal = new Tracer(Logger, Service, PayloadSender, ConfigStore,
                                            currentExecutionSegmentsContainer ?? new CurrentExecutionSegmentsContainer(), ApmServerInfo, breakdownMetricsProvider);
            }
            catch (Exception e)
            {
                Logger.Error()?.LogException(e, "Failed initializing agent.");
            }
        }
        public void System_Should_Serialize_ConfiguredHostName_And_DetectedHostName()
        {
            var systemHelper = new SystemInfoHelper(new NoopLogger());

            var hostName = "this_is_my_hostname";
            var system   = systemHelper.ParseSystemInfo(hostName);

            var json    = _payloadItemSerializer.Serialize(system);
            var jObject = JObject.Parse(json);

            var configuredHostName = jObject.Property("configured_hostname");

            configuredHostName.Should().NotBeNull();
            configuredHostName.Value.Value <string>().Should().Be(hostName);

            var detectedHostName = jObject.Property("detected_hostname");

            detectedHostName.Should().NotBeNull();
        }