In this repository we setup a simple application that will be instrumented using the Wavefront ASP.NET Core SDK to allow the applications to send metrics and traces to Wavefront.
-
Create a new workspace directory and navigate to that directory
mkdir <workspace name> cd <workspace name>
-
Create a new project named frontend.
dotnet new mvc --name frontend
-
Add the Wavefront.AspNetCore.SDK.CSharp nuget package:
dotnet add package Wavefront.AspNetCore.SDK.CSharp
Create a file named
WavefrontExtensions.cs
with the following contents. Copy the file to root of the project. This file includes SDK code that allows us to connect to a Wavefront Proxy or to Wavefront with Direct Ingestion.using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Wavefront.AspNetCore.SDK.CSharp.Common; using Wavefront.OpenTracing.SDK.CSharp; using Wavefront.OpenTracing.SDK.CSharp.Reporting; using Wavefront.SDK.CSharp.Common.Application; using Wavefront.SDK.CSharp.Proxy; using OpenTracing; namespace wavefront_sdk { public static class SteeltoeWavefrontProxyExtensions { public class WavefrontProxyOptions { public WavefrontProxyOptions() { Port = 2878; DistributionPort = 2878; TracingPort = 30000; ReportingIntervalSeconds = 30; FlushIntervalSeconds = 2; } public const string WavefrontProxy = "wavefront-proxy"; public string Hostname { get; set; } public int Port { get; set; } public int DistributionPort { get; set; } public int TracingPort { get; set; } public string Application { get; set; } public string Service { get; set; } public string Cluster { get; set; } public string Shard { get; set; } public string Source {get; set;} public int ReportingIntervalSeconds {get; set;} public int FlushIntervalSeconds { get; set; } } public static IServiceCollection AddSteeltoeWavefrontProxy(this IServiceCollection services, IConfiguration configuration) { var waveFrontProxyConfiguration = configuration.GetSection(WavefrontProxyOptions.WavefrontProxy).Get<WavefrontProxyOptions>(); var wfProxyClientBuilder = new WavefrontProxyClient.Builder(waveFrontProxyConfiguration.Hostname); wfProxyClientBuilder.MetricsPort(waveFrontProxyConfiguration.Port); wfProxyClientBuilder.DistributionPort(waveFrontProxyConfiguration.DistributionPort); wfProxyClientBuilder.TracingPort(waveFrontProxyConfiguration.TracingPort); wfProxyClientBuilder.FlushIntervalSeconds(waveFrontProxyConfiguration.TracingPort); var wavefrontSender = wfProxyClientBuilder.Build(); var applicationTags = new ApplicationTags.Builder(waveFrontProxyConfiguration.Application, waveFrontProxyConfiguration.Service) .Cluster(waveFrontProxyConfiguration.Cluster) .Shard(waveFrontProxyConfiguration.Shard) .Build(); var wfAspNetCoreReporter = new WavefrontAspNetCoreReporter.Builder(applicationTags) .WithSource(waveFrontProxyConfiguration.Source) .ReportingIntervalSeconds(waveFrontProxyConfiguration.ReportingIntervalSeconds) .Build(wavefrontSender); var wavefrontSpanReporter = new WavefrontSpanReporter.Builder() .Build(wavefrontSender); ITracer tracer = new WavefrontTracer.Builder(wavefrontSpanReporter, applicationTags).Build(); services.AddWavefrontForMvc(wfAspNetCoreReporter, tracer); return services; } } }
-
Make the following changes in
Startup.cs
-
Add the following using statement:
using wavefront_sdk;
-
Add the following line at the end of the
ConfigureServices
method:services.AddWavefrontProxy(Configuration);
-
-
Add configuration for the respective project:
-
frontend
"wavefront-proxy": { "Hostname": "IP/HOST Name of Your Wavefront Proxy", "Application": "Frontend App", "Service": "Frontend UI" }
-
-
Build the applications:
dotnet publish -o .\publish
-
Assuming you already have Wavefront Proxy provisoned on TAS with the name wavefront-proxy, create a Yaml file called manifest.yml with the following contents:
applications: - name: frontend path: .\publish buildpacks: - https://github.com/cloudfoundry/dotnet-core-buildpack services: - wavefront-proxy env: ASPNETCORE_ENVIRONMENT: Development
-
Push our application
cf push