mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2026-10-28 16:18:23 +08:00
Rename the service-name placeholder from <MY_SERVICE_NAME> to <YOUR_SERVICE_NAME> across the SDK pages and the validator allowlist, matching the <YOUR_...> convention of the other standardized placeholders.
97 lines
3.2 KiB
Plaintext
97 lines
3.2 KiB
Plaintext
---
|
|
slug: /use-cases/observability/clickstack/sdks/ruby-on-rails
|
|
description: 'Ruby on Rails SDK for ClickStack - The ClickHouse Observability Stack'
|
|
title: 'Ruby on Rails'
|
|
doc_type: 'guide'
|
|
keywords: ['clickstack', 'sdk', 'logging', 'integration', 'application monitoring']
|
|
---
|
|
|
|
import { ClickStackIntegrates } from '/snippets/components/ClickStackIntegrates/ClickStackIntegrates.jsx'
|
|
|
|
<ClickStackIntegrates signals={['traces']} />
|
|
|
|
_To send logs to ClickStack, please send logs via the [OpenTelemetry collector](/clickstack/ingesting-data/collector)._
|
|
|
|
## Getting started {#getting-started}
|
|
|
|
### Install OpenTelemetry packages {#install-otel-packages}
|
|
|
|
Use the following command to install the OpenTelemetry package.
|
|
|
|
```shell
|
|
bundle add opentelemetry-sdk opentelemetry-instrumentation-all opentelemetry-exporter-otlp
|
|
```
|
|
|
|
### Configure OpenTelemetry + logger formatter {#configure-otel-logger-formatter}
|
|
|
|
Next, you'll need to initialize the OpenTelemetry tracing instrumentation
|
|
and configure the log message formatter for Rails logger so that logs can be
|
|
tied back to traces automatically. Without the custom formatter, logs won't
|
|
be automatically correlated together in ClickStack.
|
|
|
|
In `config/initializers` folder, create a file called `hyperdx.rb` and add the
|
|
following to it:
|
|
|
|
```ruby
|
|
# config/initializers/hyperdx.rb
|
|
|
|
require 'opentelemetry-exporter-otlp'
|
|
require 'opentelemetry/instrumentation/all'
|
|
require 'opentelemetry/sdk'
|
|
|
|
OpenTelemetry::SDK.configure do |c|
|
|
c.use_all() # enables all trace instrumentation!
|
|
end
|
|
|
|
Rails.application.configure do
|
|
Rails.logger = Logger.new(STDOUT)
|
|
# Rails.logger.log_level = Logger::INFO # default is DEBUG, but you might want INFO or above in production
|
|
Rails.logger.formatter = proc do |severity, time, progname, msg|
|
|
span_id = OpenTelemetry::Trace.current_span.context.hex_span_id
|
|
trace_id = OpenTelemetry::Trace.current_span.context.hex_trace_id
|
|
if defined? OpenTelemetry::Trace.current_span.name
|
|
operation = OpenTelemetry::Trace.current_span.name
|
|
else
|
|
operation = 'undefined'
|
|
end
|
|
|
|
{ "time" => time, "level" => severity, "message" => msg, "trace_id" => trace_id, "span_id" => span_id,
|
|
"operation" => operation }.to_json + "\n"
|
|
end
|
|
|
|
Rails.logger.info "Logger initialized !! 🐱"
|
|
end
|
|
```
|
|
|
|
### Configure environment variables {#configure-environment-variables}
|
|
|
|
Afterwards you'll need to configure the following environment variables in your shell to ship telemetry to ClickStack via the OpenTelemetry collector:
|
|
|
|
<Tabs>
|
|
<Tab title="Managed ClickStack">
|
|
|
|
```shell
|
|
export OTEL_EXPORTER_OTLP_ENDPOINT=<YOUR_OTEL_COLLECTOR_HTTP_ENDPOINT> \
|
|
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
|
|
OTEL_SERVICE_NAME='<YOUR_SERVICE_NAME>' \
|
|
```
|
|
|
|
</Tab>
|
|
|
|
<Tab title="ClickStack Open Source">
|
|
|
|
```shell
|
|
export OTEL_EXPORTER_OTLP_ENDPOINT=<YOUR_OTEL_COLLECTOR_HTTP_ENDPOINT> \
|
|
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
|
|
OTEL_SERVICE_NAME='<YOUR_SERVICE_NAME>' \
|
|
OTEL_EXPORTER_OTLP_HEADERS='authorization=<YOUR_INGESTION_API_KEY>'
|
|
```
|
|
|
|
</Tab>
|
|
</Tabs>
|
|
|
|
_The `OTEL_SERVICE_NAME` environment variable is used to identify your service
|
|
in the HyperDX app, it can be any name you want._
|
|
|
|
The `OTEL_EXPORTER_OTLP_HEADERS` environment variable contains the API Key available via HyperDX app in `Team Settings → API Keys`.
|