Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion server/src/main/java/org/apache/druid/server/QueryLifecycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public void emitLogsAndMetrics(

if (e != null) {
statsMap.put("exception", e.toString());
if (baseQuery.context().isDebug() || e.getMessage() == null) {
if (shouldLogStackTrace(e, baseQuery.context())) {
log.warn(e, "Exception while processing queryId [%s]", baseQuery.getId());
} else {
log.noStackTrace().warn(e, "Exception while processing queryId [%s]", baseQuery.getId());
Expand Down Expand Up @@ -518,4 +518,25 @@ enum State
DONE
}

/**
* Returns whether stack traces should be logged for a particular exception thrown with a particular query context.
* Stack traces are logged if {@link QueryContext#isDebug()}, or if the {@link DruidException.Persona} is
* {@link DruidException.Persona#DEVELOPER} or {@link DruidException.Persona#OPERATOR}. The idea is that other
* personas are meant to interact with the API, not with code or logs, so logging stack traces by default adds
* clutter that is not very helpful.
*
* @param e exception
* @param queryContext query context
*/
public static boolean shouldLogStackTrace(final Throwable e, final QueryContext queryContext)
{
if (queryContext.isDebug() || e.getMessage() == null) {
return true;
} else if (e instanceof DruidException) {
final DruidException.Persona persona = ((DruidException) e).getTargetPersona();
return persona == DruidException.Persona.OPERATOR || persona == DruidException.Persona.DEVELOPER;
} else {
return false;
}
}
}
3 changes: 2 additions & 1 deletion sql/src/main/java/org/apache/druid/sql/http/SqlResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.server.DruidNode;
import org.apache.druid.server.QueryLifecycle;
import org.apache.druid.server.QueryResource;
import org.apache.druid.server.QueryResponse;
import org.apache.druid.server.QueryResultPusher;
Expand Down Expand Up @@ -304,7 +305,7 @@ public void recordSuccess(long numBytes)
@Override
public void recordFailure(Exception e)
{
if (sqlQuery.queryContext().isDebug()) {
if (QueryLifecycle.shouldLogStackTrace(e, sqlQuery.queryContext())) {
log.warn(e, "Exception while processing sqlQueryId[%s]", sqlQueryId);
} else {
log.noStackTrace().warn(e, "Exception while processing sqlQueryId[%s]", sqlQueryId);
Expand Down
Loading