/// <summary> /// Creates an <see cref="IContextExceptionLogger"/>. /// </summary> /// <param name="projectId">The Google Cloud Platform project ID. If unspecified and running /// on GAE or GCE the project ID will be detected from the platform.</param> /// <param name="serviceName"> An identifier of the service, such as the name of the executable or job. Cannot be null.</param> /// <param name="version">Represents the source code version that the developer provided. Cannot be null.</param> /// <param name="options">The error reporting options. Can be null, if null default options will be used.</param> /// <returns>An <see cref="IContextExceptionLogger"/> for the given options.</returns> public static IContextExceptionLogger Create(string projectId, string serviceName, string version, ErrorReportingOptions options) { GaxPreconditions.CheckNotNull(serviceName, nameof(serviceName)); GaxPreconditions.CheckNotNull(version, nameof(version)); return(ErrorReportingContextExceptionLogger.Create(projectId, serviceName, version, options)); }
/// <summary> /// Configures Google Diagnostics to be used in non ASP.NET Core applications. /// </summary> /// <remarks> /// Options may be null in which case defaults will be used. Note that the /// Google Cloud Project ID to use is required. If not set via options, it will be /// obtained from the environment, but only if running on GCP. /// </remarks> public static IServiceCollection AddGoogleDiagnostics( this IServiceCollection services, string projectId = null, string serviceName = null, string serviceVersion = null, TraceOptions traceOptions = null, LoggingOptions loggingOptions = null, ErrorReportingOptions errorReportingOptions = null) => services.AddGoogleDiagnostics( new TraceServiceOptions { Options = traceOptions, ProjectId = projectId }, new LoggingServiceOptions { Options = loggingOptions, ProjectId = projectId, ServiceName = serviceName, Version = serviceVersion }, new ErrorReportingServiceOptions { Options = errorReportingOptions, ProjectId = projectId, ServiceName = serviceName, Version = serviceVersion });
internal static IContextExceptionLogger Create(ErrorReportingServiceOptions options, IServiceProvider serviceProvider) { options = options ?? new ErrorReportingServiceOptions(); var errorReportingOptions = options.Options ?? ErrorReportingOptions.CreateInstance(); var eventTarget = options.EventTarget #pragma warning disable CS0618 // Type or member is obsolete ?? errorReportingOptions.EventTarget #pragma warning restore CS0618 // Type or member is obsolete ?? EventTarget.ForProject(Project.GetAndCheckProjectId(null, errorReportingOptions.MonitoredResource)); var client = options.Client #pragma warning disable CS0618 // Type or member is obsolete ?? eventTarget.LoggingClient #pragma warning restore CS0618 // Type or member is obsolete ?? LoggingServiceV2Client.Create(); var serviceContext = CreateServiceContext( Project.GetServiceName(options.ServiceName, errorReportingOptions.MonitoredResource), Project.GetServiceName(options.Version, errorReportingOptions.MonitoredResource)) ?? new Struct(); IConsumer <LogEntry> consumer = LogConsumer.Create(client, errorReportingOptions.BufferOptions, errorReportingOptions.RetryOptions); return(new ErrorReportingContextExceptionLogger(consumer, eventTarget, serviceContext, errorReportingOptions, serviceProvider)); }
/// <summary> /// Creates an instance of <see cref="ErrorReportingContextExceptionLogger"/> /// </summary> /// <param name="projectId">The Google Cloud Platform project ID. May be null.</param> /// <param name="serviceName">An identifier of the service, such as the name of the executable or job. May be null.</param> /// <param name="version">Represents the source code version that the developer provided. May be null.</param> /// <param name="options">Optional, error reporting options.</param> internal static IContextExceptionLogger Create(string projectId, string serviceName, string version, ErrorReportingOptions options = null) { options = options ?? ErrorReportingOptions.Create(projectId); var consumer = options.CreateConsumer(); return(new ErrorReportingContextExceptionLogger(consumer, serviceName, version, options)); }
/// <summary> /// Creates an <see cref="IContextExceptionLogger"/>. /// </summary> /// <param name="projectId">The Google Cloud Platform project ID. If unspecified and running /// on GAE or GCE the project ID will be detected from the platform.</param> /// <param name="serviceName"> An identifier of the service, such as the name of the executable or job. May be null.</param> /// <param name="version">Represents the source code version that the developer provided. May be null.</param> /// <param name="options">The error reporting options. Can be null, if null default options will be used.</param> /// <param name="serviceProvider">The service provider to obtain services from. May be null, /// in which case some context information won't be added to the LogEntry.</param> /// <returns>An <see cref="IContextExceptionLogger"/> for the given options.</returns> public static IContextExceptionLogger Create( string projectId, string serviceName, string version, ErrorReportingOptions options, IServiceProvider serviceProvider) => Create( new ErrorReportingServiceOptions { ProjectId = projectId, ServiceName = serviceName, Version = version, Options = options }, serviceProvider);
/// <summary> /// Creates an instance of <see cref="ErrorReportingContextExceptionLogger"/> /// </summary> /// <param name="projectId">The Google Cloud Platform project ID. Can be null.</param> /// <param name="serviceName">An identifier of the service, such as the name of the executable or job. /// Must not be null.</param> /// <param name="version">Represents the source code version that the developer provided. /// Must not be null.</param> /// <param name="options">Optional, error reporting options.</param> internal static IContextExceptionLogger Create(string projectId, string serviceName, string version, ErrorReportingOptions options = null) { GaxPreconditions.CheckNotNullOrEmpty(serviceName, nameof(serviceName)); GaxPreconditions.CheckNotNullOrEmpty(version, nameof(version)); options = options ?? ErrorReportingOptions.Create(projectId); var consumer = options.CreateConsumer(); return(new ErrorReportingContextExceptionLogger(consumer, serviceName, version, options)); }
internal ErrorReportingContextExceptionLogger( IConsumer <LogEntry> consumer, string serviceName, string version, ErrorReportingOptions options) { _consumer = GaxPreconditions.CheckNotNull(consumer, nameof(consumer)); _options = GaxPreconditions.CheckNotNull(options, nameof(options)); var eventTarget = options.EventTarget; GaxPreconditions.CheckState(eventTarget.Kind == EventTargetKind.Logging, $"Invalid {nameof(EventTarget)}"); _logName = GaxPreconditions.CheckNotNull(eventTarget.LogTarget, nameof(eventTarget.LogTarget)).GetFullLogName(eventTarget.LogName); _serviceContext = CreateServiceContext(serviceName, version) ?? new Struct(); }
internal ErrorReportingContextExceptionLogger( IConsumer <LogEntry> consumer, EventTarget eventTarget, Struct serviceContext, ErrorReportingOptions options, IServiceProvider serviceProvider) { GaxPreconditions.CheckNotNull(eventTarget, nameof(eventTarget)); _consumer = GaxPreconditions.CheckNotNull(consumer, nameof(consumer)); _options = GaxPreconditions.CheckNotNull(options, nameof(options)); _serviceContext = GaxPreconditions.CheckNotNull(serviceContext, nameof(serviceContext)); _logName = eventTarget.LogTarget.GetFullLogName(options.LogName); _traceTarget = eventTarget.LogTarget.Kind == LogTargetKind.Project ? TraceTarget.ForProject(eventTarget.ProjectId) : null; _serviceProvider = serviceProvider; }
internal ErrorReportingContextExceptionLogger( IConsumer <LogEntry> consumer, string serviceName, string version, ErrorReportingOptions options) { _consumer = GaxPreconditions.CheckNotNull(consumer, nameof(consumer)); _options = GaxPreconditions.CheckNotNull(options, nameof(options)); var eventTarget = options.EventTarget; GaxPreconditions.CheckState(eventTarget.Kind == EventTargetKind.Logging, $"Invalid {nameof(EventTarget)}"); _logName = GaxPreconditions.CheckNotNull(eventTarget.LogTarget, nameof(eventTarget.LogTarget)).GetFullLogName(eventTarget.LogName); _serviceContext = new Struct { Fields = { { "service", Value.ForString(GaxPreconditions.CheckNotNull(serviceName, nameof(serviceName))) }, { "version", Value.ForString(GaxPreconditions.CheckNotNull(version, nameof(version))) } } }; }
/// <summary> /// Creates an <see cref="IContextExceptionLogger"/>. /// </summary> /// <param name="projectId">The Google Cloud Platform project ID. If unspecified and running /// on GAE or GCE the project ID will be detected from the platform.</param> /// <param name="serviceName"> An identifier of the service, such as the name of the executable or job. May be null.</param> /// <param name="version">Represents the source code version that the developer provided. May be null.</param> /// <param name="options">The error reporting options. Can be null, if null default options will be used.</param> /// <returns>An <see cref="IContextExceptionLogger"/> for the given options.</returns> /// <remarks>This method will call <see cref="Create(string, string, string, ErrorReportingOptions, IServiceProvider)"/> /// passing a null value for the <see cref="IServiceProvider"/> parameter, which means that some context information /// cannot be added to log entries because there are no services to obtain that information from.</remarks> public static IContextExceptionLogger Create(string projectId, string serviceName, string version, ErrorReportingOptions options) => Create(projectId, serviceName, version, options, null);
/// <summary> /// Creates an <see cref="IContextExceptionLogger"/>. /// </summary> /// <param name="projectId">The Google Cloud Platform project ID. If unspecified and running /// on GAE or GCE the project ID will be detected from the platform.</param> /// <param name="serviceName"> An identifier of the service, such as the name of the executable or job. May be null.</param> /// <param name="version">Represents the source code version that the developer provided. May be null.</param> /// <param name="options">The error reporting options. Can be null, if null default options will be used.</param> /// <param name="serviceProvider">The service provider to obtain services from. May be null, /// in which case some context information won't be added to the LogEntry.</param> /// <returns>An <see cref="IContextExceptionLogger"/> for the given options.</returns> public static IContextExceptionLogger Create( string projectId, string serviceName, string version, ErrorReportingOptions options, IServiceProvider serviceProvider) => ErrorReportingContextExceptionLogger.Create(projectId, serviceName, version, serviceProvider, options);