OpenTelemetry + Signoz
Tags: opentelemetry, dotnet, monitoring, csharp
Published: 2022-09-16 02:48:42

OpenTelemetry aims to standardize the extraction, transformation and export of data through a set of SDKs and APIs avoiding Vendor Lock-in. Instrumentation is “automatic” and allows you to define what you want to instrument, e.g. Sql Server, HttpClient, Postgre, gRPC, etc. Opentelemetry meets the observability pillars (Trace, Metric and Log).

For data visualization, you can choose between free solutions or large players like Dynatrace, Microsoft, NewRelic, Datadog, Amazon, etc.

Many OpenTelemetry examples use an Agent Collector that can be inside the same POD as your application or somewhere in your cluster. In Figure 1 , the agent is inside the Web API POD. The system sends the data to Collector which then exports it somewhere.

![Figure 1: Example using an Agent Collector to export data](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0r68aia9nb3ee1al7xst.png)

To make the POC (Proof Of Concept) simpler I used Signoz. _It is important to note that this example does not mean that it is the best or the worst way. It's one more way to do it._

Signoz is an open source tool that has the collector and dashboard to display the data. It has a community version and can be found on Github: [https://github.com/SigNoz/signoz](https://github.com/SigNoz/signoz)

Figure 2 shows how the components were, the collector is in Signoz and the application exports to using the OTLP protocol (OpenTelemetry Protocol). Several solutions support this protocol.

![Figure 2: Exporter using OLTP for Signs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1rqqvno8hcyt8z3gz3ky.png)

Let's comment on the code snippets necessary for the POC to work. The code is on Github:
https://github.com/hugobritobh/poc_pentelemetry

Figure 3 below shows the instrumentation of the Metrics. Added metrics for HttpClient (line 30), AspNetCore (line 31) and EventCounter (line 32). In debug mode I visualize the data through the console. Finally, I export the data to Signoz (using OTLP).


![Figure 3: Adding metrics](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2e1zuejdiws0gaw6bhf3.png)

Figure 4 below shows the Trace instrumentation. Added for AWS (line 58), AspNetCore (line 59) and HttpClient (line 60). Exporting the data to Signoz (using OTLP).


![Figure 4: Adding tracing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wg4t1mleuy9rv02efca4.png)

It is important to note that there are several instrumentations, but for this example I used only a few. Another point is that I didn't use the OpenTelemetry Log function, but it is possible to do and view it in Signoz.

Figure 5 below shows a trace of the C# Web API sample project displayed in the Console.


![Figure 5: Tracing a Web API](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7sxv3ophyi33d92gmfk3.png)

Figure 6 below shows a tracing of the C# Background Service (Console) project. In this example code, an Application Exception occurs (for example).


![Figure 6: Tracing a Background Service (Job)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vunakaxru20pvix4x3ab.png)

The next step is to install Signoz to visualize the data. You can choose a tutorial on the Signoz page itself. In this POC I used it with docker:[https://signoz.io/docs/install/docker/](https://signoz.io/docs/install/docker/)

The figure below shows a Signoz Dashboard from the Web API application. You can check response time, error percentage and other details.


![Figure 7: Signoz — General Web API Dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z17rr4kbpes9hzc726ve.png)

Figure 8 shows an overview of the behavior of an application, which in this case was the Test API.

![Figure 8 : Signoz — Test API Application Tracing List](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9fqsny0g06cj3dqu3hce.png)

It is possible to see details of Trace, that is, to go through the path that was taken by the application and even the values of the variables (depending on the instrumentation that was made) as shown in the figure below.


![Figure 9: Signoz — Details of a trace
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/26ikkt3dbpsptmyvqewa.png)

There is a menu on the left where we can view all the exceptions (Figure 10):


![Figure 10: Signoz — List of Exceptions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bq07z4q87iuobhouk4x3.png)

Figure 11 presents details of an exception.


![Figure 11: Signoz — Exception Details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ejnbtcvmyrd2jrbc2g5.png)


To visualize metrics, you can create Dashboards. I created one just for testing (for C#). You can import Json from this link: [https://github.com/hugobritobh/poc_pentelemetry/blob/main/Metric/Signoz/Dashboard/Metrics.json](https://github.com/hugobritobh/poc_pentelemetry/blob/main/Metric/Signoz/Dashboard/Metrics.json)


![Figure 12: Signoz — You can create multiple Dashboards.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cjqpd8603khw3nqbaqx.png)

I consider OpenTelemetry to be the future (one to two years from now). Its use and instrumentation is quite simple and you can choose a few ways to do it. For an environment that does not have any observability, I would use OpenTelemetry. However, if you have an APM tool, do not replace it with OpenTelemetry at this time.

Portuguese version of the article: [https://medium.com/@hugobritobh/opentelemetry-signoz-b3c204afa20b](https://medium.com/@hugobritobh/opentelemetry-signoz-b3c204afa20b)

Code on Github: [https://github.com/hugobritobh/poc_opentelemetry](https://github.com/hugobritobh/poc_opentelemetry)

Github: [https://github.com/hugobritobh](https://github.com/hugobritobh)