VMware has ended active development of this project, this repository will no longer be updated.
This SDK collects out of the box metrics, histograms, and (optionally) traces from your ASP.NET Core application and reports the data to Wavefront. Data can be sent to Wavefront using either the proxy or direct ingestion. You can analyze the data in Wavefront to better understand how your application is performing in production.
Install the NuGet package.
PM> Install-Package Wavefront.AspNetCore.SDK.CSharp
> dotnet add package Wavefront.AspNetCore.SDK.CSharp
In order to collect HTTP request/response metrics and histograms for your application, you will need to register the Wavefront services that the SDK provides on application startup. This is done in the ConfigureServices method of the Startup class.
The steps to do so are as follows:
- Create an instance of
ApplicationTags: metadata about your application. - Create an instance of
IWavefrontSender: low-level interface that handles sending data to Wavefront. - Create a
WavefrontAspNetCoreReporterfor reporting ASP.NET Core metrics and histograms to Wavefront. - Optionally create a
WavefrontTracerfor reporting trace data to Wavefront. - Register Wavefront services in
Startup. For your ASP.NET Core MVC application, this is done by adding a call toservices.AddWavefrontForMvc()inConfigureServices.
The sections below detail each of the above steps.
Application tags determine the metadata (span tags) that are included with every span reported to Wavefront. These tags enable you to filter and query trace data in Wavefront.
You encapsulate application tags in an ApplicationTags object.
See Instantiating ApplicationTags for details.
An IWavefrontSender object implements the low-level interface for sending data to Wavefront. You can choose to send data to Wavefront using either the Wavefront proxy or direct ingestion.
- See Set Up an IWavefrontSender Instance for details on instantiating a proxy or direct ingestion client.
Note: If you are using multiple Wavefront C# SDKs, see Share an IWavefrontSender Instance for information about sharing a single IWavefrontSender instance across SDKs.
The IWavefrontSender is used by both the WavefrontAspNetCoreReporter and the optional WavefrontTracer.
A WavefrontAspNetCoreReporter object reports metrics and histograms to Wavefront.
To build a WavefrontAspNetCoreReporter, you must specify:
- An
ApplicationTagsobject (see above) - An
IWavefrontSenderobject (see above).
You can optionally specify:
- A nondefault source for the reported data. If you omit the source, the host name is automatically used.
- A nondefault reporting interval, which controls how often data is reported to the IWavefrontSender. The reporting interval determines the timestamps on the data sent to Wavefront. If you omit the reporting interval, data is reported once a minute.
// Create WavefrontAspNetCoreReporter.Builder using your ApplicationTags object.
var builder = new WavefrontAspNetCoreReporter.Builder(applicationTags);
// Optionally set a nondefault source name for your metrics and histograms. Omit this statement to use the host name.
builder.WithSource("mySource");
// Optionally change the reporting interval to 30 seconds. Default is 1 minute
builder.ReportingIntervalSeconds(30);
// Create a WavefrontAspNetCoreReporter using your IWavefrontSender object
WavefrontAspNetCoreReporter wfAspNetCoreReporter = builder.Build(wavefrontSender);You can optionally configure a WavefrontTracer to create and send trace data from your ASP.NET Core application to Wavefront.
To build a WavefrontTracer, you must specify:
- The
ApplicationTagsobject (see above). - A
WavefrontSpanReporterfor reporting trace data to Wavefront. See Create a WavefrontSpanReporter for details. Note: When you create theWavefrontSpanReporter, you should instantiate it with the same source name andIWavefrontSenderthat you used to create theWavefrontAspNetCoreReporter(see above).
ApplicationTags applicationTags = BuildTags(); // pseudocode; see above
Reporter wavefrontSpanReporter = BuildSpanReporter(); // pseudocode
ITracer tracer = new WavefrontTracer.Builder(wavefrontSpanReporter, applicationTags).Build();For your ASP.NET Core MVC application, add a call to services.AddWavefrontForMvc() in ConfigureServices to enable HTTP request/response metrics and histograms for your controller actions.
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Register Wavefront instrumentation services for ASP.NET Core MVC
services.AddWavefrontForMvc(wfAspNetCoreReporter);
}
}Alternatively, if you have optionally configured a WavefrontTracer to send trace data, make sure to pass it along as a parameter to ``services.AddWavefrontForMvc()`.
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Register Wavefront instrumentation services and tracing for ASP.NET Core MVC
services.AddWavefrontForMvc(wfAspNetCoreReporter, tracer);
}
}When registered, the WavefrontTracer generates server-side trace data for all incoming HTTP requests. It also generates client-side trace data and propagates trace information for all outgoing HTTP requests that use HttpClientHandler.
See the metrics documentation for details on the out of the box metrics and histograms collected by this SDK and reported to Wavefront.