/// <summary> /// Configures Google Diagnostics to be used in 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 AddGoogleDiagnosticsForAspNetCore( this IServiceCollection services, AspNetCoreTraceOptions traceOptions = null, LoggingServiceOptions loggingOptions = null, Common.ErrorReportingServiceOptions errorReportingOptions = null) => services .AddLogEntryLabelProviderSingleton <TraceIdLogEntryLabelProvider>() .AddGoogleTraceForAspNetCore(traceOptions) .AddLogging(builder => builder.AddGoogle(loggingOptions)) .AddGoogleErrorReportingForAspNetCore(errorReportingOptions);
internal static IServiceCollection AddGoogleTraceForAspNetCore(this IServiceCollection services, bool registerMiddleware, AspNetCoreTraceOptions options) { services.AddGoogleTrace(options?.ServiceOptions); services.AddSingleton(options?.TraceFallbackPredicate ?? TraceDecisionPredicate.Default); // We use TryAdd... here to allow user code to inject their own trace context provider // and matching trace context response propagator. We use Google trace header otherwise. services.TryAddGoogleTraceContextProvider(); services.TryAddSingleton <Action <HttpResponse, ITraceContext> >(PropagateGoogleTraceHeaders); // Obsolete: Adding this for backwards compatibility in case someone is using the old factory type. // The new and prefered factory type is Func<ITraceContext, IManagedTracer> which is being added by Common. services.AddSingleton <Func <TraceHeaderContext, IManagedTracer> >(sp => sp.GetRequiredService <Func <ITraceContext, IManagedTracer> >()); services.AddHttpContextAccessor(); services.AddTransient <ICloudTraceNameProvider, DefaultCloudTraceNameProvider>(); if (registerMiddleware) { // This registers the trace middleware so users don't have to. services.AddSingleton <IStartupFilter, AspNetCoreTraceStartupFilter>(); } return(services); }
/// <summary> /// Configures Google Cloud Tracing for ASP .NET Core applications./>. /// </summary> public static IServiceCollection AddGoogleTraceForAspNetCore(this IServiceCollection services, AspNetCoreTraceOptions options = null) => #pragma warning disable CS0618 // Type or member is obsolete services.AddGoogleTraceForAspNetCore(true, options);