private void FullFwAssertValid(Api.System system) { system.Should().NotBeNull(); system.DetectedHostName.Should().Be(new SystemInfoHelper(LoggerBase).GetHostName()); system.HostName.Should().Be(system.DetectedHostName); }
private void FullFwAssertValid(Api.System system) { system.Should().NotBeNull(); system.DetectedHostName.Should().Be(new SystemInfoHelper(LoggerBase).GetHostName()); #pragma warning disable 618 system.HostName.Should().Be(AgentConfig.HostName ?? system.DetectedHostName); #pragma warning restore 618 }
public PayloadSenderV2(IApmLogger logger, IConfigurationReader configurationReader, Service service, Api.System system, HttpMessageHandler handler = null ) { _service = service; _system = system; _metadata = new Metadata { Service = _service, System = _system }; _logger = logger?.Scoped(nameof(PayloadSenderV2)); var serverUrlBase = configurationReader.ServerUrls.First(); var servicePoint = ServicePointManager.FindServicePoint(serverUrlBase); servicePoint.ConnectionLeaseTimeout = DnsTimeout; servicePoint.ConnectionLimit = 20; _httpClient = new HttpClient(handler ?? new HttpClientHandler()) { BaseAddress = serverUrlBase }; _httpClient.DefaultRequestHeaders.UserAgent.Add( new ProductInfoHeaderValue($"elasticapm-{Consts.AgentName}", AdaptUserAgentValue(_service.Agent.Version))); _httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("System.Net.Http", AdaptUserAgentValue(typeof(HttpClient).Assembly.GetCustomAttribute <AssemblyFileVersionAttribute>().Version))); _httpClient.DefaultRequestHeaders.UserAgent.Add( new ProductInfoHeaderValue(AdaptUserAgentValue(_service.Runtime.Name), AdaptUserAgentValue(_service.Runtime.Version))); if (configurationReader.SecretToken != null) { _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", configurationReader.SecretToken); } Task.Factory.StartNew( () => { try { #pragma warning disable 4014 DoWork(); #pragma warning restore 4014 } catch (TaskCanceledException ex) { _logger?.Debug()?.LogExceptionWithCaller(ex); } }, CancellationToken.None, TaskCreationOptions.LongRunning, _singleThreadTaskScheduler); // Replace invalid characters by underscore. All invalid characters can be found at // https://github.com/dotnet/corefx/blob/e64cac6dcacf996f98f0b3f75fb7ad0c12f588f7/src/System.Net.Http/src/System/Net/Http/HttpRuleParser.cs#L41 string AdaptUserAgentValue(string value) => Regex.Replace(value, "[ /()<>@,:;={}?\\[\\]\"\\\\]", "_"); }
public PayloadSenderV2(IApmLogger logger, IConfigSnapshot config, Service service, Api.System system, HttpMessageHandler httpMessageHandler = null, string dbgName = null ) : base(/* isEnabled: */ true, logger, ThisClassName, service, config, httpMessageHandler) { _logger = logger?.Scoped(ThisClassName + (dbgName == null ? "" : $" (dbgName: `{dbgName}')")); _payloadItemSerializer = new PayloadItemSerializer(config); _intakeV2EventsAbsoluteUrl = BackendCommUtils.ApmServerEndpoints.BuildIntakeV2EventsAbsoluteUrl(config.ServerUrls.First()); System = system; _metadata = new Metadata { Service = service, System = System }; foreach (var globalLabelKeyValue in config.GlobalLabels) { _metadata.Labels.Add(globalLabelKeyValue.Key, globalLabelKeyValue.Value); } if (config.MaxQueueEventCount < config.MaxBatchEventCount) { _logger?.Error() ?.Log( "MaxQueueEventCount is less than MaxBatchEventCount - using MaxBatchEventCount as MaxQueueEventCount." + " MaxQueueEventCount: {MaxQueueEventCount}." + " MaxBatchEventCount: {MaxBatchEventCount}.", config.MaxQueueEventCount, config.MaxBatchEventCount); _maxQueueEventCount = config.MaxBatchEventCount; } else { _maxQueueEventCount = config.MaxQueueEventCount; } _flushInterval = config.FlushInterval; _logger?.Debug() ?.Log( "Using the following configuration options:" + " Events intake API absolute URL: {EventsIntakeAbsoluteUrl}" + ", FlushInterval: {FlushInterval}" + ", MaxBatchEventCount: {MaxBatchEventCount}" + ", MaxQueueEventCount: {MaxQueueEventCount}" , _intakeV2EventsAbsoluteUrl, _flushInterval.ToHms(), config.MaxBatchEventCount, _maxQueueEventCount); _eventQueue = new BatchBlock <object>(config.MaxBatchEventCount); TransactionFilters.Add(new TransactionIgnoreUrlsFilter(config).Filter); StartWorkLoop(); }
public PayloadSenderV2(IApmLogger logger, IConfigSnapshot config, Service service, Api.System system, HttpMessageHandler httpMessageHandler = null, string dbgName = null ) : base(/* isEnabled: */ true, logger, ThisClassName, service, config, httpMessageHandler) { _logger = logger?.Scoped(ThisClassName + (dbgName == null ? "" : $" (dbgName: `{dbgName}')")); System = system; _metadata = new Metadata { Service = service, System = System }; if (config.MaxQueueEventCount < config.MaxBatchEventCount) { _logger?.Error() ?.Log( "MaxQueueEventCount is less than MaxBatchEventCount - using MaxBatchEventCount as MaxQueueEventCount." + " MaxQueueEventCount: {MaxQueueEventCount}." + " MaxBatchEventCount: {MaxBatchEventCount}.", config.MaxQueueEventCount, config.MaxBatchEventCount); _maxQueueEventCount = config.MaxBatchEventCount; } else { _maxQueueEventCount = config.MaxQueueEventCount; } _flushInterval = config.FlushInterval; _logger?.Debug() ?.Log( "Using the following configuration options:" + " FlushInterval: {FlushInterval}" + ", MaxBatchEventCount: {MaxBatchEventCount}" + ", MaxQueueEventCount: {MaxQueueEventCount}" , _flushInterval.ToHms(), config.MaxBatchEventCount, _maxQueueEventCount); _eventQueue = new BatchBlock <object>(config.MaxBatchEventCount); StartWorkLoop(); }
public PayloadSenderV2(IApmLogger logger, IConfigurationReader configurationReader, Service service, Api.System system, HttpMessageHandler handler = null) { _service = service; _system = system; _metadata = new Metadata { Service = _service, System = _system }; _logger = logger?.Scoped(nameof(PayloadSenderV2)); var serverUrlBase = configurationReader.ServerUrls.First(); var servicePoint = ServicePointManager.FindServicePoint(serverUrlBase); servicePoint.ConnectionLeaseTimeout = DnsTimeout; servicePoint.ConnectionLimit = 20; _httpClient = new HttpClient(handler ?? new HttpClientHandler()) { BaseAddress = serverUrlBase }; if (configurationReader.SecretToken != null) { _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", configurationReader.SecretToken); } Task.Factory.StartNew( () => { try { #pragma warning disable 4014 DoWork(); #pragma warning restore 4014 } catch (TaskCanceledException ex) { _logger?.Debug()?.LogExceptionWithCaller(ex); } }, CancellationToken.None, TaskCreationOptions.LongRunning, _singleThreadTaskScheduler); }
internal static void AssertValid(this Api.System thisObj) { thisObj.Should().NotBeNull(); thisObj.Container?.AssertValid(); }
public PayloadSenderV2( IApmLogger logger, IConfigSnapshot config, Service service, Api.System system, IApmServerInfo apmServerInfo, HttpMessageHandler httpMessageHandler = null, string dbgName = null, bool isEnabled = true, IEnvironmentVariables environmentVariables = null ) : base(isEnabled, logger, ThisClassName, service, config, httpMessageHandler) { if (!isEnabled) { return; } _logger = logger?.Scoped(ThisClassName + (dbgName == null ? "" : $" (dbgName: `{dbgName}')")); _payloadItemSerializer = new PayloadItemSerializer(); _configSnapshot = config; _intakeV2EventsAbsoluteUrl = BackendCommUtils.ApmServerEndpoints.BuildIntakeV2EventsAbsoluteUrl(config.ServerUrl); System = system; _cloudMetadataProviderCollection = new CloudMetadataProviderCollection(config.CloudProvider, _logger, environmentVariables); _apmServerInfo = apmServerInfo; _metadata = new Metadata { Service = service, System = System }; foreach (var globalLabelKeyValue in config.GlobalLabels) { _metadata.Labels.Add(globalLabelKeyValue.Key, globalLabelKeyValue.Value); } if (config.MaxQueueEventCount < config.MaxBatchEventCount) { _logger?.Error() ?.Log( "MaxQueueEventCount is less than MaxBatchEventCount - using MaxBatchEventCount as MaxQueueEventCount." + " MaxQueueEventCount: {MaxQueueEventCount}." + " MaxBatchEventCount: {MaxBatchEventCount}.", config.MaxQueueEventCount, config.MaxBatchEventCount); _maxQueueEventCount = config.MaxBatchEventCount; } else { _maxQueueEventCount = config.MaxQueueEventCount; } _flushInterval = config.FlushInterval; _logger?.Debug() ?.Log( "Using the following configuration options:" + " Events intake API absolute URL: {EventsIntakeAbsoluteUrl}" + ", FlushInterval: {FlushInterval}" + ", MaxBatchEventCount: {MaxBatchEventCount}" + ", MaxQueueEventCount: {MaxQueueEventCount}" , _intakeV2EventsAbsoluteUrl, _flushInterval.ToHms(), config.MaxBatchEventCount, _maxQueueEventCount); _eventQueue = new BatchBlock <object>(config.MaxBatchEventCount); SetUpFilters(TransactionFilters, SpanFilters, ErrorFilters, apmServerInfo, logger); StartWorkLoop(); }
private void FullFwAssertValid(Api.System system) => system.Should().BeNull();
public PayloadSenderV2(IApmLogger logger, IConfigurationReader configurationReader, Service service, Api.System system, HttpMessageHandler handler = null ) { _logger = logger?.Scoped(ThisClassName); System = system; _metadata = new Metadata { Service = service, System = System }; if (configurationReader.MaxQueueEventCount < configurationReader.MaxBatchEventCount) { _logger?.Error() ?.Log( "MaxQueueEventCount is less than MaxBatchEventCount - using MaxBatchEventCount as MaxQueueEventCount." + " MaxQueueEventCount: {MaxQueueEventCount}." + " MaxBatchEventCount: {MaxBatchEventCount}.", configurationReader.MaxQueueEventCount, configurationReader.MaxBatchEventCount); _maxQueueEventCount = configurationReader.MaxBatchEventCount; } else { _maxQueueEventCount = configurationReader.MaxQueueEventCount; } _flushInterval = configurationReader.FlushInterval; _eventQueue = new BatchBlock <object>(configurationReader.MaxBatchEventCount); _cancellationTokenSource = new CancellationTokenSource(); _singleThreadTaskScheduler = new SingleThreadTaskScheduler(logger, _cancellationTokenSource.Token); var serverUrlBase = configurationReader.ServerUrls.First(); var servicePoint = ServicePointManager.FindServicePoint(serverUrlBase); try { servicePoint.ConnectionLeaseTimeout = DnsTimeout; } catch (Exception e) { _logger.Warning() ?.LogException(e, "Failed setting servicePoint.ConnectionLeaseTimeout - default ConnectionLeaseTimeout from HttpClient will be used. " + "Unless you notice connection issues between the APM Server and the agent, no action needed."); } servicePoint.ConnectionLimit = 20; _logger?.Debug()?.Log("Setting HTTP client BaseAddress to {ApmServerUrl}...", serverUrlBase); _httpClient = new HttpClient(handler ?? new HttpClientHandler()) { BaseAddress = serverUrlBase }; _httpClient.DefaultRequestHeaders.UserAgent.Add( new ProductInfoHeaderValue($"elasticapm-{Consts.AgentName}", AdaptUserAgentValue(service.Agent.Version))); _httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("System.Net.Http", AdaptUserAgentValue(typeof(HttpClient).Assembly.GetCustomAttribute <AssemblyFileVersionAttribute>().Version))); _httpClient.DefaultRequestHeaders.UserAgent.Add( new ProductInfoHeaderValue(AdaptUserAgentValue(service.Runtime.Name), AdaptUserAgentValue(service.Runtime.Version))); if (configurationReader.SecretToken != null) { _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", configurationReader.SecretToken); } #pragma warning disable 4014 Task.Factory.StartNew(DoWork, _cancellationTokenSource.Token, TaskCreationOptions.LongRunning, _singleThreadTaskScheduler); #pragma warning restore 4014 _logger.Debug()?.Log("Enqueued " + ThisClassName + "." + nameof(DoWork)); // Replace invalid characters by underscore. All invalid characters can be found at // https://github.com/dotnet/corefx/blob/e64cac6dcacf996f98f0b3f75fb7ad0c12f588f7/src/System.Net.Http/src/System/Net/Http/HttpRuleParser.cs#L41 string AdaptUserAgentValue(string value) { return(Regex.Replace(value, "[ /()<>@,:;={}?\\[\\]\"\\\\]", "_")); } }