OpenTelemetry with Clickhouse Backend
Updating compose file
For a permanent setup, we just need to comment out the Jaeger service in our docker compose file and uncomment the otel-collector, clickhouse and grafana services.
Do not forget to comment the Jaeger service as we are using Jaeger's all-in-one service which acts as a collector as well as the Jaeger UI.
Since we are using the official opentelemetry colllector above, this will leave to port conflicts if not commented.
Config files
Now we need a couple of config files to get this working.
otel-collector-config.yaml
The collector config file is pretty straight forward. We are using the all-in-one config file which is located at otel/otel-collector-config.yaml
. It basically describes how we want to receive and send telemetry data.
You can read more about configuring the collector here
clickhouse-init
This is a folder which contains a single file init-db.sql
which is used to initialize the clickhouse database.
This sql file just does
grafana.ini
This is the grafana config file which is used to configure the grafana instance. It is located at otel/grafana.ini
datasource.yaml
This is the datasource config file which is used to configure the clickhouse datasource in grafana using Clickhouse's official Grafana Plugin.
It is located at otel/datasource.yaml
.
Info
As an alternative, you can also use Altinity's Grafana Plugin for Clickhouse as an alternative or in tandem with the official plugin.
Starting the services
Let's quickly pull all the above config files and directory structure before staring the services.
Also we need to enable the otel environment variables and update the otel endpoint to otel-collector:4317
.env | |
---|---|
And finally we can start docker compose up -d
.
Just like earlier to make sure everything is working as intented we can hit the below backend endpoint
http://localhost:4000/login/test
And view the telemetry data in grafana at http://localhost:3001/
Default credentials are admin
as username and password.
Once logged in, navigate to Home -> Connections -> Data sources
and we can see ZeroShare Clickhouse Otel
- Click On Explore
- Select Query type as
Logs
orTraces
- Enable
Use Otel
- Run Query
Even though metrics is logged in clickhouse, I haven't setup an ui for it. Prometheus or something can be configured as required.
We can view the metrics related data in Clickhouse using the below query
┌─name───────────────────────────────┐
1. │ otel_logs │
2. │ otel_metrics_exponential_histogram │
3. │ otel_metrics_gauge │
4. │ otel_metrics_histogram │
5. │ otel_metrics_sum │
6. │ otel_metrics_summary │
7. │ otel_traces │
8. │ otel_traces_trace_id_ts │
9. │ otel_traces_trace_id_ts_mv │
└────────────────────────────────────┘