in opbeans/src/main/java/co/elastic/apm/opbeans/controllers/APIRestController.java [89:105]
ProductDetail product(@PathVariable long productId) {
Optional<ProductDetail> result;
Span span = tracer.spanBuilder("OpenTelemetry product span")
.setAttribute("product.id", productId)
.startSpan();
try (Scope scope = span.makeCurrent()) {
result = productRepository.getOneDetail(productId);
} finally {
span.end();
}
// Spring MVC uses exceptions to return a 404, thus we keep that out of the OTel span to avoid
// any confusion as it's not an actual server error but a way to return a client error.
return result.orElseThrow(notFound());
}