> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# telemetrygen으로 합성 OpenTelemetry 데이터 생성하기

> telemetrygen을 사용해 다양한 합성 로그, 트레이스, 메트릭을 완전 관리형 ClickHouse Observability로 전송합니다

> [tab] 완전 관리형
>
> [베타 서비스](https://clickhouse.com/docs/reference/settings/beta-and-experimental-features.md#beta-features)
>
> [`telemetrygen`](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/cmd/telemetrygen) 는 OpenTelemetry Collector Contrib의 데이터 생성기입니다. 합성 OTLP 로그, trace, 메트릭을 생성하며, 여러 서비스, 로그 심각도, 스팬 상태 및 자식 스팬, 다양한 메트릭 타입 등 데이터의 형태를 원하는 대로 조정할 수 있는 플래그를 제공합니다. 이 도구로 완전 관리형 ClickHouse Observability에 테스트 데이터를 전송한 다음, 검색 및 차트 탐색기에서 결과를 확인하세요.
>
> **1. 사전 요구 사항**
>
> 완전 관리형 ClickHouse Observability 서비스가 이미 생성되어 있어야 하며, 해당 서비스의 관리형 텔레메트리 엔드포인트에 네트워크로 액세스할 수 있어야 합니다. 자세한 내용은 [완전 관리형 시작 가이드](https://clickhouse.com/docs/ko/clickstack/observability/getting-started.md)를 참조하십시오.
>
> **2. telemetrygen 설치**
>
> Docker가 설치되어 실행 중인 상태에서, 공식 컨테이너 이미지로 `telemetrygen`을 실행하는 래퍼를 다음과 같이 정의하세요:
>
> ```shell theme={null}
> telemetrygen() {
>   docker run --rm \
>     ghcr.io/open-telemetry/opentelemetry-collector-contrib/telemetrygen:latest "$@"
> }
> ```
>
> 또는 Go를 사용해 바이너리를 설치하십시오:
>
> ```shell theme={null}
> go install github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen@latest
> ```
>
> **3. 환경 변수 설정**
>
> ClickHouse Observability 서비스를 열고 **팀 설정 → Managed Telemetry**로 이동하십시오. **OTLP HTTP 엔드포인트**와 **API Key**를 복사하십시오.
>
> ![마스킹된 OTLP HTTP 엔드포인트와 API Key가 표시된 팀 설정의 Managed Telemetry](https://mintcdn.com/private-7c7dfe99/Zk1feNn6fCQBpold/images/clickstack/getting-started/observability-managed-telemetry.png?fit=max\&auto=format\&n=Zk1feNn6fCQBpold\&q=85\&s=e63a2ac2e6ab996d3fc360ebe0f487a5)
>
> 엔드포인트는 `https://` 접두사를 제거하고 호스트와 포트만 지정하십시오. 예를 들어 `https://YOUR_OTEL_ENDPOINT:4318`은 `YOUR_OTEL_ENDPOINT:4318`로 지정합니다. `/v1/logs`와 같은 시그널 경로는 덧붙이지 마십시오.
>
> ```shell theme={null}
> export OTEL_ENDPOINT='YOUR_OTEL_ENDPOINT:4318'
> printf "API key: "
> read -r -s OTEL_API_KEY
> printf "\n"
> export OTEL_API_KEY
> ```
>
> 각 명령에서 달라지는 부분(서비스, 심각도, 상태, 속성)만 지정할 수 있도록 간단한 `tg` 헬퍼 함수를 정의하십시오:
>
> ```shell theme={null}
> tg() { local signal=$1; shift; telemetrygen "$signal" \
>   --otlp-endpoint "${OTEL_ENDPOINT}" --otlp-http \
>   --otlp-header "authorization=\"Bearer ${OTEL_API_KEY}\"" \
>   --rate 5 --duration 30s "$@"; }
> ```
>
> 보조 프로세스는 인증서 검증이 적용된 TLS 기반 OTLP HTTP를 사용합니다. `--otlp-insecure` 및 `--otlp-insecure-skip-verify` 옵션은 지정하지 마십시오. 각 명령은 30초 동안 실행되며, 관리형 텔레메트리 API Key로 인증합니다.
>
> **4. 로그 생성**
>
> 3개의 서비스에서 정보, 경고, 오류 로그를 전송합니다.
>
> ```shell theme={null}
> tg logs --service frontend --severity-text Info  --severity-number 9  --body "GET /api/products 200" \
>   --otlp-attributes 'deployment.environment="production"' \
>   --telemetry-attributes 'http.method="GET"' --telemetry-attributes 'http.status_code="200"'
> tg logs --service checkout --severity-text Warn  --severity-number 13 --body "retrying payment authorization" \
>   --otlp-attributes 'deployment.environment="production"' \
>   --telemetry-attributes 'http.method="POST"'
> tg logs --service payment  --severity-text Error --severity-number 17 --body "payment gateway timeout" \
>   --otlp-attributes 'deployment.environment="production"' \
>   --telemetry-attributes 'http.status_code="500"'
> ```
>
> 가장 유용한 로그 플래그는 다음과 같습니다.
>
> * `--service`는 `service.name`을 설정하여 이벤트가 어느 서비스에서 발생했는지 식별할 수 있도록 합니다.
> * `--severity-text`와 `--severity-number`는 심각도 수준을 설정합니다(`severity-number`의 범위는 1\~24입니다).
> * `--body`는 로그 메시지를 설정합니다.
> * `--otlp-attributes`는 리소스 수준 속성을 설정합니다(`key="value"`, `key=true` 또는 `key=<integer>`).
> * `--telemetry-attributes`는 레코드별 속성을 설정합니다.
>
> **5. trace 생성**
>
> 여러 서비스에서 성공 및 오류 상태가 포함된 다중 스팬 트레이스를 전송하십시오. 각 명령은 서로 독립된 트레이스를 생성하며, 이 예시에서는 서비스 간 호출이 발생하지 않습니다.
>
> ```shell theme={null}
> # Healthy services: the bulk of the traffic, all spans Ok
> for svc in frontend checkout cart; do
>   tg traces --service "$svc" --child-spans 3 --span-duration 80ms --status-code Ok \
>     --otlp-attributes 'deployment.environment="production"' \
>     --telemetry-attributes "http.route=\"/$svc\""
> done
>
> # A service with slower spans and errors
> tg traces --service payment --child-spans 3 --span-duration 450ms --span-links 1 --status-code Error \
>   --otlp-attributes 'deployment.environment="production"' \
>   --telemetry-attributes 'http.route="/charge"'
> ```
>
> 가장 유용한 트레이스 플래그는 다음과 같습니다.
>
> * `--child-spans`는 트레이스마다 지정한 수만큼 자식 스팬을 생성하여 각 트레이스에 실제와 같은 깊이를 부여합니다.
> * `--span-duration`은 각 스팬의 지속 시간을 설정합니다(예: `120ms`, `2s`).
> * `--status-code`는 `Unset`, `Error`, `Ok`(또는 `0`, `1`, `2`) 중 하나를 지정합니다. 오류 관련 화면을 테스트하려면 `Error`를 사용하세요.
> * `--span-links`는 스팬 간에 링크를 추가합니다.
> * `--workers`는 여러 generator를 병렬로 실행하여 더 많고 다양한 데이터를 생성합니다.
>
> **6. 메트릭 생성**
>
> 합계(sum), 게이지, 히스토그램 메트릭을 전송합니다. 이 값들은 임의로 생성한 합성 값으로, 실제 시스템을 측정한 값이 아닙니다. 각 명령은 30초 후 자동으로 중지됩니다:
>
> ```shell theme={null}
> tg metrics --service frontend --metric-type Sum       --otlp-metric-name http.server.requests --aggregation-temporality cumulative
> tg metrics --service frontend --metric-type Gauge     --otlp-metric-name system.memory.usage
> tg metrics --service payment  --metric-type Histogram --otlp-metric-name http.server.duration
> ```
>
> `--metric-type`에는 `Gauge`, `Sum`, `Histogram`, `ExponentialHistogram` 중 하나를 지정할 수 있습니다. `--otlp-metric-name`은 UI에서 찾을 수 있도록 시계열의 이름을 지정하며, `--aggregation-temporality`에는 `delta` 또는 `cumulative`를 지정합니다.
>
> **7. ClickHouse Observability에서 확인**
>
> ClickHouse Observability 서비스를 엽니다. `Search` 뷰에서 시간 범위를 `Last 15 minutes`로 설정하고, 소스를 `Logs`와 `Traces` 사이에서 전환합니다. `ServiceName`으로 필터링하면 `frontend`, `checkout`, `cart`, `payment` 서비스를 확인할 수 있고, `SeverityText`로 필터링하면 경고 및 오류 로그 행을 찾을 수 있습니다. `payment` 트레이스를 열어 자식 스팬과 오류 상태를 확인합니다. 메트릭 수집을 확인하려면 `Chart Explorer`를 열고 `Metrics`를 선택한 다음, 위에서 설정한 메트릭 이름 중 하나(예: `http.server.requests`)로 차트를 생성합니다.

> [tab] 자가 관리형
>
> [`telemetrygen`](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/cmd/telemetrygen) 는 OpenTelemetry Collector Contrib의 데이터 생성기입니다. 합성 OTLP 로그, trace, 메트릭을 생성하며, 플래그를 통해 여러 서비스, 로그 심각도, 스팬 상태와 자식 스팬, 다양한 메트릭 타입 등 데이터의 형태를 조정할 수 있습니다. ClickStack OpenTelemetry 수집기가 데이터를 정상적으로 수신하는지, 그리고 실제와 유사한 다양한 이벤트가 관측성 UI에 표시되는지 확인하는 용도로 사용하십시오.
>
> 이 가이드에서는 collector가 이미 실행 중이며 `4317`(gRPC) 및 `4318`(HTTP) 포트에서 OTLP 엔드포인트를 제공하고 있다고 가정합니다.
>
> **1. 사전 요구 사항**
>
> 이 가이드는 [ClickHouse Observability — Self-managed 시작 가이드](https://clickhouse.com/docs/ko/clickstack/self-configured/getting-started/managed.md)를 이미 완료했고, `telemetrygen`을 실행할 머신에서 OTLP gRPC(`4317`) 및 HTTP(`4318`) 엔드포인트에 연결할 수 있는 OpenTelemetry collector가 실행 중이라고 가정합니다. `OTLP_AUTH_TOKEN`으로 [collector를 보호했다면](https://clickhouse.com/docs/ko/clickstack/self-configured/ingesting-data/collector.md#securing-the-collector-self-configured) 해당 값을 미리 준비해 두십시오.
>
> **2. telemetrygen 설치**
>
> 별도 설치 없이 Docker 이미지로 `telemetrygen`을 실행합니다. 아래 명령어를 간결하게 유지하기 위해 간단한 래퍼를 정의합니다. `--add-host` 옵션을 사용하면 컨테이너에서 호스트에서 수신 대기 중인 collector에 접근할 수 있습니다:
>
> ```shell theme={null}
> telemetrygen() {
>   docker run --rm --add-host=host.docker.internal:host-gateway \
>     ghcr.io/open-telemetry/opentelemetry-collector-contrib/telemetrygen:latest "$@"
> }
> export OTEL_ENDPOINT=host.docker.internal:4317
> ```
>
> 또는 Go로 바이너리를 설치한 다음 `localhost`를 대상으로 지정하십시오:
>
> ```shell theme={null}
> go install github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen@latest
> export OTEL_ENDPOINT=localhost:4317
> ```
>
> **3. 환경 변수 설정**
>
> collector에 보안이 설정되어 있다면 인증 토큰을 내보내십시오:
>
> ```shell theme={null}
> export OTLP_AUTH_TOKEN=<your_otlp_auth_token>
> ```
>
> > [!NOTE]
> >
> > **보안이 적용되지 않은 collector**
> >
> > ClickStack OpenTelemetry 수집기는 기본적으로 인증을 요구하지 않습니다. [collector 보안 설정](https://clickhouse.com/docs/ko/clickstack/self-configured/ingesting-data/collector.md#securing-the-collector-self-configured)에 따라 `OTLP_AUTH_TOKEN`을 설정하지 않았다면 아래 보조 함수에서 `--otlp-header` 줄을 삭제하세요.
>
> 각 명령에서 달라지는 값(서비스, 심각도, 상태, 속성)만 지정할 수 있도록 간단한 `tg` 보조 함수를 정의하세요:
>
> ```shell theme={null}
> tg() { local signal=$1; shift; telemetrygen "$signal" \
>   --otlp-endpoint ${OTEL_ENDPOINT} --otlp-insecure \
>   --otlp-header "authorization=\"${OTLP_AUTH_TOKEN}\"" \
>   --rate 5 --duration 30s "$@"; }
> ```
>
> **4. 로그 생성**
>
> 로그를 하나의 단조로운 스트림으로 보내는 대신, 여러 서비스에 걸쳐 심각도가 실제 환경처럼 섞이도록 보내십시오. 대부분은 정보성 로그로 구성하고 경고와 오류를 하나씩 포함하십시오:
>
> ```shell theme={null}
> tg logs --service frontend --severity-text Info  --severity-number 9  --body "GET /api/products 200" \
>   --otlp-attributes 'deployment.environment="production"' \
>   --telemetry-attributes 'http.method="GET"' --telemetry-attributes 'http.status_code="200"'
> tg logs --service checkout --severity-text Warn  --severity-number 13 --body "retrying payment authorization" \
>   --otlp-attributes 'deployment.environment="production"' \
>   --telemetry-attributes 'http.method="POST"'
> tg logs --service payment  --severity-text Error --severity-number 17 --body "payment gateway timeout" \
>   --otlp-attributes 'deployment.environment="production"' \
>   --telemetry-attributes 'http.status_code="500"'
> ```
>
> 가장 유용한 로그 플래그는 다음과 같습니다.
>
> * `--service`는 `service.name`을 설정하여 이벤트가 어느 서비스에서 발생했는지 식별할 수 있게 합니다.
> * `--severity-text`와 `--severity-number`는 심각도 수준을 설정합니다(`severity-number`의 범위는 1\~24입니다).
> * `--body`는 로그 메시지를 설정합니다.
> * `--otlp-attributes`는 리소스 수준 속성(`key="value"`, `key=true` 또는 `key=<integer>`)을 설정합니다.
> * `--telemetry-attributes`는 레코드별 속성을 설정합니다.
>
> **5. trace 생성**
>
> 여러 정상 서비스와 장애가 발생한 의존성 1개에서 다중 스팬 트레이스를 전송하십시오. 이렇게 하면 서비스 맵이 대부분 정상이고 한 서비스에서만 오류가 발생하는 현실적인 형태를 띠게 되며, 오류 관련 뷰에도 데이터가 채워집니다.
>
> ```shell theme={null}
> # Healthy services: the bulk of the traffic, all spans Ok
> for svc in frontend checkout cart; do
>   tg traces --service "$svc" --child-spans 3 --span-duration 80ms --status-code Ok \
>     --otlp-attributes 'deployment.environment="production"' \
>     --telemetry-attributes "http.route=\"/$svc\""
> done
>
> # One slow dependency returning errors
> tg traces --service payment --child-spans 3 --span-duration 450ms --span-links 1 --status-code Error \
>   --otlp-attributes 'deployment.environment="production"' \
>   --telemetry-attributes 'http.route="/charge"'
> ```
>
> 가장 유용한 트레이스 플래그는 다음과 같습니다.
>
> * `--child-spans`는 트레이스마다 지정한 개수만큼 자식 스팬을 생성하여 각 트레이스에 실제와 같은 깊이를 부여합니다.
> * `--span-duration`은 각 스팬의 지속 시간을 설정합니다(예: `120ms`, `2s`).
> * `--status-code`는 `Unset`, `Error`, `Ok`(또는 `0`, `1`, `2`) 중 하나로 지정합니다. 오류 관련 화면을 테스트하려면 `Error`를 사용하세요.
> * `--span-links`는 스팬 간 링크를 추가합니다.
> * `--workers`는 여러 generator를 병렬로 실행하여 더 많고 다양한 데이터를 생성합니다.
>
> **6. 메트릭 생성**
>
> 대시보드에 카운터, 게이지, 분포(distribution)가 모두 표시되도록 일반적인 세 가지 메트릭 유형을 전송하십시오. 일부 생성기와 달리 `telemetrygen`은 메트릭 전송 시 `--duration` 설정을 따르므로 수동으로 중지할 필요가 없습니다.
>
> ```shell theme={null}
> tg metrics --service frontend --metric-type Sum       --otlp-metric-name http.server.requests --aggregation-temporality cumulative
> tg metrics --service frontend --metric-type Gauge     --otlp-metric-name system.memory.usage
> tg metrics --service payment  --metric-type Histogram --otlp-metric-name http.server.duration
> ```
>
> `--metric-type`에는 `Gauge`, `Sum`, `Histogram`, `ExponentialHistogram` 중 하나를 지정할 수 있습니다. `--otlp-metric-name`은 UI에서 시계열을 찾을 수 있도록 시계열의 이름을 지정하며, `--aggregation-temporality`에는 `delta` 또는 `cumulative`를 지정합니다.
>
> **7. 관측성 UI에서 확인하십시오**
>
> ClickHouse Cloud 콘솔에서 관측성 UI를 엽니다. `Search` 뷰에서 시간 범위를 `Last 15 minutes`로 설정하고, 소스를 `Logs`와 `Traces`로 번갈아 전환합니다. `ServiceName`으로 필터링하면 `frontend`, `checkout`, `cart`, `payment` 서비스를 확인할 수 있으며, `SeverityText`로 필터링하면 경고 및 오류 로그 행을 찾을 수 있습니다. `payment` 트레이스를 열어 자식 스팬과 오류 상태를 확인합니다. `Chart Explorer`를 열고 `Metrics`를 선택한 다음, 앞에서 설정한 메트릭 이름 중 하나(예: `http.server.requests`)로 차트를 그려 메트릭이 정상적으로 수집되는지 확인합니다.
