我正在尝试让 Open Telemetry 从在 GKE 上运行的 Spring Boot 3.3.5 应用程序导出跟踪记录。
我尝试按照指南这里说要使用:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-bom</artifactId>
<version>2.6.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
但是,我已经升级到版本2.8.0(2.10.0由于不兼容而无法使用)。
我还添加了这个:
<dependencies>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-spring-boot-starter</artifactId>
</dependency>
</dependencies>
我在 Spring Boot 中有以下
application.yaml
:
otel:
trace:
sampler: traceidratio
traceidratio: 0.1
propagators:
- tracecontext
resource:
attributes:
deployment.environment: test
service:
name: my-service
namespace: my-company
traces:
exporter: google_cloud_trace
由于我想导出到 Google Cloud Trace,我还尝试遵循 Google Open Telemetry 文档here,同时还依赖于:
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>exporter-auto</artifactId>
<version>0.33.0-alpha</version>
<classifier>shaded</classifier>
</dependency>
但是当将我的应用程序部署到 GKE 时,我在日志中收到此错误:
[my-service-55fc6bd6c-bfs5t] 2024-11-19T09:34:19.522Z ERROR 1 --- [my-service] [alhost:4318/...] i.o.exporter.internal.http.HttpExporter : Failed to export logs. The request could not be executed. Full error message: Failed to connect to localhost/127.0.0.1:4318
[my-service-55fc6bd6c-bfs5t]
[my-service-55fc6bd6c-bfs5t] java.net.ConnectException: Failed to connect to localhost/127.0.0.1:4318
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:297)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:207)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
[my-service-55fc6bd6c-bfs5t] at io.opentelemetry.exporter.sender.okhttp.internal.RetryInterceptor.intercept(RetryInterceptor.java:91)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
[my-service-55fc6bd6c-bfs5t] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[my-service-55fc6bd6c-bfs5t] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[my-service-55fc6bd6c-bfs5t] at java.base/java.lang.Thread.run(Unknown Source)
[my-service-55fc6bd6c-bfs5t] Caused by: java.net.ConnectException: Connection refused
[my-service-55fc6bd6c-bfs5t] at java.base/sun.nio.ch.Net.pollConnect(Native Method)
[my-service-55fc6bd6c-bfs5t] at java.base/sun.nio.ch.Net.pollConnectNow(Unknown Source)
[my-service-55fc6bd6c-bfs5t] at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(Unknown Source)
[my-service-55fc6bd6c-bfs5t] at java.base/sun.nio.ch.NioSocketImpl.connect(Unknown Source)
[my-service-55fc6bd6c-bfs5t] at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
[my-service-55fc6bd6c-bfs5t] at java.base/java.net.Socket.connect(Unknown Source)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.platform.Platform.connectSocket(Platform.kt:128)
[my-service-55fc6bd6c-bfs5t] at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:295)
[my-service-55fc6bd6c-bfs5t] ... 20 common frames omitted
即在我看来,otel 试图将跟踪发送到
127.0.0.1:4318
而不是 Google Cloud Trace。我还尝试在没有 exporter-auto
库的情况下部署应用程序,而是使用 com.google.cloud.opentelemetry:exporter-trace
(请参阅文档 here),但我也没有让它工作(它抱怨 google_cloud_trace
导出器是找不到,切换到 exporter-auto
即可解决。
如何配置 Spring Boot 3.3+ 和 OTel 以将跟踪导出到 Google Cloud Trace?
如果您在 GKE 集群中使用 Spring Boot 应用程序,您可以尝试以下操作: https://googlecloudplatform.github.io/spring-cloud-gcp/reference/html/index.html#cloud-trace 还 如果您想与酒店出口商合作:
尝试将其部署在 GKE 集群中:https://cloud.google.com/stackdriver/docs/instrumentation/opentelemetry-collector-gke
然后配置您的 java 应用程序以将跟踪发送到 opentelemetry 端点: OTEL_EXPORTER_OTLP_ENDPOINT="http://opentelemetry-collector.opentelemetry.svc.cluster.local:4317"(默认情况下)
对于 Java 应用程序,您可以配置 Java 代理来创建跟踪并将其发送到云跟踪
https://opentelemetry.io/docs/languages/java/getting-started/
理想情况下,你的环境应该看起来像这样:
JAVA_TOOL_OPTIONS="-javaagent:/opentelemetry-javaagent.jar" OTEL_TRACES_EXPORTER=otlp