Beispiel #1
0
        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,
            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();
        }