Skip to content

Commit

Permalink
Added QueryStats data to Activity #339 (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkWanderer authored Jul 30, 2023
1 parent a1b0daa commit 715d28c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit 715d28c

Please sign in to comment.