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

Added QueryStats data to Activity #339 #346

Merged
merged 1 commit into from
Jul 30, 2023
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
1 change: 1 addition & 0 deletions ClickHouse.Client/ADO/ClickHouseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ private async Task<HttpResponseMessage> PostSqlQueryAsync(string sqlQuery, Cance
var response = await connection.HttpClient.SendAsync(postMessage, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false);
QueryId = ExtractQueryId(response);
QueryStats = ExtractQueryStats(response);
activity.SetQueryStats(QueryStats);
return await ClickHouseConnection.HandleError(response, sqlQuery, activity).ConfigureAwait(false);
}

Expand Down
14 changes: 14 additions & 0 deletions ClickHouse.Client/Diagnostic/ActivitySourceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ internal static class ActivitySourceHelper
private const string TagUser = "db.user";
private const string TagService = "peer.service";
private const string TagThreadId = "thread.id";
private const string TagReadRows = "db.clickhouse.read_rows";
private const string TagReadBytes = "db.clickhouse.read_bytes";
private const string TagWrittenRows = "db.clickhouse.written_rows";
private const string TagWrittenBytes = "db.clickhouse.written_bytes";

internal const int StatementMaxLen = 300;

Expand Down Expand Up @@ -56,6 +60,16 @@ internal static void SetQuery(this Activity activity, string sql)
activity.SetTag(TagDbStatement, sql);
}

internal static void SetQueryStats(this Activity activity, QueryStats stats)
{
if (activity is null || stats is null)
return;
activity.SetTag(TagReadRows, stats.ReadRows);
activity.SetTag(TagReadBytes, stats.ReadBytes);
activity.SetTag(TagWrittenRows, stats.WrittenRows);
activity.SetTag(TagWrittenBytes, stats.WrittenBytes);
}

internal static void SetSuccess(this Activity activity)
{
#if NET6_0_OR_GREATER
Expand Down