You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a Spring Boot application has an endpoint defined that produces a response with an application/pdf content type, the service returning an error results in the response code being modified due to a failure in Spring.
My example is an application that returns a 403 response if the user is forbidden from accessing the endpoint, but when calling the API with the agent present the response becomes 406.
Package the project with mvn clean package and call the endpoint with curl http://localhost:8080/v4/check/87238923/report -I
Expected behavior
HTTP response code of 403 is returned, as the user is forbidden from accessing the resource
Actual behavior
HTTP response code of 406 is returned, and org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation is logged in the server
Javaagent or library instrumentation version
v1.3.1
Environment
JDK: 8 OS: MacOS
Additional context
I investigated the problem and have identified the root cause.
In OpenTelemetryHandlerMappingFilter.findMapping(), here, getHandler is called. Deep inside the getHandler call, RequestMappingInfoHandlerMapping.handleMatch(), here is called.
The RequestMappingInfoHandlerMapping.handleMatch() method sets several attributes onto the request, including org.springframework.web.servlet.HandlerMapping.producibleMediaTypes. Setting this attribute on the request, causes the error handling to fail as producibleMediaTypes is set to application/pdf from the request mapping. This content type does not match the JSON error response, resulting in an HTTP Response code of 406 being returned and an exception being logged.
Without the agent present, org.springframework.web.servlet.HandlerMapping.producibleMediaTypes is empty when processing the error response, allowing for the default application/json types to be used.
One of the attributes set on the request as part of RequestMappingInfoHandlerMapping.handleMatch() is used by SpringWebMvcServerSpanNaminghere.
I'm happy to help with a solution
The text was updated successfully, but these errors were encountered:
Incorporate the upstream fix to open-telemetry/opentelemetry-java-instrumentation#10379
by customizing the instrumentation as a temporary measure until the fix is merged and released upstream,
and this distro updates to that version
Signed-off-by: Ken Finnigan <ken@kenfinnigan.me>
Incorporate the upstream fix to open-telemetry/opentelemetry-java-instrumentation#10379
by customizing the instrumentation as a temporary measure until the fix is merged and released upstream,
and this distro updates to that version
Signed-off-by: Ken Finnigan <ken@kenfinnigan.me>
kenfinnigan
added a commit
to lumigo-io/opentelemetry-java-distro
that referenced
this issue
Feb 2, 2024
…bug (#279)
Incorporate the upstream fix to open-telemetry/opentelemetry-java-instrumentation#10379
by customizing the instrumentation as a temporary measure until the fix is merged and released upstream,
and this distro updates to that version
Signed-off-by: Ken Finnigan <ken@kenfinnigan.me>
Describe the bug
When a Spring Boot application has an endpoint defined that produces a response with an
application/pdf
content type, the service returning an error results in the response code being modified due to a failure in Spring.My example is an application that returns a
403
response if the user is forbidden from accessing the endpoint, but when calling the API with the agent present the response becomes406
.Steps to reproduce
I have a simple project which reproduces the failure: https://github.com/kenfinnigan/otel-spring-reproducer
Package the project with
mvn clean package
and call the endpoint withcurl http://localhost:8080/v4/check/87238923/report -I
Expected behavior
HTTP response code of 403 is returned, as the user is forbidden from accessing the resource
Actual behavior
HTTP response code of 406 is returned, and
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
is logged in the serverJavaagent or library instrumentation version
v1.3.1
Environment
JDK: 8
OS: MacOS
Additional context
I investigated the problem and have identified the root cause.
In
OpenTelemetryHandlerMappingFilter.findMapping()
, here,getHandler
is called. Deep inside thegetHandler
call,RequestMappingInfoHandlerMapping.handleMatch()
, here is called.The
RequestMappingInfoHandlerMapping.handleMatch()
method sets several attributes onto the request, includingorg.springframework.web.servlet.HandlerMapping.producibleMediaTypes
. Setting this attribute on the request, causes the error handling to fail asproducibleMediaTypes
is set toapplication/pdf
from the request mapping. This content type does not match the JSON error response, resulting in an HTTP Response code of406
being returned and an exception being logged.Without the agent present,
org.springframework.web.servlet.HandlerMapping.producibleMediaTypes
is empty when processing the error response, allowing for the defaultapplication/json
types to be used.One of the attributes set on the request as part of
RequestMappingInfoHandlerMapping.handleMatch()
is used bySpringWebMvcServerSpanNaming
here.I'm happy to help with a solution
The text was updated successfully, but these errors were encountered: