Exemplo n.º 1
0
        /// <summary>
        /// Only used for testing.  See <see cref="Initialize"/> for details.
        /// </summary>
        internal static CloudTrace InitializeInternal(HttpApplication application, string projectId = null,
                                                      TraceOptions options = null, TraceServiceClient client = null,
                                                      TraceDecisionPredicate traceFallbackPredicate = null)
        {
            GaxPreconditions.CheckNotNull(application, nameof(application));

            projectId = Project.GetAndCheckProjectId(projectId);
            CloudTrace trace = new CloudTrace(projectId, options, client, traceFallbackPredicate);

            // Add event handlers to the application.
            application.BeginRequest += trace.BeginRequest;
            application.EndRequest   += trace.EndRequest;
            application.Disposed     += (object sender, EventArgs e) => { trace.Dispose(); };
            return(trace);
        }
Exemplo n.º 2
0
        private CloudTrace(string projectId, TraceConfiguration config   = null, TraceServiceClient client = null,
                           TraceDecisionPredicate traceFallbackPredicate = null)
        {
            GaxPreconditions.CheckNotNull(projectId, nameof(projectId));

            // Create the default values if not set.
            client = client ?? TraceServiceClient.Create();
            config = config ?? TraceConfiguration.Create();
            _traceFallbackPredicate = traceFallbackPredicate ?? TraceDecisionPredicate.Default;

            _consumer = ConsumerFactory <TraceProto> .GetConsumer(
                new GrpcTraceConsumer(client), MessageSizer <TraceProto> .GetSize, config.BufferOptions);

            _tracerFactory = new ManagedTracerFactory(projectId, _consumer,
                                                      RateLimitingTraceOptionsFactory.Create(config), TraceIdFactory.Create());
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initialize tracing for this application.
 /// </summary>
 /// <param name="application">The Http application.</param>
 /// <param name="projectId">Optional if running on Google App Engine or Google Compute Engine.
 ///     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="options">Optional trace options, if unset the default will be used.</param>
 /// <param name="client">Optional trace client, if unset the default will be used.</param>
 /// <param name="traceFallbackPredicate">Optional function to trace requests. If the trace header is not set
 ///     then this function will be called to determine if a given request should be traced.  This will
 ///     not override trace headers.</param>
 public static void Initialize(HttpApplication application, string projectId = null,
                               TraceOptions options = null, TraceServiceClient client = null,
                               TraceDecisionPredicate traceFallbackPredicate = null)
 {
     InitializeInternal(application, projectId, options, client, traceFallbackPredicate);
 }