TH小破站

  • 首页
  • 容器
    • 认识Docker
    • DockerFile详解
  • k8s
    • 认识Kubernetes
    • Kubernetes部署--(kubeadm方式)
    • kubeasz部署k8s集群
    • Ansible-binary部署k8s集群-1.31.2
  • Ceph
    • 认识分布式存储
    • CPEH部署
  • CI/CD
    • DevOps认识
    • 部署--Gitlab
  • ELK
    • ELK简介
    • Elasticsearch
    • Kibana部署
    • Logstash
    • ELK--收集 tomcat 日志(实战)
  • HD
    • 认识--大数据
    • Hadoop-单机部署
    • Hadoop-伪分布部署
    • Hadoop-完全分布部署
    • Hadoop-(HA)完全分布部署
    • Ambari自动部署--Hadoop
  • Nginx
    • Nginx功能介绍
    • Nginx安全选项
    • Nginx配置文件简单介绍
    • 网站服务器部署
  • 监控
    • ZABBIX-部署(yum)
    • ZABBIX-编译安装
  • 云计算
    • KVM 概述
    • OpenStack企业级部署(T版)
    • OpenStack之dashboard部署
    • OpenStack-controller的高可用
    • openstack(Caracal版_ubuntu版本)部署
  • 数据库
    • mariadb与mysql
    • mysql主从
    • MySQL--冷备(实战)
    • MySQL--热备(dump表)
    • MySQL--热备(dump库)
    • 数据恢复实战案例
    • Xtrabackup实现MySql8.x全量备份
    • MyCat实现数据库读写分离
    • MHA实现数据库高可用
    • Percona XtraDB(PXC)实现数据库集群高可用
    • 数据库压力测试
    • PostgreSQL 基操
    • PostgreSQL备份恢复
    • PostgreSQL高可用
    • MongDB安装配置基础使用
    • MongoDB实现复制集
    • MongoDB备份还原
  • 自动化
    • ssh远程服务原理及配置
    • Ansible剧本文件应用
    • Ansible管理服务介绍
    • Ansible自动化部署node_exporter(包含升级,回滚)
    • Saltstack-部署安装
  • 脚本
    • 一键查看服务器资源利用率
    • 一键生成SSL证书
    • 保存指定数量的文件/目录
    • 初始化服务器
    • 扫描可用IP
    • 批量分发SSH密钥
    • 监控多主机磁盘脚本
    • 一键安装MySQL8.x脚本
    • Python脚本监控ES集群
    • 资源巡检脚本
    • 查看各用户使用的cpu占比
热衷于分享
架构师成长之路 !!!
  1. 首页
  2. 链路追踪
  3. 正文

opentelemetry(链路追踪)零代码集成

2025年8月10日 918点热度 0人点赞 0条评论

部署cert-manager

# kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.17.4/cert-manager.yaml
# kubectl get pod -n cert-manager 
NAME                                       READY   STATUS    RESTARTS   AGE
cert-manager-6d54964b8f-wrtmw              1/1     Running   0          80s
cert-manager-cainjector-5b7d5cb8cb-wxhcb   1/1     Running   0          80s
cert-manager-webhook-c46c6d97c-zt6jg       1/1     Running   0          80s

部署 opentelemetry-operator.yaml

# kubectl apply -f  https://github.com/open-telemetry/opentelemetry-operator/releases/latest/download/opentelemetry-operator.yaml
# kubectl get po -n opentelemetry-operator-system 
NAME                                                        READY   STATUS    RESTARTS   AGE
opentelemetry-operator-controller-manager-c664f5df9-2d9l4   2/2     Running   0          37s

部署 opentelemetry collector

必须和追踪的 服务pod 部署在同一个名称空间

otel收集器: 支持grpc (端口 4317) 和 http (端口 4318)

# cat opentelemetry-collector.yaml 
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: otel
  namespace: opentelemetry-operator-system
spec:
  config:
    receivers:
      otlp:
        protocols:
          grpc: {}
          http: {}
    
    processors:
      memory_limiter:
        check_interval: 1s
        limit_percentage: 75
        spike_limit_percentage: 15
      batch:
        send_batch_size: 10000
        timeout: 10s

    exporters:
      debug: {}
      otlp:
        endpoint: "http://tempo.monitoring:4317"  # 部署的 tempo 地址
        tls:
          insecure: true

    service:
      pipelines:
        traces:
          receivers: [otlp]
          processors: [memory_limiter, batch]
          exporters: [debug, otlp]  
        metrics:
          receivers: [otlp]
          processors: [memory_limiter, batch]
          exporters: [debug]  
        logs:
          receivers: [otlp]
          processors: [memory_limiter, batch]
          exporters: [debug] 

