Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BatchingActivityProcessor"/> class with custom settings.
        /// </summary>
        /// <param name="exporter">Exporter instance.</param>
        /// <param name="maxQueueSize">Maximum queue size. After the size is reached activities are dropped by processor.</param>
        /// <param name="scheduledDelay">The delay between two consecutive exports.</param>
        /// <param name="exporterTimeout">Maximum allowed time to export data.</param>
        /// <param name="maxExportBatchSize">The maximum batch size of every export. It must be smaller or equal to maxQueueSize.</param>
        public BatchingActivityProcessor(ActivityExporter exporter, int maxQueueSize, TimeSpan scheduledDelay, TimeSpan exporterTimeout, int maxExportBatchSize)
        {
            if (maxQueueSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxQueueSize));
            }

            if (maxExportBatchSize <= 0 || maxExportBatchSize > maxQueueSize)
            {
                throw new ArgumentOutOfRangeException(nameof(maxExportBatchSize));
            }

            if (scheduledDelay <= TimeSpan.FromMilliseconds(0))
            {
                throw new ArgumentOutOfRangeException(nameof(scheduledDelay));
            }

            this.exporter           = exporter ?? throw new ArgumentNullException(nameof(exporter));
            this.maxQueueSize       = maxQueueSize;
            this.scheduledDelay     = scheduledDelay;
            this.exporterTimeout    = exporterTimeout;
            this.maxExportBatchSize = maxExportBatchSize;

            this.exportQueue = new ConcurrentQueue <Activity>();

            this.flushTimer = new System.Timers.Timer
            {
                AutoReset = false,
                Enabled   = true,
                Interval  = this.scheduledDelay.TotalMilliseconds,
            };

            this.flushTimer.Elapsed += async(sender, args) =>
            {
                bool lockTaken = this.flushLock.Wait(0);
                try
                {
                    if (!lockTaken)
                    {
                        // If the lock was already held, it means a flush is already executing.
                        return;
                    }

                    await this.FlushAsyncInternal(drain : false, lockAlreadyHeld : true, CancellationToken.None).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    OpenTelemetrySdkEventSource.Log.SpanProcessorException(nameof(System.Timers.Timer.Elapsed), ex);
                }
                finally
                {
                    if (lockTaken)
                    {
                        this.flushLock.Release();
                    }
                }
            };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BatchExportActivityProcessor"/> class.
        /// </summary>
        /// <param name="exporter">Exporter instance.</param>
        /// <param name="maxQueueSize">The maximum queue size. After the size is reached data are dropped. The default value is 2048.</param>
        /// <param name="scheduledDelayMilliseconds">The delay interval in milliseconds between two consecutive exports. The default value is 5000.</param>
        /// <param name="exporterTimeoutMilliseconds">How long the export can run before it is cancelled. The default value is 30000.</param>
        /// <param name="maxExportBatchSize">The maximum batch size of every export. It must be smaller or equal to maxQueueSize. The default value is 512.</param>
        public BatchExportActivityProcessor(
            ActivityExporter exporter,
            int maxQueueSize = 2048,
            int scheduledDelayMilliseconds  = 5000,
            int exporterTimeoutMilliseconds = 30000,
            int maxExportBatchSize          = 512)
            : base(exporter)
        {
            if (maxQueueSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxQueueSize));
            }

            if (maxExportBatchSize <= 0 || maxExportBatchSize > maxQueueSize)
            {
                throw new ArgumentOutOfRangeException(nameof(maxExportBatchSize));
            }

            if (scheduledDelayMilliseconds <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(scheduledDelayMilliseconds));
            }

            if (exporterTimeoutMilliseconds < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(exporterTimeoutMilliseconds));
            }

            this.circularBuffer              = new CircularBuffer <Activity>(maxQueueSize);
            this.scheduledDelayMilliseconds  = scheduledDelayMilliseconds;
            this.exporterTimeoutMilliseconds = exporterTimeoutMilliseconds;
            this.maxExportBatchSize          = maxExportBatchSize;
            this.exporterThread              = new Thread(new ThreadStart(this.ExporterProc))
            {
                IsBackground = true,
                Name         = $"OpenTelemetry-{nameof(BatchExportActivityProcessor)}-{exporter.GetType().Name}",
            };
            this.exporterThread.Start();
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleExportActivityProcessor"/> class.
 /// </summary>
 /// <param name="exporter">Activity exporter instance.</param>
 public SimpleExportActivityProcessor(ActivityExporter exporter)
     : base(exporter)
 {
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BatchingActivityProcessor"/> class with default parameters:
 /// <list type="bullet">
 /// <item>
 /// <description>maxQueueSize = 2048,</description>
 /// </item>
 /// <item>
 /// <description>scheduledDelay = 5 sec,</description>
 /// </item>
 /// <item>
 /// <description>exporterTimeout = 30 sec,</description>
 /// </item>
 /// <item>
 /// <description>maxExportBatchSize = 512</description>
 /// </item>
 /// </list>
 /// </summary>
 /// <param name="exporter">Exporter instance.</param>
 public BatchingActivityProcessor(ActivityExporter exporter)
     : this(exporter, DefaultMaxQueueSize, DefaultScheduledDelay, DefaultExporterTimeout, DefaultMaxExportBatchSize)
 {
 }
 /// <summary>
 /// Configures exporter.
 /// </summary>
 /// <param name="exporter">Exporter instance.</param>
 /// <returns>Returns <see cref="ActivityProcessorPipelineBuilder"/>.</returns>
 public ActivityProcessorPipelineBuilder SetExporter(ActivityExporter exporter)
 {
     this.Exporter = exporter ?? throw new ArgumentNullException(nameof(exporter));
     return(this);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ReentrantExportActivityProcessor"/> class.
 /// </summary>
 /// <param name="exporter">Activity exporter instance.</param>
 public ReentrantExportActivityProcessor(ActivityExporter exporter)
 {
     this.exporter = exporter ?? throw new ArgumentNullException(nameof(exporter));
 }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReentrantExportActivityProcessor"/> class.
 /// </summary>
 /// <param name="exporter">Activity exporter instance.</param>
 public ReentrantExportActivityProcessor(ActivityExporter exporter)
     : base(exporter)
 {
 }