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
21 changes: 6 additions & 15 deletions src/Interpreters/OpenTelemetrySpanLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <Common/hex.h>
#include <Common/CurrentThread.h>
#include <Core/Field.h>


namespace DB
Expand Down Expand Up @@ -64,13 +65,7 @@ void OpenTelemetrySpanLogElement::appendToBlock(MutableColumns & columns) const
// The user might add some ints values, and we will have Int Field, and the
// insert will fail because the column requires Strings. Convert the fields
// here, because it's hard to remember to convert them in all other places.

Map map(attribute_names.size());
for (size_t attr_idx = 0; attr_idx < map.size(); ++attr_idx)
{
map[attr_idx] = Tuple{attribute_names[attr_idx], toString(attribute_values[attr_idx])};
}
columns[i++]->insert(map);
columns[i++]->insert(attributes);
}


Expand Down Expand Up @@ -158,35 +153,31 @@ void OpenTelemetrySpanHolder::addAttribute(const std::string& name, UInt64 value
if (trace_id == UUID())
return;

this->attribute_names.push_back(name);
this->attribute_values.push_back(std::to_string(value));
this->attributes.push_back(Tuple{name, toString(value)});
}

void OpenTelemetrySpanHolder::addAttribute(const std::string& name, const std::string& value)
{
if (trace_id == UUID())
return;

this->attribute_names.push_back(name);
this->attribute_values.push_back(value);
this->attributes.push_back(Tuple{name, value});
}

void OpenTelemetrySpanHolder::addAttribute(const Exception & e)
{
if (trace_id == UUID())
return;

this->attribute_names.push_back("clickhouse.exception");
this->attribute_values.push_back(getExceptionMessage(e, false));
this->attributes.push_back(Tuple{"clickhouse.exception", getExceptionMessage(e, false)});
}

void OpenTelemetrySpanHolder::addAttribute(std::exception_ptr e)
{
if (trace_id == UUID() || e == nullptr)
return;

this->attribute_names.push_back("clickhouse.exception");
this->attribute_values.push_back(getExceptionMessage(e, false));
this->attributes.push_back(Tuple{"clickhouse.exception", getExceptionMessage(e, false)});
}

bool OpenTelemetryTraceContext::parseTraceparentHeader(const std::string & traceparent,
Expand Down
3 changes: 1 addition & 2 deletions src/Interpreters/OpenTelemetrySpanLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ struct OpenTelemetrySpan
std::string operation_name;
UInt64 start_time_us;
UInt64 finish_time_us;
Array attribute_names;
Array attribute_values;
Map attributes;
// I don't understand how Links work, namely, which direction should they
// point to, and how they are related with parent_span_id, so no Links for now.
};
Expand Down
3 changes: 1 addition & 2 deletions src/Interpreters/ThreadStatusExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ void ThreadStatus::detachQuery(bool exit_if_already_detached, bool thread_exits)
span.finish_time_us =
std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
span.attribute_names.push_back("clickhouse.thread_id");
span.attribute_values.push_back(thread_id);
span.attributes.push_back(Tuple{"clickhouse.thread_id", toString(thread_id)});

opentelemetry_span_log->add(span);
}
Expand Down
44 changes: 12 additions & 32 deletions src/Interpreters/executeQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,28 +301,15 @@ static void onExceptionBeforeStart(const String & query_for_logging, ContextPtr
span.operation_name = "query";
span.start_time_us = current_time_us;
span.finish_time_us = time_in_microseconds(std::chrono::system_clock::now());

/// Keep values synchronized to type enum in QueryLogElement::createBlock.
span.attribute_names.push_back("clickhouse.query_status");
span.attribute_values.push_back("ExceptionBeforeStart");

span.attribute_names.push_back("db.statement");
span.attribute_values.push_back(elem.query);

span.attribute_names.push_back("clickhouse.query_id");
span.attribute_values.push_back(elem.client_info.current_query_id);

span.attribute_names.push_back("clickhouse.exception");
span.attribute_values.push_back(elem.exception);

span.attribute_names.push_back("clickhouse.exception_code");
span.attribute_values.push_back(elem.exception_code);

span.attributes.reserve(6);
span.attributes.push_back(Tuple{"clickhouse.query_status", "ExceptionBeforeStart"});
span.attributes.push_back(Tuple{"db.statement", elem.query});
span.attributes.push_back(Tuple{"clickhouse.query_id", elem.client_info.current_query_id});
span.attributes.push_back(Tuple{"clickhouse.exception", elem.exception});
span.attributes.push_back(Tuple{"clickhouse.exception_code", toString(elem.exception_code)});
if (!context->query_trace_context.tracestate.empty())
{
span.attribute_names.push_back("clickhouse.tracestate");
span.attribute_values.push_back(
context->query_trace_context.tracestate);
span.attributes.push_back(Tuple{"clickhouse.tracestate", context->query_trace_context.tracestate});
}

opentelemetry_span_log->add(span);
Expand Down Expand Up @@ -956,20 +943,13 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
span.start_time_us = elem.query_start_time_microseconds;
span.finish_time_us = time_in_microseconds(finish_time);

/// Keep values synchronized to type enum in QueryLogElement::createBlock.
span.attribute_names.push_back("clickhouse.query_status");
span.attribute_values.push_back("QueryFinish");

span.attribute_names.push_back("db.statement");
span.attribute_values.push_back(elem.query);

span.attribute_names.push_back("clickhouse.query_id");
span.attribute_values.push_back(elem.client_info.current_query_id);
span.attributes.reserve(4);
span.attributes.push_back(Tuple{"clickhouse.query_status", "QueryFinish"});
span.attributes.push_back(Tuple{"db.statement", elem.query});
span.attributes.push_back(Tuple{"clickhouse.query_id", elem.client_info.current_query_id});
if (!context->query_trace_context.tracestate.empty())
{
span.attribute_names.push_back("clickhouse.tracestate");
span.attribute_values.push_back(
context->query_trace_context.tracestate);
span.attributes.push_back(Tuple{"clickhouse.tracestate", context->query_trace_context.tracestate});
}

opentelemetry_span_log->add(span);
Expand Down