Beispiel #1
0
        /// <summary>
        /// Attempts to shutdown the TracerProviderSdk, blocks the current thread until
        /// shutdown completed or timed out.
        /// </summary>
        /// <param name="provider">TracerProviderSdk instance on which Shutdown will be called.</param>
        /// <param name="timeoutMilliseconds">
        /// The number of milliseconds to wait, or <c>Timeout.Infinite</c> to
        /// wait indefinitely.
        /// </param>
        /// <returns>
        /// Returns <c>true</c> when shutdown succeeded; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// Thrown when the <c>timeoutMilliseconds</c> is smaller than -1.
        /// </exception>
        /// <remarks>
        /// This function guarantees thread-safety. Only the first call will
        /// win, subsequent calls will be no-op.
        /// </remarks>
        public static bool Shutdown(this TracerProvider provider, int timeoutMilliseconds = Timeout.Infinite)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (provider is TracerProviderSdk tracerProviderSdk)
            {
                if (timeoutMilliseconds < 0 && timeoutMilliseconds != Timeout.Infinite)
                {
                    throw new ArgumentOutOfRangeException(nameof(timeoutMilliseconds), timeoutMilliseconds, "timeoutMilliseconds should be non-negative.");
                }

                if (Interlocked.Increment(ref tracerProviderSdk.ShutdownCount) > 1)
                {
                    return(false); // shutdown already called
                }

                try
                {
                    return(tracerProviderSdk.OnShutdown(timeoutMilliseconds));
                }
                catch (Exception ex)
                {
                    OpenTelemetrySdkEventSource.Log.TracerProviderException(nameof(tracerProviderSdk.OnShutdown), ex);
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Attempts to shutdown the TracerProviderSdk, blocks the current thread until
        /// shutdown completed or timed out.
        /// </summary>
        /// <param name="provider">TracerProviderSdk instance on which Shutdown will be called.</param>
        /// <param name="timeoutMilliseconds">
        /// The number (non-negative) of milliseconds to wait, or
        /// <c>Timeout.Infinite</c> to wait indefinitely.
        /// </param>
        /// <returns>
        /// Returns <c>true</c> when shutdown succeeded; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown when the <c>timeoutMilliseconds</c> is smaller than -1.
        /// </exception>
        /// <remarks>
        /// This function guarantees thread-safety. Only the first call will
        /// win, subsequent calls will be no-op.
        /// </remarks>
        public static bool Shutdown(this TracerProvider provider, int timeoutMilliseconds = Timeout.Infinite)
        {
            Guard.ThrowIfNull(provider);
            Guard.ThrowIfInvalidTimeout(timeoutMilliseconds);

            if (provider is TracerProviderSdk tracerProviderSdk)
            {
                if (Interlocked.Increment(ref tracerProviderSdk.ShutdownCount) > 1)
                {
                    return(false); // shutdown already called
                }

                try
                {
                    return(tracerProviderSdk.OnShutdown(timeoutMilliseconds));
                }
                catch (Exception ex)
                {
                    OpenTelemetrySdkEventSource.Log.TracerProviderException(nameof(tracerProviderSdk.OnShutdown), ex);
                    return(false);
                }
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Flushes the all the processors at TracerProviderSdk, blocks the current thread until flush
        /// completed, shutdown signaled or timed out.
        /// </summary>
        /// <param name="provider">TracerProviderSdk instance on which ForceFlush will be called.</param>
        /// <param name="timeoutMilliseconds">
        /// The number of milliseconds to wait, or <c>Timeout.Infinite</c> to
        /// wait indefinitely.
        /// </param>
        /// <returns>
        /// Returns <c>true</c> when force flush succeeded; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// Thrown when the <c>timeoutMilliseconds</c> is smaller than -1.
        /// </exception>
        /// <remarks>
        /// This function guarantees thread-safety.
        /// </remarks>
        public static bool ForceFlush(this TracerProvider provider, int timeoutMilliseconds = Timeout.Infinite)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (provider is TracerProviderSdk tracerProviderSdk)
            {
                if (timeoutMilliseconds < 0 && timeoutMilliseconds != Timeout.Infinite)
                {
                    throw new ArgumentOutOfRangeException(nameof(timeoutMilliseconds), timeoutMilliseconds, "timeoutMilliseconds should be non-negative.");
                }

                try
                {
                    return(tracerProviderSdk.OnForceFlush(timeoutMilliseconds));
                }
                catch (Exception ex)
                {
                    OpenTelemetrySdkEventSource.Log.TracerProviderException(nameof(tracerProviderSdk.OnForceFlush), ex);
                    return(false);
                }
            }

            return(true);
        }
Beispiel #4
0
        public static TracerProvider AddProcessor(this TracerProvider provider, BaseProcessor <Activity> processor)
        {
            Guard.ThrowIfNull(provider);
            Guard.ThrowIfNull(processor);

            if (provider is TracerProviderSdk tracerProviderSdk)
            {
                tracerProviderSdk.AddProcessor(processor);
            }

            return(provider);
        }
Beispiel #5
0
        public static TracerProvider AddProcessor(this TracerProvider provider, BaseProcessor <Activity> processor)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (processor == null)
            {
                throw new ArgumentNullException(nameof(processor));
            }

            if (provider is TracerProviderSdk tracerProviderSdk)
            {
                tracerProviderSdk.AddProcessor(processor);
            }

            return(provider);
        }
Beispiel #6
0
        /// <summary>
        /// Flushes all the processors registered under TracerProviderSdk, blocks the current thread
        /// until flush completed, shutdown signaled or timed out.
        /// </summary>
        /// <param name="provider">TracerProviderSdk instance on which ForceFlush will be called.</param>
        /// <param name="timeoutMilliseconds">
        /// The number (non-negative) of milliseconds to wait, or
        /// <c>Timeout.Infinite</c> to wait indefinitely.
        /// </param>
        /// <returns>
        /// Returns <c>true</c> when force flush succeeded; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown when the <c>timeoutMilliseconds</c> is smaller than -1.
        /// </exception>
        /// <remarks>
        /// This function guarantees thread-safety.
        /// </remarks>
        public static bool ForceFlush(this TracerProvider provider, int timeoutMilliseconds = Timeout.Infinite)
        {
            Guard.ThrowIfNull(provider);
            Guard.ThrowIfInvalidTimeout(timeoutMilliseconds);

            if (provider is TracerProviderSdk tracerProviderSdk)
            {
                try
                {
                    return(tracerProviderSdk.OnForceFlush(timeoutMilliseconds));
                }
                catch (Exception ex)
                {
                    OpenTelemetrySdkEventSource.Log.TracerProviderException(nameof(tracerProviderSdk.OnForceFlush), ex);
                    return(false);
                }
            }

            return(true);
        }
Beispiel #7
0
        public static TracerProvider AddProcessor(this TracerProvider provider, ActivityProcessor processor)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (processor == null)
            {
                throw new ArgumentNullException(nameof(processor));
            }

            var trait = provider as TracerProviderSdk;

            if (trait == null)
            {
                throw new ArgumentException($"{nameof(provider)} is not an instance of TracerProviderSdk");
            }

            return(trait.AddProcessor(processor));
        }