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

Log errors in RestResponse regardless of error_trace parameter #101066

Merged
merged 4 commits into from Oct 31, 2023

Conversation

cbuescher
Copy link
Member

Currently, setting the "error_trace" request parameter to "true" leads to error stack traces being
included in the rest response, but will prevent logging them in the "rest.suppressed" logger in the
RestResponse class.
In order to improve visibility of those errors in our logs, this PR changes the logging behavior be
independent of the "error_trace" request parameter and only take the "rest.exception.stacktrace.skip"
parameter into account, which is only used internally.

Closes #100884

Currently we only log exceptions in RestResponse when the request parameter
"error_trace" isn't set or set to "false". If the client requests traces in the
rest response, we skip the server side logging. In order to improve visibility
of those errors in our logs this changes the logging behaviour to only depend on
the "rest.exception.stacktrace.skip" which is only used internally.

Closes elastic#100884
@cbuescher cbuescher added >enhancement :Core/Infra/Core Core issues without another label :Search/Search Search-related issues that do not fall into other categories v8.12.0 labels Oct 18, 2023
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Oct 18, 2023
@elasticsearchmachine
Copy link
Collaborator

Hi @cbuescher, I've created a changelog YAML for you.

@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Oct 18, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@cbuescher
Copy link
Member Author

fyi I left the "rest.exception.stacktrace.skip" condition in there around the logging block because I'm unsure how we internally use it today. Some research makes me think that we only ever change the global default of "rest.exception.stacktrace.skip == true" in overwrites to the XContent rendering parameter for certain object, e.g. like in

Params exceptionParams = new DelegatingMapParams(STACK_TRACE_ENABLED_PARAMS, params);
. If that understanding is correct we might as well remove the logic here and in tests as well and only keep the parameter around for xcontent rendering purposes.

Copy link
Contributor

@pgomulka pgomulka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one question, an additional one if we go ahead with this change (and I think we should) is whether the logger should still be called rest.suppressed. it seems like we are changing its behaviour significantly that it would deserve a rename as a follow-up, or at least a general discussion about the long-term direction.

@@ -115,7 +115,7 @@ public RestResponse(RestChannel channel, Exception e) throws IOException {
@SuppressWarnings("this-escape")
public RestResponse(RestChannel channel, RestStatus status, Exception e) throws IOException {
this.status = status;
ToXContent.Params params = paramsFromRequest(channel.request());
ToXContent.Params params = channel.request();
if (params.paramAsBoolean(REST_EXCEPTION_SKIP_STACK_TRACE, REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT) && e != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does this param come from? isn't its default true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in ElasticsearchExceptionL391 to decide whether stack traces are rendered as part of the xContent output of an exception. Some xContent Object use it to overwrite the default with "false", e.g. ExceptionWatchRecordL318, ILMHistoryItemL113 and maybe others (I didn't do a full search). The important thing I think that it should never be set through a Rest request but might be switched from the default "true" to "false" in several places programmatically.

Copy link
Contributor

@quux00 quux00 Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need still need this if check here?

params.paramAsBoolean(REST_EXCEPTION_SKIP_STACK_TRACE, REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT) 

Do we want to check it only if status.getStatus() < 500 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this again more closely, REST_EXCEPTION_SKIP_STACK_TRACE is only ever set to "false" in GetFeatureUpgradeStatusResponse, ExceptionWatchRecord and ILMHistoryItem because it seems someone decided to always render exception stack traces inside those objects. That also means it should never be set here, so you are right this check can be removed. The presence of an exception is still something we'd need to check I think, also we want to log both 400/500s here so I don't see why we should condition on status here. I will push some changes.

@@ -131,6 +131,9 @@ public RestResponse(RestChannel channel, RestStatus status, Exception e) throws
SUPPRESSED_ERROR_LOGGER.warn(messageSupplier, e);
}
}
if (params.paramAsBoolean("error_trace", false) && status != RestStatus.UNAUTHORIZED) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you are just rearranging code for this case, but (if you understand it) could you add a code comment of what this is for and what it is doing? It's not clear to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added comments

@cbuescher
Copy link
Member Author

@javanna @quux00 thanks for the additional review, I removed conditioning on the REST_EXCEPTION_SKIP_STACK_TRACE parameter in the RestResponse logging now since it cannot be different from the default value at least in this location. Its still used (and changed) for xcontent rendering so I'd like to keep it there for now. If we decide so we can also remove it there in a follow up. Let me know what you think.

Copy link
Contributor

@quux00 quux00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cbuescher cbuescher merged commit 73eb3ec into elastic:main Oct 31, 2023
13 checks passed
mark-vieira pushed a commit to mark-vieira/elasticsearch that referenced this pull request Nov 2, 2023
…ic#101066)

Currently we only log exceptions in RestResponse when the request parameter
"error_trace" isn't set or set to "false". If the client requests traces in the
rest response, we skip the server side logging. In order to improve visibility
of those errors in our logs this changes the logging behaviour to only depend on
the "rest.exception.stacktrace.skip" which is only used internally.

Closes elastic#100884
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Core Core issues without another label >enhancement :Search/Search Search-related issues that do not fall into other categories Team:Core/Infra Meta label for core/infra team Team:Search Meta label for search team v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Always log 500 errors in RestResponse
5 participants