Код: Выделить всё
org.springframework.boot
spring-boot-starter-parent
3.4.5
com.example
app
0.0.1
app
Demo project for Spring Boot Observability
24
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-actuator
io.micrometer
micrometer-registry-prometheus
io.opentelemetry
opentelemetry-exporter-otlp
io.micrometer
micrometer-tracing-bridge-otel
< /code>
@RestController
@SpringBootApplication
public class AppApplication {
Logger logger = LoggerFactory.getLogger(AppApplication.class);
public static void main(String[] args) {
SpringApplication.run(AppApplication.class, args);
}
@GetMapping("/")
public String root(@RequestParam(value = "name", defaultValue = "World") String name, @RequestHeader HttpHeaders headers) {
logger.error(headers.toString());
logger.error(String.format("Hello %s!!", name));
logger.debug("Debugging log");
logger.info("Info log");
logger.warn("Hey, This is a warning!");
logger.error("Oops! We have an Error. OK");
return String.format("Hello %s!!", name);
}
@GetMapping("/io_task")
public String io_task() throws InterruptedException {
Thread.sleep(1000);
logger.info("io_task");
return "io_task";
}
@GetMapping("/peanuts/{id}")
public Peanuts getPeanutsById(@PathVariable Long id) {
logger.info("Get Peanuts Character by id");
return new Peanuts(id, "Snoopy", "Charlie Brown's pet beagle");
}
record Peanuts(Long id, String name, String description) {}
}
Однако нет образцов. С или без того же проблемы.>
Подробнее здесь: https://stackoverflow.com/questions/796 ... -exemplars