下载最新的 opentelemetry-javaagent.jar from Releases
运行jar
java -javaagent:path/to/opentelemetry-javaagent.jar -jar myapp.jar
配置 jaeger
服务
- # 方式一:
- java -javaagent:path/to/opentelemetry-javaagent.jar \
- -Dotel.service.name=your-service-name \
- -Dotel.traces.exporter=jaeger \
- -Dotel.exporter.jaeger.endpoint=http://localhost:14250 \
- -jar myapp.jar
-
- # 方式二(容器添加环境变量):
- OTEL_TRACES_EXPORTER=jaeger
- OTEL_EXPORTER_JAEGER_ENDPOINT=http://localhost:14250
- OTEL_SERVICE_NAME=your-service-name
参考Dockerfile
- FROM dggecr01.huawei.com:80/scan-engine/ringcentral/jdk:latest
- WORKDIR /app
- EXPOSE 8090
- COPY ./target/myapp.jar .
- COPY ./lib/opentelemetry-javaagent.jar .
- CMD java -javaagent:opentelemetry-javaagent.jar -jar myapp.jar
java实战
部署jaeger,一体1.38版本 弃用这种方式安装,原因时间长了内存爆炸
docker run -d --name jaeger -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 -e COLLECTOR_OTLP_ENABLED=true -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 4317:4317 -p 4318:4318 -p 14250:14250 -p 14268:14268 -p 14269:14269 -p 9411:9411 jaegertracing/all-in-one:1.38
分开的安装
- docker run -d --name=jaeger-collector -p 9411:9411 -p 14250:14250 -p 14268:14268 -p 14269:14269 -e SPAN_STORAGE_TYPE=elasticsearch -e ES_SERVER_URLS=http://1.2.1.5:9200 -e ES_INDEX_PREFIX=test jaegertracing/jaeger-collector:1.38
-
- docker run -d --name=jaeger-agent -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778/tcp -p 5775:5775/udp -e REPORTER_GRPC_HOST_PORT=1.2.1.5:14250 jaegertracing/jaeger-agent:1.38
-
- docker run -d --name=jaeger-query -p 16686:16686 -p 16687:16687 -e SPAN_STORAGE_TYPE=elasticsearch -e ES_SERVER_URLS=http://1.2.1.5:9200 -e ES_INDEX_PREFIX=test jaegertracing/jaeger-query:1.38
-
- Jaeger Spark依赖项 这是一个Spark作业,它从存储中收集跨度,分析服务之间的链接,并将其存储以供以后在UI中呈现
- docker pull jaegertracing/spark-dependencies:latest
- 下面这个是执行一次的,会自动退出,每次更新需要执行一次
- docker run -d --name=jaeger-spark -e STORAGE=elasticsearch -e ES_NODES=http://1.2.1.5:9200 -e ES_INDEX_PREFIX=test jaegertracing/spark-dependencies:latest
访问ui
因为下载的是上面的opentelemetry-javaagent.jar,目前没有用到1.38版的agent,可以单独下载
Dockerfile
- FROM anapsix/alpine-java:8_server-jre_unlimited
-
- MAINTAINER jeecgos@163.com
-
- RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
-
- RUN mkdir -p /javaapp
-
- WORKDIR /javaapp
-
- EXPOSE 8079
-
- ADD ./javaapp-1.0-SNAPSHOT.jar ./
- ADD ./opentelemetry-javaagent.jar ./
-
- CMD sleep 2;java -Dfile.encoding=utf-8 -Djava.security.egd=file:/dev/./urandom -javaagent:opentelemetry-javaagent.jar -jar javaapp-1.0-SNAPSHOT.jar
构建镜像docker build -t javaapp:latest .
运行docker-compose.yml
- version: '2'
- services:
- javaapp:
- container_name: javaapp
- image: javaapp:latest
- hostname: javaapp
- ports:
- - 8079:8079
- restart: on-failure
- environment:
- - TZ=Asia/Shanghai
- - OTEL_TRACES_EXPORTER=jaeger
- - OTEL_EXPORTER_JAEGER_ENDPOINT=http://192.168.1.182:14250
- - OTEL_SERVICE_NAME=javaapp
- - OTEL_METRICS_EXPORTER=none
- 原因
- OpenTelemetry 默认配置 otel.metrics.exporter=otlp (default), 因此 javaagent 默认会往 http://localhost:4317 推送 metrics 指标。
-
- 解决
- 设置 otel.metrics.exporter=none 或 环境变量OTEL_METRICS_EXPORTER=none
-