> ## 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.

# 从 Elastic 迁移 SDK

> 将 Elastic SDK 插桩迁移至全托管的 ClickHouse Observability，自管理部署则需使用单独的连接设置。

Elastic Stack 提供两类语言 SDK，用于对应用程序进行插桩：

1. **[Elastic 官方 APM agent](https://www.elastic.co/docs/reference/apm-agents/)** – 这类 agent 专为 Elastic Stack 构建。如果您使用的是这类 agent，请规划迁移到对应语言的 [OpenTelemetry 插桩](https://opentelemetry.io/docs/languages/)，包括应用程序中用到的所有自定义 span 和属性。

2. **[Elastic Distributions of OpenTelemetry (EDOT SDKs)](https://www.elastic.co/docs/reference/opentelemetry/edot-sdks/)** – 这是 Elastic 基于标准 OpenTelemetry SDK 推出的发行版，支持 .NET、Java、Node.js、PHP 和 Python。如果您的应用程序已在使用 EDOT SDK，则无需重新对代码进行插桩，只需重新配置 SDK，将遥测数据导出到 ClickHouse Observability 的 OTLP 端点即可。详情请参阅[“迁移 EDOT SDK”](#migrating-edot-sdks-self-configured)。

## 迁移 EDOT SDK

Elastic 的 OpenTelemetry SDK 发行版 (EDOT SDKs) 是官方 OpenTelemetry SDK 的定制版本。例如，[EDOT Python SDK](https://www.elastic.co/docs/reference/opentelemetry/edot-sdks/python/) 是 [OpenTelemetry Python SDK](https://opentelemetry.io/docs/languages/python/) 的厂商定制发行版，专为与 Elastic Observability 无缝协作而设计。

由于这些 SDK 基于标准的 OpenTelemetry 库，迁移到 ClickHouse Observability 非常简单，无需重新插桩。只需调整配置，将遥测数据发送到您的 ClickHouse Observability OTLP 端点即可。

配置遵循标准的 OpenTelemetry 机制。对于 Python，通常通过环境变量进行配置，详见 [OpenTelemetry 零代码插桩文档](https://opentelemetry.io/docs/zero-code/python/configuration/)。

典型的 EDOT SDK 配置示例如下：

```shell theme={null}
export OTEL_RESOURCE_ATTRIBUTES='service.name=YOUR_APP_NAME'
export OTEL_EXPORTER_OTLP_ENDPOINT=https://my-deployment.ingest.us-west1.gcp.cloud.es.io
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=ApiKey P....l"
```

迁移时，请更新应用程序环境中的 OTLP 连接设置，然后重启应用程序。以下示例使用 OTLP HTTP 协议及 protobuf 编码。

> [tab] 全托管
>
> [Beta 版产品](https://clickhouse.com/docs/reference/settings/beta-and-experimental-features.md#beta-features)
>
> 从 **团队设置 → 数据 → Managed Telemetry** 中复制 OTLP HTTP 端点和 API key：
>
> ```shell theme={null}
> export OTEL_RESOURCE_ATTRIBUTES='service.name=YOUR_APP_NAME'
> export OTEL_EXPORTER_OTLP_PROTOCOL='http/protobuf'
> export OTEL_EXPORTER_OTLP_ENDPOINT='https://YOUR_OTEL_ENDPOINT:4318'
> export OTEL_EXPORTER_OTLP_HEADERS='authorization=Bearer%20YOUR_API_KEY'
> ```
>
> 请原样使用该端点 (包括端口) ，不要附加 `/v1/traces` 等信号后缀。请求头值中使用 `%20` 对 `Bearer` 后的空格进行编码。有关连接详情，请参阅[发送 OpenTelemetry 数据](https://clickhouse.com/docs/zh/clickstack/observability/ingesting-data/opentelemetry.md)。

> [tab] 自管理
>
> 将 SDK 指向接收端采集器的可访问 OTLP HTTP 端点：
>
> ```shell theme={null}
> export OTEL_RESOURCE_ATTRIBUTES='service.name=YOUR_APP_NAME'
> export OTEL_EXPORTER_OTLP_PROTOCOL='http/protobuf'
> export OTEL_EXPORTER_OTLP_ENDPOINT='http://YOUR_COLLECTOR_HOST:4318'
> export OTEL_EXPORTER_OTLP_HEADERS='authorization=YOUR_COLLECTOR_TOKEN'
> ```
>
> 如果您已使用 `OTLP_AUTH_TOKEN` 为接收端采集器启用了安全保护，请将该令牌作为 authorization 的值。仅当应用程序与采集器位于同一网络命名空间时，才可使用 `localhost`。如果采集器启用了 TLS，请使用其 HTTPS 端点，并将 SDK 配置为信任其证书。请参阅[保护采集器](https://clickhouse.com/docs/zh/clickstack/self-configured/ingesting-data/collector.md#securing-the-collector-self-configured)。
>
> 如果采集器已禁用身份验证，请清除之前的 Elastic 请求头：
>
> ```shell theme={null}
> unset OTEL_EXPORTER_OTLP_HEADERS
> ```

如果您的应用程序设置了针对特定信号的 OTLP 端点、协议或请求头变量，也请一并更新，因为这些变量的优先级高于上述通用设置。设置服务名称时，请保留现有的资源属性。
