This tutorial was initially posted on SigNoz Blog and is written by Ricardo Paiva
OpenTelemetry can be utilized to instrument your Elixir purposes to generate telemetry knowledge. The telemetry knowledge can then be visualized utilizing an observability device to watch your Elixir utility efficiency. On this tutorial, we are going to use OpenTelemetry Elixir libraries to instrument an Elixir utility after which visualize it utilizing SigNoz.
Someplace throughout the lifetime of an utility, it is inevitable that it’s going to have some efficiency points. You probably have arrange observability to your purposes, it could possibly assist you determine these efficiency points rapidly.
Introduction
For cloud-native purposes, OpenTelemetry supplies a framework to arrange observability. It consists of a set of instruments, APIs, and SDKs that you should use to instrument, generate, gather, and export telemetry knowledge for evaluation so as to perceive your software program’s efficiency and conduct.
On this tutorial, we’ll present you the right way to monitor your Elixir utility utilizing OpenTelemetry and Signoz. We’ll give attention to the commonest and fundamental Elixir combo:Β Phoenix + Ecto.
As soon as every part is put in and configured, you’ll see how a lot time your endpoints and database operations are taking. The collected knowledge, when visualized by a backend device like SigNoz will allow you to to troubleshot issues, determine bottlenecks and in addition discover utilization patterns that may allow you to enhance your utility pro-actively.
OpenTelemetry and SigNoz
OpenTelemetry libraries can solely allow the era of telemetry knowledge. You want a backend that takes within the knowledge for storage and visualization. SigNoz is a full-stack open-source APM device that can be utilized for storing and visualizing the telemetry knowledge collected with OpenTelemetry. It’s constructed natively on OpenTelemetry and works on the OTLP knowledge codecs.
SigNoz supplies question and visualization capabilities for the end-user and comes with out-of-box charts for utility metrics and traces.
Now letβs get all the way down to the right way to implement OpenTelemetry in your Elixir utility.
Putting in SigNoz
First, it’s good to set up SigNoz in order that OpenTelemetry can ship the info to it.
SigNoz may be put in on macOS or Linux computer systems in simply three steps through the use of a easy set up script.
The set up script routinely installs Docker Engine on Linux. Nevertheless, on macOS, you have to manually set up Docker Engine earlier than working the set up script.
git clone -b major https://github.com/SigNoz/signoz.git
cd signoz/deploy/
./set up.sh
You possibly can go to our documentation for directions on the right way to set up SigNoz utilizing Docker Swarm and Helm Charts.
If you end up achieved putting in SigNoz, you possibly can entry the UI atΒ http://localhost:3301
Instrumenting an Elixir Phoenix utility with OpenTelemetry
Weβll give attention to instrumenting one of the crucial widespread combos of the Elixir world: Phoenix + Ecto.
Step 1: Add the required dependencies
Step one to instrument your Elixir utility with OpenTelemetry is so as to add the required dependencies to your combine.exs
file and fetch them with combine deps.get
{:opentelemetry, "~> 1.0.3"},
{:opentelemetry_exporter, "~> 1.0.3"},
{:opentelemetry_phoenix, "~> 1.0.0"},
{:opentelemetry_ecto, "~> 1.0.0"}
Step 2: Configure the Elixir utility to export telemetry knowledge
Then we have to configure our utility to export telemetry knowledge. There are two issues that it’s good to set:
-
YOUR_APP_NAME
You possibly can put your utility or service title right here for identification. -
OTEL Collector endpoint
The OTEL collector comes bundled with SigNoz set up. Since, we put in SigNoz on our native machine, the endpoint ishttp://localhost:4318
.
config :opentelemetry, :useful resource, service: %{title: "YOUR_APP_NAME"}
config :opentelemetry, :processors,
otel_batch_processor: %{
exporter: {
:opentelemetry_exporter,
%{endpoints: ["http://localhost:4318"]}
}
}
Step 3: Initialize telemetry handlers
As it’s documented within the opentelemetry_phoenix
and opentelemetry_ecto
hexdocs.pm pages, we have to initialize each telemetry handlers.
OpentelemetryPhoenix.setup()
OpentelemetryEcto.setup([:your_app_name, :repo])
:your_app_name
needs to be changed by your app title and congratulations, you’ve gotten instrumented your utility with OpenTelemetry.
Monitor your Elixir utility with Signoz
Now you can monitor your Elixir utility with SigNoz. Whether or not youβre utilizing a Phoenix to create REST APIs or HTML purposes, it’s good to generate some knowledge by interacting along with your utility.
On this GitHub repository youβll discover an Elixir Phoenix API that exposes a few endpoints however weβll give attention to one: /api/customers
that may return a listing of customers which might be saved on the respective database desk.
If you wish to use this pattern utility, please confer with the README file within the repository so as to make it run regionally.
Now, letβs do a few calls to one of many endpoints.
curl http://localhost:4000/api/customers
This could generate some telemetry knowledge, which might be exported to SigNoz OTEL collector.
You possibly can entry SigNoz UI at http://localhost:3301/application (after signing up) to see your Elixir Phoenix API being monitored. The opposite purposes that you simply see are pattern purposes that come bundled with the set up.
Monitor utility metrics of your Elixir app
SigNoz supplies out-of-box charts for utility metrics like latency, requests per sec, error proportion, and many others.
Analyze your tracing knowledge with the Traces tab
Your utility metrics are additionally seamlessly correlated with tracing knowledge. You possibly can select any timestamp or endpoint to discover Traces throughout that period.
Full breakdown of requests
You possibly can see an entire breakdown of the request with Flamegraphs and Gantt charts. You possibly can click on on any span within the spans desk to entry it.
From our Elixir utility, we are able to see a hint consisting of two spans. The guardian one corresponds to the HTTP request and the second corresponds to the database name.
Troubleshooting an error
SigNoz may also assist in troubleshooting errors with error monitoring.
For this, weβll need to power an error and we are able to do that by doing the next request:
curl http://localhost:4000/api/customers/one thing
This can trigger an error as a result of this endpoint is anticipating an integer
and never a string
You possibly can go to http://localhost:3301/errors to take a look at the errors in your utility.
Should you click on on the error, youβll see some extra particulars in regards to the error and even the stack hint.
Conclusion
Utilizing OpenTelemetry libraries, you possibly can instrument your Elixir purposes for establishing observability. You possibly can then use an open-source APM device like SigNoz to make sure the graceful efficiency of your Elixir purposes.
OpenTelemetry is the long run for establishing observability for cloud-native apps. It’s backed by an enormous neighborhood and covers all kinds of know-how and frameworks. Utilizing OpenTelemetry, engineering groups can instrument polyglot and distributed purposes with peace of thoughts.
SigNoz is an open-source observability device that comes with a SaaS-like expertise. You possibly can check out SigNoz by visiting its GitHub repo π
You probably have any questions or want any assist in setting issues up, be a part of our slack neighborhood and ping us inΒ #assist
channel.
Additional Studying
Implementing OpenTelemetry in Angular application
Monitor your Nodejs application with OpenTelemetry and SigNoz