clj-otel

Ion Simion 2024-05-30T09:30:47.414359Z

Hi everyone! I’m new with otel and might have some facts confused. Is there a way to render metrics instead of exporting them to a collector? I assumed clj-otel.exporter.prometheus would allow that but is blank when I access the host/port.

Dimitar Uzunov 2024-05-31T08:58:40.305199Z

You can also send metrics directly to an otel backend that can visualize them

Ion Simion 2024-05-31T08:59:29.604779Z

Thank you, I don’t wish to send the metrics, I want to have them built in the same app, so it just exposes the metrics for pulling.

Dimitar Uzunov 2024-05-31T09:01:04.484889Z

https://opentelemetry.io/img/otel-diagram.svg - perhaps you are looking for an in-memory time-series database of some sort?

Ion Simion 2024-05-31T09:01:41.043079Z

yes yes exactly, but didn’t find an example of implementing with clj-otel

Dimitar Uzunov 2024-05-31T09:03:08.602329Z

yeah I’m not sure otel is intended to be used in this scenario, it is about the observability of applications

Dimitar Uzunov 2024-05-31T09:04:04.226859Z

@simionionion perhaps you can describe your need in #find-my-lib?

Ion Simion 2024-05-31T09:05:37.698979Z

thank you, I guess my only option would be with the java interop around the open-telemetry, a lot to figure out though ..

Dimitar Uzunov 2024-05-31T09:06:56.609859Z

if you mean you just want to view the application traces and metrics locally you can run jeager locally pretty easily: https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-api/0.2.6/doc/tutorial#_start_telemetry_backend

Ion Simion 2024-05-31T09:08:14.240079Z

Yes, done the tutorial, however still fits as a separate collector and isn’t accepted

steffan 2024-05-31T11:27:26.436639Z

You can export metrics directly to a Prometheus instance without going via any Collector(s). The divisor-app is a small example that exports directly to Prometheus. https://github.com/steffan-westcott/clj-otel/tree/master/examples/divisor-app

👀 1
steffan 2024-05-31T11:32:16.827869Z

`divisor-app` uses the OpenTelemetry agent at runtime. By default, the agent attempts to export metrics using OTLP, so the option otel.metrics.exporter=prometheus is required to use Prometheus instead. You'll see this option (and others) in the deps.edn of the example.

Ion Simion 2024-05-31T11:33:54.001209Z

So it does a push exporting right? my task is to be a pull server, so I can add it as source in Prometheus or any other similar

steffan 2024-05-31T11:35:58.796649Z

divisor-app includes a Prometheus configuration, where the Prometheus instance scrapes (pulls) metrics from an HTTP endpoint provided by the instrumentation agent.

Ion Simion 2024-05-31T11:36:30.057709Z

oh, yes, no instrumentation agent, all instrumenting will be internal..

steffan 2024-05-31T11:37:46.611089Z

The instrumentation agent runs as a Java agent, so it is in the same OS process as the main application.

Ion Simion 2024-05-31T11:40:20.464889Z

no java agent, all metrics would be manually instrumented around the code

steffan 2024-05-31T11:44:31.271059Z

Manual instrumentation is the primary use case of clj-otel, so you are in the right place 😄 You have the option of using the Java agent or not when using clj-otel. Using the agent is useful, as you get lots of high-quality instrumentation with no effort. Please take a look at this https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-api/0.2.6/doc/concepts#_instrumenting_libraries_and_applications.

👀 1
Ion Simion 2024-05-31T11:50:34.377799Z

In iopates package there was a reitit middleware that used io.prometheus.server to render the metrics .. I have to do something similar but with open-telemetrics .. my view is foggy, confusing aspects .. I understand clj-otel doesn’t have such a middlerware, and most probably I need some “in memory” thingy .. Or perhaps I could use jetty to render the registry metrics? 🤯

steffan 2024-05-31T11:55:11.999349Z

Perhaps to clear your view, might I suggest looking through the https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-api/0.2.6/doc/concepts documentation? I think you may be confusing instrumentation (getting the telemetry data) with visualisation (analysis and display of telemetry data). Telemetry backends are responsible for visualisation.

steffan 2024-05-31T12:02:18.352339Z

Prometheus ships with a very basic display of metrics that it collects (scrapes). Telemetry backends (like Grafana and many others) integrate with your Prometheus instance to give a more comprehensive display and analysis.

Ion Simion 2024-05-31T12:04:58.061549Z

Yes, that’s what I need, a basic display of metrics, not a collector or exporter to collector.

steffan 2024-05-31T12:08:58.450149Z

In the OpenTelemetry model, that display would be provided by a telemetry backend. clj-otel scope does not include making a telemetry backend, as it's focus is on the source of the telemetry data, not the visualisation.

Ion Simion 2024-05-31T12:10:37.369809Z

Yess, but it exports right ? and instead of export it, can’t I store it in memory, and on request, display it? ..

steffan 2024-05-31T12:13:29.861129Z

The Prometheus exporter does not store metrics, as far as I know. It exports metrics in batches of a few seconds' worth of metrics at a time.

1
steffan 2024-05-31T12:14:33.059499Z

A Prometheus instance stores the metrics it scrapes, so I think you may be duplicating effort.

Ion Simion 2024-05-31T12:15:29.313519Z

quoting - “Must not be specific to Prometheus, but to OpenTelemetry, in case tomorrow we switch to something else”

steffan 2024-05-31T12:22:05.596619Z

It sounds like you need to investigate the use cases for analysis and display of your metrics. You will need to develop queries against those metrics, which will likely involve PromQL or similar. OpenTelemetry and clj-otel is a standardisation effort around the capture and forwarding of telemetry data to compatible telemetry backends. I think it would be a lot of effort (but not impossible) to create your own telemetry backend, so you may need to look at the capabilities of existing backends and see if they fit your needs.

Ion Simion 2024-05-31T22:22:46.715189Z

Thank you very much for your time and patience. I will continue on Monday. Have an awesome weekend!

steffan 2024-06-01T09:13:22.297029Z

Correction: divisor-app in fact does not use the OpenTelemetry instrumentation agent. Instead, it uses the autoconfigure SDK extension. I'm sorry for any confusion caused. This https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-api/0.2.6/doc/guides#_configure_and_run_an_application_with_telemetry explains the various options for configuring and running an application with telemetry.

✅ 1