本文档采用自动化机器翻译技术翻译。 尽管我们力求提供准确的译文,但不对翻译内容的完整性、准确性或可靠性作出任何保证。 若出现任何内容不一致情况,请以原始 英文 版本为准,且原始英文版本为权威文本。

开始使用 Open Telemetry

这是我们将要创建的设置,用于需要监控的应用程序:

  • 在 Linux 主机上运行的被监控应用程序/工作负载

  • 在同一 Linux 主机上运行的 Open Telemetry 收集器

  • SUSE Observability 或 SUSE Cloud Observability

在运行 Open Telemetry 收集器的 Linux 主机上对应用程序进行插桩

安装 Open Telemetry 收集器

对于生产环境,强烈建议安装收集器,因为它可以快速卸载数据,并且收集器可以处理额外的操作,如重试、批处理、加密或甚至敏感数据过滤。

首先我们将安装收集器。我们将其配置为:

  • 接收来自多个经过插桩的应用程序的数据

  • 用主机属性丰富收集的数据

  • 为跟踪生成指标

  • 将数据转发到 SUSE Observability,包括使用 API 密钥进行身份验证

此外,当出现连接问题时,它还会重试发送数据。

创建服务令牌

有两种方法可以创建服务令牌:

  • SUSE Observability UI - 点击屏幕左上角打开主菜单,然后转到 StackPacks > Open Telemetry。 如果您之前没有这样做,请点击 INSTALL 按钮。 点击 CREATE NEW SERVICE TOKEN 按钮并将值复制到剪贴板。

  • SUSE Observability CLI - 请参见 管理服务令牌

服务令牌值必须在下面的说明中提到 <SERVICE_TOKEN> 的地方使用。

安装并配置收集器

收集器为大多数 Linux 版本和架构提供软件包(apk、deb 和 rpm),并使用 systemd 进行自动服务配置。要安装它,请找到 Github 上的最新版本 并更新示例中的 URL 以使用最新版本:

  • DEB AMD64

  • DEB ARM64

  • RPM AMD64

  • RPM ARM64

wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.123.1/otelcol-contrib_0.123.1_linux_amd64.deb
sudo dpkg -i otelcol-contrib_0.123.1_linux_amd64.deb
wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.123.1/otelcol-contrib_0.123.1_linux_arm64.deb
sudo dpkg -i otelcol-contrib_0.123.1_linux_arm64.deb
wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.123.1/otelcol-contrib_0.123.1_linux_amd64.rpm
sudo rpm -iv1 otelcol-contrib_0.123.1_linux_amd64.rpm
wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.123.1/otelcol-contrib_0.123.1_linux_arm64.rpm
sudo rpm -iv1 otelcol-contrib_0.123.1_linux_arm64.rpm

有关其他安装选项,请使用 Open Telemetry 指南

安装后,通过编辑 /etc/otelcol-contrib/config.yaml 修改收集器配置。更改文件,使其看起来像这里的 config.yaml 示例,将 <otlp-suse-observability-endpoint:port> 替换为您的 OTLP 端点(请参阅 OTLP API 以获取您的端点),并为 <SERVICE_TOKEN> 插入您的服务词元:

config.yaml
receivers:
  otlp:
    protocols:
      # Only bind to localhost to keep the collector secure, see https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/security-best-practices.md#safeguards-against-denial-of-service-attacks
      grpc:
        endpoint: 127.0.0.1:4317
      http:
        endpoint: 127.0.0.1:4318
  # Collect own metrics
  prometheus:
    config:
      scrape_configs:
      - job_name: 'otel-collector'
        scrape_interval: 10s
        static_configs:
        - targets: ['0.0.0.0:8888']
extensions:
  health_check: {}
  pprof:
    endpoint: 0.0.0.0:1777
  zpages:
    endpoint: 0.0.0.0:55679
  # Use the API key from the env for authentication
  bearertokenauth:
    scheme: SUSEObservability
    token: "<SERVICE_TOKEN>"
exporters:
  nop: {}
  debug: {}
  otlp/suse-observability:
    compression: snappy
    auth:
      authenticator: bearertokenauth
    # Put in your own otlp endpoint, for example otlp-suse-observability.my.company.com:443
    endpoint: <otlp-suse-observability-endpoint:port>
processors:
  memory_limiter:
    check_interval: 5s
    limit_percentage: 80
    spike_limit_percentage: 25
  batch: {}
  # Optionally include resource information from the system running the collector
  resourcedetection/system:
    detectors: [env, system] # Replace system with gcp, ec2, azure when running in cloud environments
    system:
      hostname_sources: ["os"]
connectors:
  # Generate metrics for spans
  spanmetrics:
    metrics_expiration: 5m
    namespace: otel_span
service:
  extensions: [ bearertokenauth, health_check, pprof, zpages ]
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, resourcedetection/system, batch]
      exporters: [debug, spanmetrics, otlp/suse-observability]
    metrics:
      receivers: [otlp, spanmetrics, prometheus]
      processors: [memory_limiter, batch, resourcedetection/system]
      exporters: [debug, otlp/suse-observability]
    logs:
      receivers: [otlp]
      processors: []
      exporters: [nop]

最后重启收集器:

sudo systemctl restart otelcol-contrib

要查看收集器的日志,请使用:

sudo journalctl -u otelcol-contrib

从您的应用程序收集遥测数据

收集遥测数据的常见方法是使用 Open Telemetry SDK 对您的应用程序进行插桩。我们为几种语言编写了一些快速入门指南,但还有更多:

SDK 不需要额外配置,它们默认通过 OTLP 或 OTLP over HTTP(取决于支持的协议)导出到 localhost。

对于其他语言,请遵循 opentelemetry.io 上的文档。

查看结果

前往 SUSE Observability,确保已安装 Open Telemetry Stackpack(通过主菜单 -> Stackpacks)。

过一段时间,如果您的应用程序正在处理一些流量,您应该能够在 Open Telemetry -> 服务和服务实例概览中找到它。跟踪将在 跟踪探索器跟踪视角 中显示,适用于服务和服务实例组件。跨度指标和特定语言的指标(如果可用)将在 指标视角 中为组件提供。

后续步骤

您可以通过遵循 我们的指南 为您的应用程序的组件(例如服务或服务实例)添加新的图表。还可以使用指标创建 新的监控器,并设置 通知,以便在您的应用程序不可用或出现性能问题时收到通知。