コード例 #1
0
        internal RpcRetryConsumer(IConsumer <T> consumer, RetryOptions options,
                                  Func <T, int> sizer, Func <Action, RetryOptions, ISequentialThreadingTimer> timerFactory)
        {
            _consumer     = GaxPreconditions.CheckNotNull(consumer, nameof(consumer));
            _options      = GaxPreconditions.CheckNotNull(options, nameof(options));
            _sizer        = GaxPreconditions.CheckNotNull(sizer, nameof(sizer));
            _timerFactory = GaxPreconditions.CheckNotNull(timerFactory, nameof(timerFactory));

            // Start the background timer that will retry failed requests.
            if (options.RetryType != RetryType.None)
            {
                _timer = _timerFactory(FlushBuffer, _options);
            }
        }
コード例 #2
0
 private LoggingOptions(
     LogLevel logLevel,
     string logName,
     Dictionary <string, string> labels,
     MonitoredResource monitoredResource,
     BufferOptions bufferOptions,
     RetryOptions retryOptions)
 {
     LogName           = logName;
     LogLevel          = GaxPreconditions.CheckEnumValue(logLevel, nameof(logLevel));
     Labels            = labels;
     MonitoredResource = monitoredResource;
     BufferOptions     = bufferOptions;
     RetryOptions      = retryOptions;
 }
コード例 #3
0
 /// <summary>
 /// Create a new instance of <see cref="LoggerOptions"/>.
 /// </summary>
 /// <param name="logLevel">Optional, the minimum log level.  Defaults to <see cref="LogLevel.Information"/></param>
 /// <param name="logName">Optional, the name of the log.  Defaults to 'aspnetcore'.</param>
 /// <param name="labels">Optional, custom labels to be added to log entries.
 /// Keys and values added to <paramref name="labels"/> should not be null.
 /// If they are, an exception will be throw when attempting to log an entry.
 /// The entry won't be logged and the exception will be propagated depending
 /// on the value of <see cref="RetryOptions.ExceptionHandling"/>.</param>
 /// <param name="monitoredResource">Optional, the monitored resource.  The monitored resource will
 /// be automatically detected if it is not set and will default to the global resource if the detection fails.
 /// See: https://cloud.google.com/logging/docs/api/v2/resource-list </param>
 /// <param name="bufferOptions">Optional, the buffer options.  Defaults to a <see cref="BufferType.Timed"/></param>
 /// <param name="retryOptions">Optional, the retry options.  Defaults to a <see cref="RetryType.None"/></param>
 /// <param name="loggerDiagnosticsOutput">Optional. If set some logger diagnostics info will be written
 /// to the given <see cref="TextWriter"/>. Currently the only diagnostics info we provide is the URL where
 /// the logs written with these options can be found.</param>
 /// <param name="serviceName">A string that represents the version of the service or the source code that logs are written for.
 /// When set, it will be included in the <code>serviceContext</code> field of the log entry JSON payload.</param>
 /// <param name="version">A string that represents the version of the service or the source code that logs are written for.
 /// When set, it will be included in the <code>serviceContext</code> field of the log entry JSON payload.</param>
 public static LoggerOptions CreateWithServiceContext(
     LogLevel logLevel = LogLevel.Information,
     string logName    = null,
     Dictionary <string, string> labels  = null,
     MonitoredResource monitoredResource = null,
     BufferOptions bufferOptions         = null,
     RetryOptions retryOptions           = null,
     TextWriter loggerDiagnosticsOutput  = null,
     string serviceName = null,
     string version     = null)
 {
     logName ??= _baseLogName;
     labels ??= new Dictionary <string, string>();
     monitoredResource ??= MonitoredResourceBuilder.FromPlatform();
     bufferOptions ??= BufferOptions.TimedBuffer();
     retryOptions ??= RetryOptions.NoRetry();
     return(new LoggerOptions(logLevel, logName, labels, monitoredResource, bufferOptions, retryOptions, loggerDiagnosticsOutput, serviceName, version));
 }
