internal AgentComponents(
            IApmLogger logger,
            IConfigurationReader configurationReader,
            IPayloadSender payloadSender,
            IMetricsCollector metricsCollector,
            ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer
            )
        {
            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.ReadContainerId(Logger);

            PayloadSender = payloadSender ?? new PayloadSenderV2(Logger, ConfigurationReader, Service, system);

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

            TracerInternal = new Tracer(Logger, Service, PayloadSender, ConfigurationReader,
                                        currentExecutionSegmentsContainer ?? new CurrentExecutionSegmentsContainer(Logger));
        }
예제 #2
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());
        }
예제 #3
0
        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 AgentComponents(
            IApmLogger logger = null,
            IConfigurationReader configurationReader = null,
            IPayloadSender payloadSender             = null
            )
        {
            Logger = logger ?? ConsoleLogger.LoggerOrDefault(configurationReader?.LogLevel);
            ConfigurationReader = configurationReader ?? new EnvironmentConfigurationReader(Logger);
            Service             = Service.GetDefaultService(ConfigurationReader, Logger);

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

            PayloadSender = payloadSender ?? new PayloadSenderV2(Logger, ConfigurationReader, Service, system);

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

            TracerInternal       = new Tracer(Logger, Service, PayloadSender, ConfigurationReader);
            TransactionContainer = new TransactionContainer();
        }
예제 #5
0
        internal AgentComponents(
            IApmLogger logger,
            IConfigurationReader configurationReader,
            IPayloadSender payloadSender,
            IMetricsCollector metricsCollector,
            ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer,
            ICentralConfigurationFetcher centralConfigurationFetcher,
            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.GetSystemInfo(ConfigurationReader.HostName);

                ConfigurationStore = new ConfigurationStore(new ConfigurationSnapshotFromReader(ConfigurationReader, "local"), Logger);

                ApmServerInfo = apmServerInfo ?? new ApmServerInfo();

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

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

                HttpTraceConfiguration = new HttpTraceConfiguration();
                SubscribedListeners    = new HashSet <Type>();

                // initialize the tracer before central configuration or metric collection is started
                TracerInternal = new Tracer(Logger, Service, PayloadSender, ConfigurationStore,
                                            currentExecutionSegmentsContainer ?? new CurrentExecutionSegmentsContainer(), ApmServerInfo, breakdownMetricsProvider);

                if (ConfigurationReader.Enabled)
                {
                    CentralConfigurationFetcher = centralConfigurationFetcher ?? new CentralConfigurationFetcher(Logger, ConfigurationStore, Service);
                    MetricsCollector            = metricsCollector ?? new MetricsCollector(Logger, PayloadSender, ConfigurationStore, 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, ConfigurationStore,
                                            currentExecutionSegmentsContainer ?? new CurrentExecutionSegmentsContainer(), ApmServerInfo, breakdownMetricsProvider);


                if (ConfigurationReader.EnableOpenTelemetryBridge)
                {
#if NET5_0 || NET6_0
                    if (ApmServerInfo.Version >= new ElasticVersion(7, 16, 0, string.Empty))
                    {
                        new OpenTelemetry.ElasticActivityListener(this, TracerInternal);
                    }
                    else
                    {
                        Logger.Warning()?.Log("OpenTelemetry (Activity) bridge is only supported with APM Server 7.16.0 or newer - bridge won't be enabled..");
                    }
#else
                    Logger.Warning()?.Log("OpenTelemetry (Activity) bridge is only supported on .NET5 or newer - bridge won't be enabled.");
#endif
                }
            }
            catch (Exception e)
            {
                Logger.Error()?.LogException(e, "Failed initializing agent.");
            }
        }
