如果我正确理解了这个问题的答案,Spring Cloud Sleuth 将被 Spring Boot 3 的 Micrometer Tracing 所取代。到目前为止,我使用 Spring Boot 3 里程碑 3 来实现跟踪的实验失败了。是否有一个示例项目可以用来指导我。
顺便说一句:这是我的实验https://github.com/stse/spring-boot-otel。我尝试使用测微计追踪和开放遥测技术通过 Otlp 和 Grpc 将追踪推送到新遗迹。
随着 OpenTelemetry 试图成为应用程序/服务可观察性的事实上的标准,Micrometer 适合在哪里?Micrometer网站声称它是SLF4J的metrics,但这不是与OpenTelemetry的Metrics API矛盾吗?我想知道 OpenTelemetry 的 Metric API 是否应该代表 SLF4J,而 Micrometer 是否应该代表 Log4J 之类的实现。
如果有人能帮助我澄清这一点,我将不胜感激。
我有一个 Spring boot 应用程序使用千分尺抛出开放指标统计数据。
对于每个 HTTP 端点,我可以看到以下指标,我认为该指标跟踪给定端点的请求数量:
http_server_requests_seconds_count
我的问题是如何在 Grafana 查询中使用它来显示每分钟调用我的端点的请求数?
我试过
http_client_requests_seconds_count{}
和
sum(rate(http_client_requests_seconds_count{}[1m]))
但两者都不起作用。
提前致谢。
我尝试从普罗米修斯获取这些测量值:
increase(http_server_requests_seconds_count{uri="myURI"}[10s])increase(http_server_requests_seconds_count{uri="myURI"}[30s])rate(http_server_requests_seconds_count{uri="myURI"}[10s])rate(http_server_requests_seconds_count{uri="myURI"}[30s])然后我运行一个 python 脚本,其中创建了 5 个线程,每个线程都访问此 myURI 端点:
我在 Grafana 上看到的是:
我收到了这些值:
我预计会收到这些(但没有):
有人可以用我的例子解释这个函数背后的公式以及实现我期望的指标/值的方法吗?
我正在尝试使用 Micrometer.io 和 Spring Boot 2.0.0.RELEASE 来生成 Prometheus 指标。
当我尝试将 List 的大小公开为 Gauge 时,它一直显示 NaN。在文档中它说;
您有责任持有对您使用 Gauge 测量的状态对象的强引用。
我尝试了一些不同的方法,但我无法解决问题。这是我的一些试验代码。
import io.micrometer.core.instrument.*;
import io.swagger.backend.model.Product;
import io.swagger.backend.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@RestController
@RequestMapping("metrics")
public class ExampleController {
private AtomicInteger atomicInteger = new AtomicInteger();
private ProductService productService;
private final Gauge productGauge;
@Autowired
public HelloController(ProductService productService,
MeterRegistry registry) {
this.productService = productService;
createGauge("product_gauge", productService.getProducts(), registry);
}
private void createGauge(String metricName, List<Product> products,
MeterRegistry registry) {
List<Product> products = productService.getProducts();
// …Run Code Online (Sandbox Code Playgroud) 新手在这里,试图了解有关千分尺的更多信息。我目前正在探索如何实现这一点:
我正在使用启用了执行器和千分尺的 Spring boot 2。考虑以下类:
@Component
class MyService {
@Autowired
AuthorizeTransaction callbackTransaction;
@Autowired
AuthorizeTransaction immediateTransaction;
private MeterRegistry meterRegistry;
private Counter requestCounter;
private Counter responseCounter;
public MyService(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
initCounters();
}
private initCounters() {
requestCounter = Counter.builder("iso_request")
.tags("mti", "0100") // how do I change the value of this tag for other request types like 0200, 0120, etc.,
.register(meterRegistry);
responseCounter = Counter.builder("iso_response")
.tags("mti", "0101")
.tags("response_code", "00") // how do I change the value of this tag for other response …Run Code Online (Sandbox Code Playgroud) 从spring-boot-parent版本 2.5.5 升级到 2.6.0 后,我开始看到这些错误消息充斥着日志:
[INFO] [stdout] 2022-01-11 13:40:01.157 WARN 76859 --- [ udp-epoll-2] i.m.s.reactor.netty.channel.FluxReceive : [6d1243de, L:/127.0.0.1:58160 - R:localhost/127.0.0.1:8125] An exception has been observed post termination, use DEBUG level to see the full stack: java.net.PortUnreachableException: readAddress(..) failed: Connection refused
使用DEBUG级别:
[INFO] [stdout] 2022-01-11 13:38:29.733 WARN 76479 --- [ udp-epoll-2] i.m.s.reactor.netty.channel.FluxReceive : [43aad7ce, L:/127.0.0.1:38108 - R:localhost/127.0.0.1:8125] An exception has been observed post termination
[INFO] [stdout]
[INFO] [stdout] java.net.PortUnreachableException: readAddress(..) failed: Connection refused
[INFO] [stdout] at io.micrometer.shaded.io.netty.channel.epoll.EpollDatagramChannel.translateForConnected(EpollDatagramChannel.java:575)
[INFO] [stdout] …Run Code Online (Sandbox Code Playgroud) 将 Spring Boot 从版本 2.x 迁移到版本 3 后,我们在日志中丢失了 traceId 和 spanId。
我们删除了所有sleuth依赖项并添加了
implementation 'io.micrometer:micrometer-core'
implementation 'io.micrometer:micrometer-tracing'
implementation 'io.micrometer:micrometer-tracing-bridge-brave'
implementation platform('io.micrometer:micrometer-tracing-bom:latest.release')
Run Code Online (Sandbox Code Playgroud)
也
implementation 'io.micrometer:micrometer-core'
implementation 'io.micrometer:micrometer-tracing'
implementation 'io.micrometer:micrometer-tracing-bridge-brave'
implementation platform('io.micrometer:micrometer-tracing-bom:latest.release')
Run Code Online (Sandbox Code Playgroud)
但没有记录任何traceIds 和spanIds。
有什么我们错过的吗?
OpenApi 文档说它支持微米。整合如何运作?除了这个小文档之外我找不到任何东西。
我在 Spring Boot 应用程序中有一个 FeignClient
@FeignClient(name = "SomeService", url = "xxx", configuration = FeignConfiguration.class)
public interface SomeService {
@GET
@Path("/something")
Something getSomething();
}
Run Code Online (Sandbox Code Playgroud)
与配置
public class FeignConfiguration {
@Bean
public Capability capability() {
return new MicrometerCapability();
}
}
Run Code Online (Sandbox Code Playgroud)
和微米积分作为依赖项
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-micrometer</artifactId>
<version>10.12</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
该代码进行了调用,但我无法通过actuator概述找到任何新指标,需要一些有关我的 HTTP 请求的一般信息。缺少什么部分?
我有下面的代码,用于处理来自其他应用程序的请求,这些应用程序通过标头传递traceId Traceparent。我希望它能够从请求中吸收父级 TraceId,并且在 zipkin 仪表板中我应该看到该应用程序与其他应用程序之间的连接。它曾经与spring-cloud-sleuth-zipkin. 现在我迁移到spring boot 3,包改为micrometer-tracing-bridge-otel(参见pom.xml)。现在,它不再从请求中提取父traceId,而是生成一个全为0的默认父traceId,导致应用程序与zipkin仪表板中的其他应用程序断开连接
我使用带有标头的简单卷曲请求进行了测试Traceparent:curl --location --request GET 'http://localhost:8080/test' --header 'Traceparent: 00-63cf0173620c57b0aed605ee94255089-1444ca74c3d2133a-01'但此代码不会从标头中提取父上下文。知道如何进行这项工作吗?
@RestController
public class Test {
@Autowired
private Tracer tracer;
@GetMapping(path="/test")
public ResponseEntity<?> handleTest() {
ScopedSpan span = tracer.startScopedSpan("test span");
return ResponseEntity.ok();
}
}
Run Code Online (Sandbox Code Playgroud)
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
</parent>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-sender-urlconnection</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud) spring-boot spring-cloud-sleuth micrometer spring-micrometer micrometer-tracing