C# .NET 4 ASP
Error Monitoring / Logging / Tracing in .NET 4.x via the OpenTelemetry Protocol (OTLP).
Install the highlight-io .NET SDK.
Download the highlight SDK package from NuGet and save it to your project solution.
nuget install Highlight.ASP4
Set up your highlight.io browser SDK.
The installation differs from the normal frontend getting started guide in the configuration of the .NET trace propagation.
The TraceParentContext value is set based on the server trace context so that
client side tracing can carry the existing trace ID and session context.
Update your Views/Shared/_Layout.cshtml
HTML template entrypoint based on the following:
@using OpenTelemetry.Trace
@functions {
// set the `traceparent` meta tag to the current active span to propagate context to the client
string GetTraceParentContext()
{
var currentTrace = Tracer.CurrentSpan;
if (!currentTrace.IsRecording)
{
return "00-00-00-00";
}
var traceId = currentTrace.Context.TraceId;
var spanId = currentTrace.Context.SpanId;
return $"00-{traceId.ToHexString()}-{spanId.ToHexString()}-01";
}
}
<!DOCTYPE html>
<html>
<head>
<meta name="traceparent" content="@GetTraceParentContext()">
<script src="https://unpkg.com/highlight.run"></script>
<script>
H.init('<YOUR_PROJECT_ID>', {
serviceName: 'highlight-dot-net-frontend',
tracingOrigins: true,
networkRecording: {
enabled: true,
recordHeadersAndBody: true,
},
});
</script>
@* your standard head contents here... *@
</head>
<body>
@* your standard body contents here... *@
@RenderSection("scripts", required: false)
</body>
</html>
.NET supports OpenTelemetry instrumentation out of the box.
The Highlight.ASP4 NuGet package sets up OpenTelemetry instrumentation and export for highlight, injecting configuration functions for your ASPCore app to simplify instrumentation.
Bootstrap Highlight with your ASP 4 application MVC entrypoint.
Update your Global.asax.cs
application entrypoint to initialize highlight.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
Highlight.OpenTelemetry.Register(options =>
{
options.ProjectId = "<YOUR_PROJECT_ID>";
options.ServiceName = "example-dotnet-backend";
});
var logger = new LoggerConfiguration()
.Enrich.WithHighlight()
.WriteTo.HighlightOpenTelemetry(options =>
{
options.ProjectId = "<YOUR_PROJECT_ID>";
options.ServiceName = "example-dotnet-backend";
})
.CreateLogger();
logger.Information("Hello, World!");
}
protected void Application_End()
{
Highlight.OpenTelemetry.Unregister();
}
}
Verify your errors are being recorded.
Verify that the backend error handling works by triggering the code that reports the error to highlight and visiting the highlight errors portal.
Verify your backend logs are being recorded.
Visit the highlight logs portal and check that backend logs are coming in.
Verify your backend traces are being recorded.
Visit the highlight traces portal and check that backend traces are coming in.