配置 opentelemetry 以使用 Spring boot 3 创建跨度

问题描述 投票:0回答:1

我正在尝试使用

spans
newRelic
应用程序
 为我的 
micrometer
 创建 
spring boot 3

我的代码看起来像这样 -

import io.micrometer.tracing.annotation.NewSpan; 
import io.micrometer.tracing.Tracer;

@Autowired
private Tracer tracer;

@NewSpan("span") public Person apply(Message<Person> person){ 
var span= tracer.spanBuilder().name("event").start(); 
span.end();    
}

我的依赖树看起来像这样 -

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>2022.0.4</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-dependencies</artifactId>
            <version>3.2.9</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-tracing-bom</artifactId>
            <version>1.1.1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>

    <!--        TRACE       -->

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-tracing-bridge-otel</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-new-relic -->
    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-new-relic</artifactId>
    </dependency>
 </dependencies>

我有这样的应用程序属性 -

 management:
  tracing:
   sampling:
    probability: 1.0
  newrelic:
   metrics:
    export:
     enabled: true
     api-key: sss
     account-id: sss
  endpoints:
   web:
    exposure:
    include: "*"

我在任何地方都没有日志,代码执行正常,但我在 newRelic 中看不到任何跨度。

有人可以指出这个设置的缺点吗?

我可以在日志中看到traceId和spanId

2023-12-04T10:40:20.529Z 信息 [事件中继,事件中继-8657d79975-xqdg8,bad941449fc11d712c78db4bc0cad8d5,03f15d59cea9ff0c] 1 --- [调度-1] c.eventrelay.Producer : 发送事件 针对 ff201146-94b1-435f-a846-57ac76449f11

其中

bad941449fc11d712c78db4bc0cad8d5
是我的
traceId
03f15d59cea9ff0c
是我的
spanId

spring-boot newrelic open-telemetry
1个回答
0
投票

我使用

opentelemetry
导出我的跨度。

io.opentelemetry:opentelemetry-exporter-otlp
如描述这里解决了我的问题。

我也在使用这个属性来导出:

management:   
    otlp:
      tracing:
          endpoint: https://localhost:4318/v1/traces
          headers:
             api-key: shdgjsgdjdjgajdjasgd
             account-id: abc
© www.soinside.com 2019 - 2024. All rights reserved.