コード例 #4
0
 /// <summary>
 /// Create a new instance of <see cref="LoggerOptions"/> with default service context.
 /// If <paramref name="monitoredResource"/> is provided, the service context will be obtained from it.
 /// Else, if running on GAE, the service context will be obtained from the platform.
 /// </summary>
 /// <param name="logLevel">Optional, the minimum log level.  Defaults to <see cref="LogLevel.Information"/></param>
 /// <param name="logName">Optional, the name of the log.  Defaults to 'aspnetcore'.</param>
 /// <param name="labels">Optional, custom labels to be added to log entries.
 /// Keys and values added to <paramref name="labels"/> should not be null.
 /// If they are, an exception will be throw when attempting to log an entry.
 /// The entry won't be logged and the exception will be propagated depending
 /// on the value of <see cref="RetryOptions.ExceptionHandling"/>.</param>
 /// <param name="monitoredResource">Optional, the monitored resource.  The monitored resource will
 /// be automatically detected if it is not set and will default to the global resource if the detection fails.
 /// See: https://cloud.google.com/logging/docs/api/v2/resource-list </param>
 /// <param name="bufferOptions">Optional, the buffer options.  Defaults to a <see cref="BufferType.Timed"/></param>
 /// <param name="retryOptions">Optional, the retry options.  Defaults to a <see cref="RetryType.None"/></param>
 /// <param name="loggerDiagnosticsOutput">Optional. If set some logger diagnostics info will be written
 /// to the given <see cref="TextWriter"/>. Currently the only diagnostics info we provide is the URL where
 /// the logs written with these options can be found.</param>
 public static LoggerOptions CreateWithDetectedServiceContext(
     LogLevel logLevel = LogLevel.Information,
     string logName    = null,
     Dictionary <string, string> labels  = null,
     MonitoredResource monitoredResource = null,
     BufferOptions bufferOptions         = null,
     RetryOptions retryOptions           = null,
     TextWriter loggerDiagnosticsOutput  = null) =>
 CreateWithServiceContext(
     logLevel,
     logName,
     labels,
     monitoredResource,
     bufferOptions,
     retryOptions,
     loggerDiagnosticsOutput,
     Project.GetServiceName(null, monitoredResource),
     Project.GetServiceVersion(null, monitoredResource));
コード例 #5
0
        private LoggerOptions(
            LogLevel logLevel,
            string logName,
            Dictionary <string, string> labels,
            MonitoredResource monitoredResource,
            BufferOptions bufferOptions,
            RetryOptions retryOptions,
            TextWriter loggerDiagnosticsOutput,
            string serviceName,
            string version)
        {
            LogName                 = logName;
            LogLevel                = GaxPreconditions.CheckEnumValue(logLevel, nameof(logLevel));
            Labels                  = labels;
            MonitoredResource       = monitoredResource;
            BufferOptions           = bufferOptions;
            RetryOptions            = retryOptions;
            LoggerDiagnosticsOutput = loggerDiagnosticsOutput;

            // Create the service context here, this class is inmutable.
            ServiceContext = CreateServiceContext(serviceName, version);
        }
コード例 #6
0
 private ErrorReportingOptions(EventTarget eventTarget, BufferOptions bufferOptions, RetryOptions retryOptions)
     : this(GaxPreconditions.CheckNotNull(eventTarget, nameof(eventTarget)).LogName ?? LogNameDefault,
            eventTarget.MonitoredResource ?? MonitoredResourceBuilder.FromPlatform(),
            bufferOptions,
            retryOptions) =>
コード例 #7
0
 /// <summary>
 /// Creates an <see cref="ErrorReportingOptions"/> that will send error events to the
 /// Google Cloud Logging API.
 /// </summary>
 /// <param name="projectId">Optional if running on Google App Engine or Google Compute Engine.
 ///     The Google Cloud Platform project ID. If running on GAE or GCE the project ID will be
 ///     detected from the platform.</param>
 /// <param name="bufferOptions">The buffer options for the error reporter. Defaults to no buffer.</param>
 /// <param name="retryOptions">The retry options for the error reporter. Defaults to no retry.</param>
 public static ErrorReportingOptions Create(
     string projectId = null, BufferOptions bufferOptions = null, RetryOptions retryOptions = null) =>
 Create(EventTarget.ForLogging(projectId), bufferOptions, retryOptions);
