Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Spring Web: Automatically Report 4xx-5xx responses as errors in Kibana/Elastic #519

Closed
NicklasWallgren opened this issue Jan 24, 2025 · 2 comments

Comments

@NicklasWallgren
Copy link

NicklasWallgren commented Jan 24, 2025

The Elastic Java APM automatically reports spans with http.response.status_code in the 4xx and 5xx ranges as errors in Kibana when using Spring Boot, which is extremely useful. Is this functionality something that could be incorporated into the OpenTelemetry (OTel) agent and/or APM server?

While it’s possible to manually record these errors (for instance, by using a ControllerAdvice and invoking Span#recordException()) it would be great to have behavior similar to the Elastic agent built-in.

@JonasKunz
Copy link
Contributor

The Elastic Java APM automatically reports spans with http.response.status_code in the 4xx and 5xx ranges as errors in Kibana when using Spring Boot

The classic elastic APM agent doesn't automatically turn status codes into error-objects in the UI, at least to my knowledge.
The transaction is marked as failed for 5xx status codes automatically, but the same thing should be happening for for the opentelemetry agent.

I think the difference you are seeing come from exceptions raised by your controllers, which in turn are caught by spring and converted to corresponding status codes.
In the classic agent we have an instrumentation on spring level to preserve those exceptions from controllers and attach them to the transactions (which actually come from the Servlet-API instrumentation), this is why they appear as errors in the UI.

You can however achieve pretty much the same behaviour for the opentelemetry based agent:
By setting otel.instrumentation.common.experimental.controller-telemetry.enabled to true, you will get spans on the controller level in addition to the servlet-API root spans (= the transactions). If those spans (= the controller methods) end with exceptions, they will be recorded as errors.

Does this solve your problem already and give you the expected behaviour?

@NicklasWallgren
Copy link
Author

It does indeed - appreciate the detailed explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants