百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
O

opentelemetry-rails-example

> 编程语言
开源

使用 OpenTelemetry 为 Rails 应用程序进行可观测性测试的参考仓库,采用自主托管的开源技术,可在任何环境中进行可观测性测试。

170 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

使用 OpenTelemetry 为 Rails 应用程序进行可观测性测试的参考仓库,采用自主托管的开源技术,可在任何环境中进行可观测性测试。

Observability for Rails with OpenTelemetry

A reference repository for instrumenting Rails apps with observability, using self-hosted, open-source tools rather than commercial observability platforms. It’s intended primarily for testing, experimentation, and debugging - not as an ultimate guidance for production setups.

It's opinionated in the way that included libraries and solutions do have alternatives. The goal is to stay aligned with Open Source and Open Standards. Suggestions and discussions around alternative approaches are welcome.

The stack is available in two forms:

  • as a Kamal deployment - see rails_app/config/deploy.yml
  • as a Docker Compose - see docker-compose.yml

The repository is being gradually updated as Open Telemetry SDK and Open Telemetry Contrib Packages for Ruby progress. (Note: as of now, the Ruby OTel instrumentation for metrics and traces is WIP.)

I recommend visiting open-telemetry/opentelemetry-demo for a complete example of instrumentation of a distributed system.

Table of Contents

  • Short demo
  • Included tech stack
    • Telemetry Data Producers
    • Collection and processing agents
    • Storage and query backends
    • Visualization
  • Deployment
    • Kamal
    • Docker Compose
  • Telemetry data
    • Logs
    • Traces
    • Metrics
    • Correlating logs, traces and metrics
  • TODOs

Short demo

Included tech stack

Telemetry Data Producers

Currently, the source of the telemetry data is a Ruby on Rails app, which acts as a web server and a SolidQueue background jobs processor. It's instrumented with OpenTelemetry to emit traces to the collector and outputs logs to the STDOUT.

Collection and processing agents

Agent(s) run on the same host as the Rails application. Their role is to collect, process, and export telemetry data. Up to this point, the architecture is vendor-agnostic, allowing to switch destinations or test multiple destinations without changes to the application code.

Included agents:

  • OpenTelemetry Collector
    • receives, processes, and exports traces
    • derives metrics from traces and exports them to Prometheus
  • Vector
    • scraps, processes, and exports logs

Storage and query backends

Since this demo presents a self-hosted approach, this part represents the long-term storage and query API backends. It's strongly recommended to run these services on a separate host to increase the likelihood of accessing observability data during application outages.

Included services:

  • Tempo for traces
  • Loki for logs
  • Prometheus for metrics

Visualization

  • Grafana dashboarding for traces, logs, and metrics

Deployment

Kamal

The Rails app includes a proposed Kamal deployment for the entire observability stack. The setup defines three servers:

  • App Server - runs the Rails application and telemetry agents
  • DB Server – hosts the database
  • Observability Server – runs Grafana and stores telemetry data (traces, logs, metrics)

You can find the full configuration in rails_app/config/deploy.yml

Note: This deployment setup is provided as a general example. While it has been successfully tested in a live environment, it's not intedned to be used on-spot. You may need to adapt it to suit your specific requirements.

Docker Compose

Docker Compose allows to run the entire stack locally and experiment with it.

Most of the commands to operate this repo are available through the Makefile.

  1. Start the stack by running:
bash
make up
  1. Make a sample request:
bash
curl localhost:3000/demo/database_bulk_read

or you can run the included load tests with k6. For more details, check the k6 subdirectory: k6 load test

  1. Visit the Grafana Rack API Performance dashboard to see graphs http://localhost:3001/d/7NAwfw5ab/rack-api-performance

Telemetry data

Logs

The rails_semantic_logger gem is used in the Rails app to produce and output logs to the STDOUT in the JSON format. Then, Vector scraps logs from the docker's standard output, removes redundant fields, and pushes them to Loki in a more human-friendly fmt format. Loki stores the logs and makes them available for querying in Grafana.

In addition to standard fields, there are extra fields included: request_id, trace_id, span_id and operation.

Traces

The Rails app is auto-instrumented with suitable Open Telemetry Contrib packages. The list of all available packages can be found on the OpenTelemetry registry.

Traces produced by the instrumentation are being sent to the OpenTelemetry Collector. Then, OpenTelemetry Collector applies tail sampling to drop noisy traces (with the latency <10ms), and exports them to Tempo which stores the traces and makes them available for querying in Grafana.

Metrics

The Rails application does not emit metrics directly. Instead, metrics are derived from spans (all, not samples) using the spanmetrics processor in the OpenTelemetry Collector.

Correlating logs, traces and metrics

The real synergy comes from correlating all the pillars of observability - logs, traces, and metrics - together. It's super convenient to easily navigate from a log to a related trace or even from a spike in metric to a related trace. That's the main motivation behind including Grafana in the stack - a single UI that is capable of presenting and correlating all the data.

TODOs

  • Own metrics with StatsD

Issues· 1 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言