MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / logQueryException

Function logQueryException

src/Interpreters/executeQuery.cpp:796–861  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

794}
795
796void logQueryException(
797 QueryLogElement & elem,
798 const ContextMutablePtr & context,
799 const Stopwatch & start_watch,
800 const ASTPtr & query_ast,
801 std::shared_ptr<OpenTelemetry::SpanHolder> query_span,
802 bool internal,
803 bool log_error)
804{
805 const Settings & settings = context->getSettingsRef();
806 auto log_queries = settings[Setting::log_queries];
807
808 elem.type = QueryLogElementType::EXCEPTION_WHILE_PROCESSING;
809 elem.exception_code = getCurrentExceptionCode();
810 auto exception_message = getCurrentExceptionMessageAndPattern(/* with_stacktrace */ false);
811 elem.exception = std::move(exception_message.text);
812 elem.exception_format_string = exception_message.format_string;
813 elem.exception_format_string_args = exception_message.format_string_args;
814
815 QueryStatusPtr process_list_elem = context->getProcessListElement();
816
817 /// Update performance counters before logging to query_log
818 CurrentThread::finalizePerformanceCounters();
819 const auto time_now = std::chrono::system_clock::now();
820 elem.event_time = timeInSeconds(time_now);
821 elem.event_time_microseconds = timeInMicroseconds(time_now);
822
823 incrementFailedQueryProfileEvents(query_ast, context->getClientInfo(), internal);
824
825 QueryStatusInfoPtr info;
826 if (process_list_elem)
827 {
828 info = std::make_shared<QueryStatusInfo>(process_list_elem->getInfo(true, settings[Setting::log_profile_events], false));
829 addStatusInfoToQueryLogElement(elem, *info, query_ast, context, time_now);
830 }
831 else
832 {
833 elem.query_duration_ms = start_watch.elapsedMilliseconds();
834 }
835 logQueryMetricLogFinish(context, internal, elem.client_info.current_query_id, time_now, info);
836
837 elem.query_result_cache_usage = QueryResultCacheUsage::None;
838
839 elem.is_internal = internal;
840
841 if (settings[Setting::calculate_text_stack_trace] && log_error)
842 elem.stack_trace = getExceptionStackTraceString(std::current_exception());
843 logException(context, elem, log_error);
844
845 /// In case of exception we log internal queries also
846 if (log_queries && elem.type >= settings[Setting::log_queries_min_type]
847 && static_cast<Int64>(elem.query_duration_ms) >= settings[Setting::log_queries_min_query_duration_ms].totalMilliseconds())
848 {
849 if (auto query_log = context->getQueryLog())
850 query_log->add(elem);
851 }
852
853 if (query_span)

Callers 4

doExecuteTaskFunction · 0.85
executeQueryImplFunction · 0.85
processDataMethod · 0.85

Calls 15

getCurrentExceptionCodeFunction · 0.85
timeInSecondsFunction · 0.85
logQueryMetricLogFinishFunction · 0.85
logExceptionFunction · 0.85
getQueryLogMethod · 0.80
nowFunction · 0.50
timeInMicrosecondsFunction · 0.50
getProcessListElementMethod · 0.45

Tested by

no test coverage detected