Skip to content

Commit

Permalink
Added http headers in opentelemetry span logs table
Browse files Browse the repository at this point in the history
  • Loading branch information
jonymohajanGmail committed Oct 11, 2024
1 parent 862c6cd commit cd126e6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Interpreters/ClientInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,19 @@ String toString(ClientInfo::Interface interface)
return std::format("Unknown {}!\n", static_cast<int>(interface));
}

String toString(ClientInfo::HTTPMethod method)
{
switch (method)
{
case ClientInfo::HTTPMethod::UNKNOWN:
return "UNKNOWN";
case ClientInfo::HTTPMethod::GET:
return "GET";
case ClientInfo::HTTPMethod::POST:
return "POST";
case ClientInfo::HTTPMethod::OPTIONS:
return "OPTIONS";
}
}

}
2 changes: 1 addition & 1 deletion src/Interpreters/ClientInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,5 @@ class ClientInfo
};

String toString(ClientInfo::Interface interface);

String toString(ClientInfo::HTTPMethod method);
}
3 changes: 3 additions & 0 deletions src/Server/GRPCServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,9 @@ namespace
query_context->getSettingsRef(),
query_context->getOpenTelemetrySpanLog());
thread_trace_context->root_span.kind = OpenTelemetry::SERVER;
thread_trace_context->root_span.addAttribute("http.referer", query_context->getClientInfo().http_referer);
thread_trace_context->root_span.addAttribute("http.user.agent", query_context->getClientInfo().http_user_agent);
thread_trace_context->root_span.addAttribute("http.method", toString(query_context->getClientInfo().http_method));

/// Prepare for sending exceptions and logs.
const Settings & settings = query_context->getSettingsRef();
Expand Down
3 changes: 3 additions & 0 deletions src/Server/HTTPHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,9 @@ void HTTPHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse
context->getOpenTelemetrySpanLog());
thread_trace_context->root_span.kind = OpenTelemetry::SERVER;
thread_trace_context->root_span.addAttribute("clickhouse.uri", request.getURI());
thread_trace_context->root_span.addAttribute("http.referer", session->getClientInfo().http_referer);
thread_trace_context->root_span.addAttribute("http.user.agent", session->getClientInfo().http_user_agent);
thread_trace_context->root_span.addAttribute("http.method", toString(session->getClientInfo().http_method));

response.setContentType("text/plain; charset=UTF-8");
response.set("X-ClickHouse-Server-Display-Name", server_display_name);
Expand Down
3 changes: 3 additions & 0 deletions src/Server/TCPHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ void TCPHandler::runImpl()
query_context->getSettingsRef(),
query_context->getOpenTelemetrySpanLog());
thread_trace_context->root_span.kind = OpenTelemetry::SERVER;
thread_trace_context->root_span.addAttribute("http.referer", query_context->getClientInfo().http_referer);
thread_trace_context->root_span.addAttribute("http.user.agent", query_context->getClientInfo().http_user_agent);
thread_trace_context->root_span.addAttribute("http.method", toString(query_context->getClientInfo().http_method));

query_scope.emplace(query_context, /* fatal_error_callback */ [this]
{
Expand Down

0 comments on commit cd126e6

Please sign in to comment.