コード例 #8
0
 /// <summary>
 /// Creates an <see cref="ErrorReportingOptions"/>.
 /// </summary>
 /// <param name="eventTarget">Where the error events should be sent. Must not be null.</param>
 /// <param name="bufferOptions">The buffer options for the error reporter. Defaults to no buffer.</param>
 /// <param name="retryOptions">The retry options for the error reporter. Defaults to no retry.</param>
 public static ErrorReportingOptions Create(
     EventTarget eventTarget, BufferOptions bufferOptions = null, RetryOptions retryOptions = null) =>
 new ErrorReportingOptions(eventTarget,
                           bufferOptions ?? BufferOptions.NoBuffer(), retryOptions ?? RetryOptions.NoRetry());
コード例 #9
0
 private ErrorReportingOptions(EventTarget eventTarget, BufferOptions bufferOptions, RetryOptions retryOptions)
 {
     EventTarget   = GaxPreconditions.CheckNotNull(eventTarget, nameof(eventTarget));
     BufferOptions = GaxPreconditions.CheckNotNull(bufferOptions, nameof(bufferOptions));
     RetryOptions  = GaxPreconditions.CheckNotNull(retryOptions, nameof(retryOptions));
 }
コード例 #10
0
 /// <summary>
 /// Creates a <see cref="TraceOptions"/>.
 /// </summary>
 /// <param name="qpsSampleRate">Optional, the number of queries traced per second.  The sample rate determines
 ///     how often requests are automatically traced. Defaults to <see cref="DefaultQpsSampleRate"/>.
 /// </param>
 /// <param name="bufferOptions">Optional, the buffer options.  Defaults to a <see cref="BufferType.Timed"/>.</param>
 /// <param name="retryOptions">Optional, the retry options.  Defaults to a <see cref="RetryType.None"/>.</param>
 public static TraceOptions Create(
     double qpsSampleRate = DefaultQpsSampleRate, BufferOptions bufferOptions = null, RetryOptions retryOptions = null)
 {
     return(new TraceOptions(
                qpsSampleRate, bufferOptions ?? BufferOptions.TimedBuffer(), retryOptions ?? RetryOptions.NoRetry()));
 }
コード例 #11
0
 /// <summary>
 /// Create a new instance of <see cref="LoggingOptions"/>.
 /// </summary>
 /// <param name="logLevel">Optional, the minimum log level. Defaults to <see cref="LogLevel.Information"/></param>
 /// <param name="logName">Optional, the name of the log. Defaults to 'aspnetcore'.</param>
 /// <param name="labels">Optional, custom labels to be added to log entries.
 /// Keys and values added to <paramref name="labels"/> should not be null.
 /// If they are, an exception will be thrown when attempting to log an entry.
 /// The entry won't be logged and the exception will be propagated depending
 /// on the value of <see cref="RetryOptions.ExceptionHandling"/>.</param>
 /// <param name="monitoredResource">Optional, the monitored resource. The monitored resource will
 /// be automatically detected if it is not set and will default to the global resource if the detection fails.
 /// See: https://cloud.google.com/logging/docs/api/v2/resource-list </param>
 /// <param name="bufferOptions">Optional, the buffer options. Defaults to a <see cref="BufferType.Timed"/></param>
 /// <param name="retryOptions">Optional, the retry options. Defaults to a <see cref="RetryType.None"/></param>
 public static LoggingOptions Create(LogLevel logLevel = LogLevel.Information, string logName = null,
                                     Dictionary <string, string> labels = null, MonitoredResource monitoredResource = null,
                                     BufferOptions bufferOptions        = null, RetryOptions retryOptions = null) =>
 new LoggingOptions(logLevel, logName ?? _baseLogName,
                    labels ?? new Dictionary <string, string>(), monitoredResource ?? MonitoredResourceBuilder.FromPlatform(),
                    bufferOptions ?? BufferOptions.TimedBuffer(), retryOptions ?? RetryOptions.NoRetry());