使用 OpenTelemetry 为 Rails 应用程序进行可观测性测试的参考仓库,采用自主托管的开源技术,可在任何环境中进行可观测性测试。
使用 OpenTelemetry 为 Rails 应用程序进行可观测性测试的参考仓库,采用自主托管的开源技术,可在任何环境中进行可观测性测试。
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:
rails_app/config/deploy.ymldocker-compose.ymlThe 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.
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.
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:
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:
The Rails app includes a proposed Kamal deployment for the entire observability stack. The setup defines three servers:
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 allows to run the entire stack locally and experiment with it.
Most of the commands to operate this repo are available through the Makefile.
make upcurl localhost:3000/demo/database_bulk_reador you can run the included load tests with k6. For more details, check the k6 subdirectory: k6 load test
Rack API Performance dashboard to see graphs http://localhost:3001/d/7NAwfw5ab/rack-api-performanceThe 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.
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.
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.
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.
暂无开放 Issues,或尚未同步最近议题。