예제 #6
0
        internal AgentComponents(
            IApmLogger logger,
            IConfigurationReader configurationReader,
            IPayloadSender payloadSender,
            IMetricsCollector metricsCollector,
            ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer,
            ICentralConfigurationFetcher centralConfigurationFetcher,
            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.GetSystemInfo(ConfigurationReader.HostName);

                ConfigurationStore = new ConfigurationStore(new ConfigurationSnapshotFromReader(ConfigurationReader, "local"), Logger);

                ApmServerInfo = apmServerInfo ?? new ApmServerInfo();

                // Called by PayloadSenderV2 after the ServerInfo is fetched
                Action <bool, IApmServerInfo> serverInfoCallback = null;

#if NET5_0 || NET6_0
                ElasticActivityListener activityListener = null;
                if (ConfigurationReader.EnableOpenTelemetryBridge)
                {
                    activityListener = new OpenTelemetry.ElasticActivityListener(this);

                    serverInfoCallback = (success, serverInfo) =>
                    {
                        if (success)
                        {
                            if (serverInfo.Version >= new ElasticVersion(7, 16, 0, string.Empty))
                            {
                                Logger.Info()
                                ?.Log("APM Server version ready - OpenTelemetry (Activity) bridge is active. Current Server version: {version}",
                                      serverInfo.Version.ToString());
                            }
                            else
                            {
                                Logger.Warning()
                                ?.Log(
                                    "OpenTelemetry (Activity) bridge is only supported with APM Server 7.16.0 or newer - bridge won't be enabled. Current Server version: {version}",
                                    serverInfo.Version.ToString());
                                activityListener?.Dispose();
                            }
                        }
                        else
                        {
                            Logger.Warning()
                            ?.Log(
                                "Unable to read server version - OpenTelemetry (Activity) bridge is only supported with APM Server 7.16.0 or newer. "
                                + "The bridge remains active, but due to unknown server version it may not work as expected.");
                        }
                    };
                }
#endif
                PayloadSender = payloadSender
                                ?? new PayloadSenderV2(Logger, ConfigurationStore.CurrentSnapshot, Service, system, ApmServerInfo,
                                                       isEnabled: ConfigurationReader.Enabled, serverInfoCallback: serverInfoCallback);

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

                HttpTraceConfiguration = new HttpTraceConfiguration();
                SubscribedListeners    = new HashSet <Type>();

                // initialize the tracer before central configuration or metric collection is started
                TracerInternal = new Tracer(Logger, Service, PayloadSender, ConfigurationStore,
                                            currentExecutionSegmentsContainer ?? new CurrentExecutionSegmentsContainer(), ApmServerInfo, breakdownMetricsProvider);

#if NET5_0 || NET6_0
                if (ConfigurationReader.EnableOpenTelemetryBridge)
                {
                    // If the server version is not known yet, we enable the listener - and then the callback will do the version check once we have the version
                    if (ApmServerInfo.Version == null || ApmServerInfo?.Version == new ElasticVersion(0, 0, 0, null))
                    {
                        activityListener?.Start(TracerInternal);
                    }
                    // Otherwise do a version check
                    else if (ApmServerInfo.Version >= new ElasticVersion(7, 16, 0, string.Empty))
                    {
                        Logger.Info()
                        ?.Log("Starting OpenTelemetry (Activity) bridge");

                        activityListener?.Start(TracerInternal);
                    }
                    else
                    {
                        Logger.Warning()
                        ?.Log(
                            "OpenTelemetry (Activity) bridge is only supported with APM Server 7.16.0 or newer - bridge won't be enabled. Current Server version: {version}",
                            ApmServerInfo.Version.ToString());
                        activityListener?.Dispose();
                    }
                }
#endif

                if (ConfigurationReader.Enabled)
                {
                    CentralConfigurationFetcher = centralConfigurationFetcher ?? new CentralConfigurationFetcher(Logger, ConfigurationStore, Service);
                    MetricsCollector            = metricsCollector ?? new MetricsCollector(Logger, PayloadSender, ConfigurationStore, breakdownMetricsProvider);
                    MetricsCollector.StartCollecting();
                }
                else
                {
                    Logger.Info()?.Log("The Elastic APM .NET Agent is disabled - the agent won't capture traces and metrics.");
                }
            }
            catch (Exception e)
            {
                Logger.Error()?.LogException(e, "Failed initializing agent.");
            }
        }