/// <summary> /// Initialize tracing for this application. /// </summary> /// <param name="projectId">The Google Cloud Platform project ID.</param> /// <param name="application">The Http application.</param> /// <param name="config">Optional trace configuration, if unset the default will be used.</param> /// <param name="client">Optional trace client, if unset the default will be used.</param> public static void Initialize(string projectId, HttpApplication application, TraceConfiguration config = null, TraceServiceClient client = null) { GaxPreconditions.CheckNotNull(application, nameof(application)); CloudTrace trace = new CloudTrace(projectId, config, client); // Add event handlers to the application. application.BeginRequest += trace.BeginRequest; application.EndRequest += trace.EndRequest; application.Disposed += (object sender, EventArgs e) => { trace.Dispose(); }; }
/// <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="config">Optional trace configuration, 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, TraceConfiguration config = null, TraceServiceClient client = null, TraceDecisionPredicate traceFallbackPredicate = null) { GaxPreconditions.CheckNotNull(application, nameof(application)); projectId = CommonUtils.GetAndCheckProjectId(projectId); CloudTrace trace = new CloudTrace(projectId, config, client, traceFallbackPredicate); // Add event handlers to the application. application.BeginRequest += trace.BeginRequest; application.EndRequest += trace.EndRequest; application.Disposed += (object sender, EventArgs e) => { trace.Dispose(); }; }
/// <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); }