/// <summary>
        /// Configures Google Cloud Trace for dependency injection.
        /// </summary>
        public static IServiceCollection AddGoogleTrace(
            this IServiceCollection services, Action <TraceServiceOptions> setupAction)
        {
            GaxPreconditions.CheckNotNull(services, nameof(services));
            GaxPreconditions.CheckNotNull(setupAction, nameof(setupAction));

            var serviceOptions = new TraceServiceOptions();

            setupAction(serviceOptions);

            var client    = serviceOptions.Client ?? TraceServiceClient.Create();
            var options   = serviceOptions.Options ?? TraceOptions.Create();
            var projectId = Project.GetAndCheckProjectId(serviceOptions.ProjectId);

            var consumer      = ManagedTracer.CreateConsumer(client, options);
            var tracerFactory = ManagedTracer.CreateFactory(projectId, consumer, options);

            services.AddSingleton(tracerFactory);
            services.AddSingleton(ManagedTracer.CreateDelegatingTracer(ContextTracerManager.GetCurrentTracer));

            // On .Net Standard 2.0 or higher, we can use the System.Net.Http.IHttpClientFactory defined in Microsoft.Extensions.Http,
            // for which we need a DelegatingHandler with no InnerHandler set. This is the recommended way.
            // It should be registered as follows.
            return(services.AddTransient(UnchainedTraceHeaderPropagatingHandlerFactory));
        }
 /// <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,
     TraceServiceOptions traceOptions     = null,
     LoggingServiceOptions loggingOptions = null,
     ErrorReportingServiceOptions errorReportingOptions = null) => services
 .AddGoogleTrace(traceOptions)
 .AddLogging(builder => builder.AddGoogle(loggingOptions))
 .AddGoogleErrorReporting(errorReportingOptions);
Esempio n. 3
0
        /// <summary>
        /// Configures Google Cloud Trace for dependency injection.
        /// </summary>
        public static IServiceCollection AddGoogleTrace(this IServiceCollection services, TraceServiceOptions options = null)
        {
            GaxPreconditions.CheckNotNull(services, nameof(services));

            var client       = options?.Client ?? TraceServiceClient.Create();
            var traceOptions = options?.Options ?? TraceOptions.Create();
            var projectId    = Project.GetAndCheckProjectId(options?.ProjectId);

            var consumer      = ManagedTracer.CreateConsumer(client, traceOptions);
            var tracerFactory = ManagedTracer.CreateFactory(projectId, consumer, traceOptions);

            services.AddSingleton(tracerFactory);
            services.AddSingleton(ManagedTracer.CreateDelegatingTracer(ContextTracerManager.GetCurrentTracer));

            // On .Net Standard 2.0 or higher, we can use the System.Net.Http.IHttpClientFactory defined in Microsoft.Extensions.Http,
            // for which we need a DelegatingHandler with no InnerHandler set.
            // we register factories for the UnchainedTraceHeaderPropagatingHandler.
#pragma warning disable CS0618 // Type or member is obsolete
            // This factory we register for backwards compatibility only.
            // We can remove it on our next major version as we are making UnchainedTraceHeaderPropagatingHandler
            // obsolete as well.
            services.AddTransient(UnchainedTraceHeaderPropagatingHandlerFactory);
#pragma warning restore CS0618 // Type or member is obsolete
            // This is the new factory, that takes trace custom labels into account.
            return(services.AddSingleton <OutgoingGoogleTraceHandlerFactory>());
        }