Closed lrwh closed 9 months ago
本地测试,使用链路运行正常且能正常串联。但也缺少了部分 span 信息。
java -javaagent:/home/liurui/agent/opentelemetry-javaagent-1.26.1-guance.jar -Dotel.traces.exporter=otlp -Dotel.exporter.otlp.endpoint=http://localhost:4317 -Dotel.resource.attributes=service.name=springboot-server -Djava.ext.dirs="./lib:$JAVA_HOME/jre/lib/ext" -jar springboot-server.jar
使用 -Dloader.path
替换 -Djava.ext.dirs
ddtrace 的链路能够串联,效果基本上和 OTEL 一样,但也缺少了部分 span 信息。
java -javaagent:/home/liurui/agent/dd-java-agent-1.12.1-guance.jar -Ddd.service.name=springboot-server -Ddd.env=1.0 -Ddd.agent.port=9529 -Dloader.path="lib/" -jar springboot-server.jar
初步推断,是因为 agent 优先加载了,所以 agent 只对 jdk 原有的代码做了增强,而对于框架层,基本上看不见。
-Djava.ext.dirs
参数是 ExtClassLoader
来加载的,而一般 java 程序是以 AppClassLoader
来加载代码。所以导致 agent 无法加载到 -Djava.ext.dirs
相关的依赖。
按照以下方式进行处理,问题已解决
java -jar -Dloader.path="lib/" springboot-server.jar
用 -Dloader.path
替换 -Djava.ext.dirs
java -Xbootclasspath/a:$JAVA_HOME/lib/tools.jar -jar agent-attach-java-jar-with-dependencies.jar -options "dd.agent.port=9529,dd.trace.debug=true" -displayName springboot-server.jar -agent-jar /usr/local/datakit/data/dd-java-agent.jar
agent-attach-java 仓库 : https://github.com/GuanceCloud/agent-attach-java
部分客户仍然调整后无法导致应用无法启动
原始命令:
nohup java -server ${SYS_ARGS} ${APP_ARGS} ${JAVA_AGENT_OPTS} $JAVA_MEM_OPTS $JAVA_JMX_OPTS $JAVA_RMI_SERVER_HOST -Dconfig.entry=${Dconfig} -Xbootclasspath/a:$CONF_DIR -jar -Djava.ext.dirs="${DEPLOY_DIR}/lib/:$JAVA_HOME/jre/lib/ext" ${DEPLOY_DIR}/lib/$JAR_NAME > $NOHUP_LOG_FILES 2>&1 &
调整后的命令
nohup java -server ${SYS_ARGS} ${APP_ARGS} ${JAVA_AGENT_OPTS} $JAVA_MEM_OPTS $JAVA_JMX_OPTS $JAVA_RMI_SERVER_HOST -Dconfig.entry=${Dconfig} -Xbootclasspath/a:$CONF_DIR -jar -Dloader.path=“${DEPLOY_DIR}/lib/” -Djava.ext.dirs="$JAVA_HOME/jre/lib/ext" ${DEPLOY_DIR}/lib/$JAR_NAME > $NOHUP_LOG_FILES 2>&1 &
暂时无解,先close
背景
Springboot 从 jar 包中分离出 lib 包,实现 lib 包与项目代码分离部署
运行指令
demo 地址 https://github.com/lrwh/observable-demo/tree/main/springboot-server
需要调整pom