> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-parallel-read-in-order-multi-part.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> ClickStack용 Ruby on Rails SDK - ClickHouse Observability Stack

# Ruby on Rails

export const ClickStackIntegrates = ({signals = []}) => {
  const list = Array.isArray(signals) ? signals : String(signals).split(",");
  const supported = list.map(s => String(s).trim().toLowerCase());
  const pillStyle = {
    display: "inline-flex",
    alignItems: "center",
    padding: "0.125rem 0.625rem",
    borderRadius: "9999px",
    fontSize: "0.8125rem",
    fontWeight: 500,
    lineHeight: 1.6,
    color: "#161517",
    backgroundColor: "#faff69",
    border: "1px solid rgba(0, 0, 0, .1)",
    marginRight: "0.5rem"
  };
  return <div style={{
    margin: "0 0 1.25rem"
  }}>
      <span style={{
    marginRight: "0.5rem"
  }}>이 가이드에서 통합하는 항목:</span>
      {supported.includes("logs") && <span style={pillStyle}>로그</span>}
      {supported.includes("metrics") && <span style={pillStyle}>메트릭</span>}
      {supported.includes("traces") && <span style={pillStyle}>트레이스</span>}
    </div>;
};

<ClickStackIntegrates signals={['traces']} />

*로그를 ClickStack으로 보내려면 [OpenTelemetry collector](/ko/clickstack/ingesting-data/collector)를 통해 전송하십시오.*

<h2 id="getting-started">
  시작하기
</h2>

<h3 id="install-otel-packages">
  OpenTelemetry 패키지 설치
</h3>

다음 명령으로 OpenTelemetry 패키지를 설치하십시오.

```shell theme={null}
bundle add opentelemetry-sdk opentelemetry-instrumentation-all opentelemetry-exporter-otlp
```

<h3 id="configure-otel-logger-formatter">
  OpenTelemetry + 로거 포매터 구성
</h3>

다음으로, OpenTelemetry tracing instrumentation을 초기화하고
Rails 로거의 로그 메시지 포매터를 구성해야 로그가 자동으로
트레이스와 연결되도록 할 수 있습니다. 사용자 지정 포매터가 없으면 로그와 트레이스는
ClickStack에서 자동으로 연관되지 않습니다.

`config/initializers` 폴더에서 `hyperdx.rb`라는 파일을 생성하고
다음을 추가하십시오:

```ruby theme={null}
# config/initializers/hyperdx.rb

require 'opentelemetry-exporter-otlp'
require 'opentelemetry/instrumentation/all'
require 'opentelemetry/sdk'

OpenTelemetry::SDK.configure do |c|
  c.use_all() # 모든 트레이스 계측을 활성화합니다!
end

Rails.application.configure do
  Rails.logger = Logger.new(STDOUT)
  # Rails.logger.log_level = Logger::INFO # 기본값은 DEBUG이며, 프로덕션 환경에서는 INFO 이상으로 설정하는 것을 권장합니다
  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
```

<h3 id="configure-environment-variables">
  환경 변수 설정
</h3>

이제 OpenTelemetry collector를 통해 telemetry를 ClickStack으로 전송할 수 있도록 셸에서 다음 환경 변수를 설정해야 합니다:

<Tabs>
  <Tab title="Managed ClickStack">
    ```shell theme={null}
    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 theme={null}
    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>

*`OTEL_SERVICE_NAME` 환경 변수는 HyperDX 앱에서 서비스를 식별하는 데 사용되며,
원하는 이름으로 자유롭게 지정할 수 있습니다.*

`OTEL_EXPORTER_OTLP_HEADERS` 환경 변수에는 HyperDX 앱의 `Team Settings → API Keys`에서 확인할 수 있는 API Key가 포함됩니다.
