SpringBoot3+Micrometer无Agent发送Trace到DataDog失败,求正确配置
无Agent方式向DataDog发送Trace的正确配置
核心问题修正
你之前的配置错误在于端点URL版本不匹配和认证Header键错误,DataDog的OTLP HTTP接收规则与其他平台存在差异:
1. 正确的OTLP端点URL
DataDog的OTLP HTTP Span接收端点为:
https://<你的DataDog站点>.datadoghq.com/api/v2/spans
以你使用的us5站点为例,正确URL是:
https://us5.datadoghq.com/api/v2/spans
注:你之前用的
/api/v0.3/traces是DataDog旧版Trace API,并非OTLP兼容端点,无法接收OpenTelemetry导出的Span数据。
2. 正确的认证机制
需要使用DD-API-KEY作为Header键,值为你的DataDog API密钥,而非apiKeySecretArn。
修正后的代码示例
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class TraceConfig { @Bean public SpanExporter spanExporter() { return OtlpHttpSpanExporter.builder() .setEndpoint("https://us5.datadoghq.com/api/v2/spans") .addHeader("DD-API-KEY", "你的DataDog API密钥") .build(); } }
额外必要配置
为让DataDog正确识别服务,建议在配置文件中添加服务名和采样规则:
spring.application.name=你的服务名称 management.tracing.sampling.probability=1.0 # 测试阶段全量采样,生产可按需调整
依赖确认
确保已引入以下核心依赖(适配Spring Boot 3):
<!-- Micrometer Tracing 桥接 OpenTelemetry --> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-tracing-bridge-otel</artifactId> </dependency> <!-- OpenTelemetry OTLP HTTP Exporter --> <dependency> <groupId>io.opentelemetry</groupId> <artifactId>opentelemetry-exporter-otlp-http-trace</artifactId> <version>与Spring Boot版本匹配的对应版本</version> </dependency>
内容的提问来源于stack exchange,提问作者kafkaobservability
相关产品推荐
相关产品推荐

