Class CloudTrace
Google Trace for ASP.NET Applications.
Inheritance
Implements
Inherited Members
Namespace: Google.Cloud.Diagnostics.AspNet
Assembly: Google.Cloud.Diagnostics.AspNet.dll
Syntax
public sealed class CloudTrace : IDisposable
Remarks
Handles tracing for ASP.NET applications and sends data to the Stackdriver Trace API Reporting.
By default when initialized a small sampling of http requests will automatically be traced. Additional trace data can be collected manually.
Examples
public class Global : HttpApplication
{
public override void Init()
{
base.Init();
CloudTrace.Initialize(this, "some-project-id");
}
}
public void MakeHttpRequest()
{
var traceHeaderHandler = CloudTrace.CreateTracingHttpMessageHandler();
using (var httpClient = HttpClientFactory.Create(traceHeaderHandler))
{
...
}
}
public void DoSomething()
{
using (CloudTrace.Tracer.StartSpan("DoSomething"))
{
...
}
}
Fields
Tracer
Gets the IManagedTracer for tracing. It can be used for creating spans for a trace as well as adding meta data to them. This IManagedTracer is a singleton.
Declaration
public static readonly IManagedTracer Tracer
Field Value
| Type | Description |
|---|---|
| IManagedTracer |
Methods
CreateTracingHttpMessageHandler()
Creates a TraceHeaderPropagatingHandler to propagate trace headers
in Http requests.
public void DoSomething()
{
var traceHeaderHandler = CloudTrace.CreateTracingHttpMessageHandler();
using (var httpClient = new HttpClient(traceHeaderHandler))
{
...
}
}
Declaration
public static TraceHeaderPropagatingHandler CreateTracingHttpMessageHandler()
Returns
| Type | Description |
|---|---|
| TraceHeaderPropagatingHandler |
Dispose()
Declaration
public void Dispose()
Implements
Initialize(HttpApplication, String, TraceOptions, TraceServiceClient, TraceDecisionPredicate)
Initialize tracing for this application.
Declaration
public static void Initialize(HttpApplication application, string projectId = null, TraceOptions options = null, TraceServiceClient client = null, TraceDecisionPredicate traceFallbackPredicate = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Web.HttpApplication | application | The Http application. |
| System.String | 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. |
| TraceOptions | options | Optional trace options, if unset the default will be used. |
| Google.Cloud.Trace.V1.TraceServiceClient | client | Optional trace client, if unset the default will be used. |
| TraceDecisionPredicate | 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. |