# kubectl apply -f opentelemetry-collector.yaml 
# kubectl get po -n opentelemetry-operator-system 
NAME                                                        READY   STATUS    RESTARTS   AGE
opentelemetry-operator-controller-manager-c664f5df9-2d9l4   2/2     Running   0          25m
otel-collector-6bcf9fd89-xq7hm                              1/1     Running   0          53s

安装 Instrumentation

OpenTelemetry Operator 可以注入和配置 OpenTelemetry 自动检测库。目前支持Apache HTTPD、DotNet、Go、Java、NodeJS和Python。

若要使用自动检测,请使用 SDK 和检测的配置来配置检测资源。

# cat opentelemetry-instrumentation.yaml 
apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
  name: my-instrumentation
  namespace: opentelemetry-operator-system
spec:
  exporter:
    endpoint: http://otel-collector.opentelemetry-operator-system:4317
  
  propagators:
    - tracecontext
    - baggage
    - b3
  
  sampler:
    type: parentbased_traceidratio
    argument: "1"
  
  env:
    # Java 自动注入配置
    - name: OTEL_JAVAAGENT_ENABLED
      value: "true"
    - name: OTEL_INSTRUMENTATION_JAVA_ENABLED
      value: "true"
    - name: OTEL_EXPORTER_OTLP_ENDPOINT
      value: http://otel-collector.opentelemetry-operator-system:4317
    - name: OTEL_EXPORTER_OTLP_PROTOCOL
      value: grpc   # 如果需要 http/protobuf,则改成 http/protobuf
    
    # NodeJS 自动注入配置
    - name: OTEL_NODE_RESOURCE_DETECTORS
      value: all
    - name: NODE_OPTIONS
      value: --require @opentelemetry/auto-instrumentations-node/register
    
    # Python 自动注入配置
    - name: OTEL_PYTHON_ENABLED
      value: "true"
    - name: OTEL_PYTHON_DISTRO
      value: opentelemetry-distro
    - name: OTEL_PYTHON_CONFIGURATOR
      value: opentelemetry-distro-configurator
    - name: OTEL_TRACES_EXPORTER
      value: otlp
    - name: OTEL_METRICS_EXPORTER
      value: otlp
    - name: OTEL_LOGS_EXPORTER
      value: otlp
    - name: OTEL_EXPORTER_OTLP_PROTOCOL
      value: grpc   # Python 也可以改成 http/protobuf

# kubectl apply -f opentelemetry-instrumentation.yaml 
# kubectl get instrumentations.opentelemetry.io -n opentelemetry-operator-system 
NAME                 AGE   ENDPOINT                                                   SAMPLER                    SAMPLER ARG
my-instrumentation   81s   http://otel-collector.opentelemetry-operator-system:4317   parentbased_traceidratio   1

opentelemetry使用案例

JAVA跟踪案例

部署JAVA服务

# cat opentelemetry-deployment-java.yaml 
kind: Deployment
apiVersion: apps/v1
metadata:
  name: spring-boot-helloworld
  namespace: opentelemetry-operator-system
  labels:
    app: spring-boot-helloworld
spec:
  replicas: 1
  selector:
    matchLabels:
      app: spring-boot-helloworld
  template:
    metadata:
      name: spring-boot-helloworld
      labels:
        app: spring-boot-helloworld
      annotations:  # 这个注解非常重要
        instrumentation.opentelemetry.io/inject-java: "true"
    spec:
      containers:
      - name: spring-boot-helloworld
        image: registry.cn-zhangjiakou.aliyuncs.com/tanghao-public/spring-boot-helloworld:v0.9.5
        ports:
        - name: http
          containerPort: 80
          protocol: TCP
---
kind: Service
apiVersion: v1
metadata:
  name: spring-boot-helloworld
  namespace: opentelemetry-operator-system
  labels:
    app: spring-boot-helloworld
spec:
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 80
  selector:
    app: spring-boot-helloworld

# kubectl apply -f opentelemetry-deployment-java.yaml 
### 进入集群中带 curl 的 pod 发起请求
# kubectl exec -it demoapp-7b944679dd-q9m75 -- sh
# curl spring-boot-helloworld.opentelemetry-operator-system
Hello Spring Boot 2.0!

grafana tempo里面查询链路追踪情况

 

标签: 暂无
最后更新:2025年8月10日

tanghao946

这个人很懒,什么都没留下

点赞

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复
文章目录
  • 部署cert-manager
  • 部署 opentelemetry-operator.yaml
  • 部署 opentelemetry collector
  • 安装 Instrumentation
  • opentelemetry使用案例
    • JAVA跟踪案例
      • 部署JAVA服务
      • grafana tempo里面查询链路追踪情况

COPYRIGHT © 2025 TH小破站. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

渝ICP备2023013789号

渝公网安备50011702500926号