/// <summary> /// Creates an instance of <see cref="GoogleExceptionLogger"/>. /// <para> /// Can be used when running on Google App Engine or Google Compute Engine. /// The Google Cloud Platform project to report errors to will detected from the /// current platform. /// </para> /// </summary> /// <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> public static GoogleExceptionLogger Create(string serviceName, string version, ErrorReportingOptions options = null) { var contextLogger = ContextExceptionLogger.Create(null, serviceName, version, options); return(new GoogleExceptionLogger(contextLogger)); }
public void ConfigureServices(IServiceCollection services, IConfiguration config) { var isEnabled = config.GetValue <bool>("logging:stackdriver:enabled"); if (isEnabled) { var projectId = config.GetValue <string>("logging:stackdriver:projectId"); if (!string.IsNullOrWhiteSpace(projectId)) { services.AddSingleton <ITelemetryConfigurator>( new Configurator(projectId)); services.AddSingleton <ILogAppender, StackdriverSeverityLogAppender>(); services.AddSingleton <ILogAppender, StackdriverExceptionHandler>(); var serviceName = config.GetValue <string>("logging:name") ?? "Squidex"; var serviceVersion = Assembly.GetEntryAssembly()?.GetName().Version?.ToString(); services.AddSingleton(c => ContextExceptionLogger.Create(projectId, serviceVersion, serviceVersion, null)); } } }
/// <summary> /// Creates an instance of <see cref="GoogleExceptionLogger"/>. /// </summary> /// <param name="projectId">The Google Cloud Platform project ID. Must not 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> public static GoogleExceptionLogger Create(string projectId, string serviceName, string version, ErrorReportingOptions options = null) { GaxPreconditions.CheckNotNullOrEmpty(projectId, nameof(projectId)); var contextLogger = ContextExceptionLogger.Create(projectId, serviceName, version, options); return(new GoogleExceptionLogger(contextLogger)); }
/// <summary> /// Adds services for middleware that will report all uncaught exceptions to the /// Google Cloud Error Reporting API. /// <para> /// Can be used when running on Google App Engine or Google Compute Engine. /// The Google Cloud Platform project to report errors to will detected from the /// current platform. /// </para> /// </summary> /// <param name="services">The service collection. Must not be null.</param> /// <param name="setupAction">Action to set up options. Must not be null.</param> /// <remarks> /// If <see cref="RetryOptions.ExceptionHandling"/> is set to <see cref="ExceptionHandling.Propagate"/> /// and the <see cref="RequestDelegate"/> executed by this middleware throws an exception and this /// diagnostics library also throws an exception trying to report it an <see cref="AggregateException"/> /// with both exceptions will be thrown. Otherwise only the exception from the <see cref="RequestDelegate"/> /// will be thrown. /// </remarks> public static IServiceCollection AddGoogleExceptionLogging( this IServiceCollection services, Action <ErrorReportingServiceOptions> setupAction) { GaxPreconditions.CheckNotNull(services, nameof(services)); GaxPreconditions.CheckNotNull(setupAction, nameof(setupAction)); var serviceOptions = new ErrorReportingServiceOptions(); setupAction(serviceOptions); services.AddHttpContextAccessor(); services.AddSingleton(ContextExceptionLogger.Create( serviceOptions.ProjectId, serviceOptions.ServiceName, serviceOptions.Version, serviceOptions.Options)); return(services.AddSingleton(CreateExceptionLogger)); }
public static void AddMyTelemetry(this IServiceCollection services, IConfiguration config) { services.AddOpenTelemetryTracing(builder => { var serviceName = config.GetValue <string>("logging:name") ?? "Notifo"; var serviceVersion = Assembly.GetEntryAssembly()?.GetName().Version?.ToString(); builder.SetResourceBuilder( ResourceBuilder.CreateDefault() .AddService(serviceName, "Notifo", typeof(Startup).Assembly.GetName().Version !.ToString())); builder.AddSource("Notifo"); builder.AddAspNetCoreInstrumentation(); builder.AddHttpClientInstrumentation(); if (config.GetValue <bool>("logging:stackdriver:enabled")) { var projectId = config.GetRequiredValue("logging:stackdriver:projectId"); builder.UseStackdriverExporter(projectId); services.AddSingleton(c => ContextExceptionLogger.Create(projectId, serviceVersion, serviceVersion, null)); } if (config.GetValue <bool>("logging:applicationInsights:enabled")) { builder.AddAzureMonitorTraceExporter(options => { config.GetSection("logging:applicationInsights").Bind(options); }); } if (config.GetValue <bool>("logging:otlp:enabled")) { // See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); builder.AddOtlpExporter(options => { config.GetSection("logging:otlp").Bind(options); }); } }); }
/// <summary> /// Adds services for middleware that will report all uncaught exceptions to the /// Stackdriver Error Reporting API. /// <para> /// Can be used when running on Google App Engine or Google Compute Engine. /// The Google Cloud Platform project to report errors to will detected from the /// current platform. /// </para> /// </summary> /// <param name="services">The service collection. Must not be null.</param> /// <param name="setupAction">Action to set up options. Must not be null.</param> /// <remarks> /// If <see cref="RetryOptions.ExceptionHandling"/> is set to <see cref="ExceptionHandling.Propagate"/> /// and the <see cref="RequestDelegate"/> executed by this middleware throws an exception and this /// diagnostics library also throws an exception trying to report it an <see cref="AggregateException"/> /// with both exceptions will be thrown. Otherwise only the exception from the <see cref="RequestDelegate"/> /// will be thrown. /// </remarks> public static IServiceCollection AddGoogleExceptionLogging( this IServiceCollection services, Action <ErrorReportingServiceOptions> setupAction) { GaxPreconditions.CheckNotNull(services, nameof(services)); GaxPreconditions.CheckNotNull(setupAction, nameof(setupAction)); var serviceOptions = new ErrorReportingServiceOptions(); setupAction(serviceOptions); var serviceName = GaxPreconditions.CheckNotNull(serviceOptions.ServiceName, nameof(serviceOptions.ServiceName)); var version = GaxPreconditions.CheckNotNull(serviceOptions.Version, nameof(serviceOptions.Version)); // Only add the HttpContextAccessor if it's not already added. services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton(ContextExceptionLogger.Create( serviceOptions.ProjectId, serviceName, version, serviceOptions.Options)); return(services.AddSingleton(CreateExceptionLogger)); }