Otel instrumenting .Net OLTP

DeveloperSteve
Lumigo
5 min readMar 22, 2024

--

Otel instrumenting .Net OLTP

The .NET framework is a tool for creating various applications, from interactive web services to robust enterprise solutions. It has an extensive collection of libraries, supports multiple languages, and offers advanced tools to build high-performance, scalable applications that can meet a multitude of requirements. The framework constantly adapts to changing software needs and is supported by a dynamic ecosystem of add-ons and a passionate community.

Navigating the complexities of performance optimization and issue resolution within the intricate web of .NET’s distributed systems presents a notable challenge. The dense network of services and components characteristic of these systems can obscure the root causes of issues, complicating the troubleshooting process. Enter OpenTelemetry, a pivotal instrument in this landscape, offering a structured means to collect and scrutinize telemetry data, including logs, metrics, and traces. The fusion of OpenTelemetry with the .NET framework transforms the approach to identifying and addressing issues, enhancing transparency in the operational dynamics of applications and facilitating the oversight of multifaceted, distributed architectures.

Now, let’s take a quick look at OpenTelemetry and its role in augmenting .NET application development.

OpenTelemetry (also known as Otel)

OpenTelemetry is a comprehensive framework that provides consistent and high-quality telemetry data for cloud-native software applications. It consists of APIs, libraries, agents, and instruments, which work together to collect, refine, and direct telemetry data, including metrics, traces, and application logs. The primary goal of OpenTelemetry is to simplify the monitoring and understanding of systems, which helps to improve performance, quickly detect issues, and gain a deeper understanding of application behavior in live settings. OpenTelemetry combines observability aspects by merging logging, tracing, and metrics into a unified perspective of system performance and activities.

Behold… OpenTelemetry

Capturing telemetry data at various operational junctures is the initial step in instrumenting the application. This can be achieved using existing libraries and frameworks for automatic instrumentation or manual coding for specific telemetry capture. After collection, the data undergoes processing and enrichment to add valuable context for more insightful analysis and troubleshooting. This telemetry can then be dispatched to diverse analytical tools and backend systems for visualization and querying. This seamless process facilitates the generation of insights regarding application performance and dynamics, fostering a holistic view of applications, encompassing broad performance metrics down to granular request traces.

Central to the OpenTelemetry ecosystem, the OpenTelemetry Protocol (OTLP) stands out as an efficient, scalable conduit for transferring telemetry data to backend analytical platforms. Engineered for lightness and neutrality, OTLP ensures wide compatibility and minimal impact on performance. It accommodates gRPC and HTTP for versatile data transfer and is tailored for batch processing, ensuring the streamlined movement of substantial telemetry volumes with optimized resource usage. OTLP’s design guarantees the effective and dependable conveyance of telemetry to backend systems, where it can be further leveraged to foster application performance and dependability enhancements.

Demo App Testing

Crafting a Minimal .NET Application with OpenTelemetry and OTLP demonstrates a straightforward approach to incorporating OpenTelemetry within a .NET console application, specifically using the OpenTelemetry Protocol (OTLP) to forward trace data to Lumigo, a platform designed to offer actionable insights into application performance and issues. The initial setup involves creating a new .NET console application and adding the required OpenTelemetry NuGet packages, which are pivotal for the instrumentation and export of telemetry data. The dotnet new console command kick-starts the project, followed by adding packages such as OpenTelemetry, OpenTelemetry.Exporter.OpenTelemetryProtocol, and OpenTelemetry.Instrumentation.Http, which together lay down the foundation for telemetry data collection and export.

The integration’s crux lies in configuring the OpenTelemetry SDK within the application’s Program.cs file, where a tracer provider is set up with a resource builder to define service details and the OTLP exporter to specify the endpoint and authentication token for Lumigo. This setup includes the AddHttpClientInstrumentation method to automatically collect telemetry data from HTTP client requests and the AddOtlpExporter method to direct this data to the specified Lumigo endpoint using an authorization token. This configuration is instrumental in initiating the telemetry data flow from the application to Lumigo, allowing for detailed observation and analysis of the application’s operations.

When performing a basic function in the application, an ActivitySource instance is utilized to initiate an activity named “SampleOperation,” which contains the application’s logic. This activity, along with its child “ChildOperation,” is labeled with custom attributes to enhance the trace data. Next, the application generates trace data by simulating activity within these operations, which is then sent to Lumigo through OTLP. This straightforward yet efficient example illustrates the usefulness of OpenTelemetry in .NET applications for monitoring and troubleshooting intricate distributed systems, allowing developers to gain comprehensive insights into their application’s actions and performance concerns.

Take it for a Spin

When monitoring the performance of .NET applications, integrating .NET frameworks with OpenTelemetry and using Lumigo’s tracing can significantly boost visibility. OpenTelemetry’s powerful features include efficient auto-instrumentation, simplified telemetry data collection, and eliminating the need for complex coding. If you want to find out more and test it out for yourself, check out the article Implementing OpenTelemetry in .Net for all the code and examples to get a working demo up and running.

Sign up now for Lumigo to get detailed insights into the application’s operations, making it easier to comprehend complex .NET environments.

--

--

DeveloperSteve
Lumigo

Lilypad Network Chief Innovation Officer | Director The Coochin Company | 30+ years Developer | 10+ years Data Analyst | 10+ years Devrel