@@ -43,6 +43,30 @@ class ClientCase : public testing::TestWithParam<ClientOptions> {
4343        return  " SELECT "   + column_name + "  FROM "   + table_name;
4444    }
4545
46+     void  FlushLogs () {
47+         try  {
48+             client_->Execute (" SYSTEM FLUSH LOGS"  );
49+         } catch  (const  std::exception & e) {
50+             std::cerr << " Got error while flushing logs: "   << e.what () << std::endl;
51+             const  auto  wait_for_flush = []() {
52+                 //  Insufficient privileges, the only safe way is to wait long enough for system
53+                 //  to flush the logs automaticaly. Usually it takes 7.5 seconds, so just in case,
54+                 //  wait 3 times that to ensure that all previously executed queries are in the logs now.
55+                 const  auto  wait_duration = std::chrono::seconds (23 );
56+                 std::cerr << " Now we wait "   << wait_duration << " ..."   << std::endl;
57+                 std::this_thread::sleep_for (wait_duration);
58+             };
59+             //  DB::Exception: clickhouse_cpp_cicd: Not enough privileges. To execute this query it's necessary to have grant SYSTEM FLUSH LOGS ON
60+             if  (std::string (e.what ()).find (" To execute this query it's necessary to have grant SYSTEM FLUSH LOGS ON"  ) != std::string::npos) {
61+                 wait_for_flush ();
62+             }
63+             //  DB::Exception: clickhouse_cpp_cicd: Cannot execute query in readonly mode
64+             if  (std::string (e.what ()).find (" Cannot execute query in readonly mode"  ) != std::string::npos) {
65+                 wait_for_flush ();
66+             }
67+         }
68+     }
69+ 
4670    std::unique_ptr<Client> client_;
4771    const  std::string table_name = " test_clickhouse_cpp_test_ut_table"  ;
4872    const  std::string column_name = " test_column"  ;
@@ -850,19 +874,7 @@ TEST_P(ClientCase, Query_ID) {
850874    client_->SelectCancelable (" SELECT 'b', count(*) FROM "   + table_name, query_id, [](const  Block &) { return  true ; });
851875    client_->Execute (Query (" TRUNCATE TABLE "   + table_name, query_id));
852876
853-     try  {
854-         client_->Execute (" SYSTEM FLUSH LOGS"  );
855-     } catch  (const  std::exception & e) {
856-         //  DB::Exception: clickhouse_cpp_cicd: Not enough privileges. To execute this query it's necessary to have grant SYSTEM FLUSH LOGS ON
857-         if  (std::string (e.what ()).find (" To execute this query it's necessary to have grant SYSTEM FLUSH LOGS ON"  ) != std::string::npos) {
858-             //  Insufficient privileges, the only safe way is to wait long enough for system
859-             //  to flush the logs automatically. Usually it takes 7.5 seconds, so just in case,
860-             //  wait 3 times that to ensure that all previously executed queries are in the logs now.
861-             const  auto  wait_duration = std::chrono::seconds (23 );
862-             std::cerr << " Got error while flushing logs, now we wait "   << wait_duration << " ..."   << std::endl;
863-             std::this_thread::sleep_for (wait_duration);
864-         }
865-     }
877+     FlushLogs ();
866878
867879    size_t  total_count = 0 ;
868880    client_->Select (" SELECT type, query_kind, query_id, query " 
@@ -1115,6 +1127,31 @@ TEST_P(ClientCase, ServerLogs) {
11151127}
11161128
11171129
1130+ TEST_P (ClientCase, TracingContext) {
1131+     Block block;
1132+     createTableWithOneColumn<ColumnString>(block);
1133+ 
1134+     Query query (" INSERT INTO "   + table_name + "  (*) VALUES (\' Foo\' ), (\' Bar\' )"   );
1135+     open_telemetry::TracingContext tracing_context;
1136+     std::srand (std::time (0 ));
1137+     tracing_context.trace_id  = {std::rand (), std::rand ()};
1138+     query.SetTracingContext (tracing_context);
1139+     client_->Execute (query);
1140+ 
1141+     FlushLogs ();
1142+ 
1143+     size_t  received_rows = 0 ;
1144+     client_->Select (" SELECT trace_id, toString(trace_id), operation_name " 
1145+                    " FROM system.opentelemetry_span_log " 
1146+                    " WHERE trace_id = toUUID(\' "   + ToString (tracing_context.trace_id ) + " \' );"  ,
1147+         [&](const  Block& block) {
1148+             //  std::cerr << PrettyPrintBlock{block} << std::endl;
1149+             received_rows += block.GetRowCount ();
1150+     });
1151+ 
1152+     EXPECT_GT (received_rows, 0u );
1153+ }
1154+ 
11181155const  auto  LocalHostEndpoint = ClientOptions()
11191156        .SetHost(           getEnvOrDefault(" CLICKHOUSE_HOST"  ,     " localhost"  ))
11201157        .SetPort(   getEnvOrDefault<size_t >(" CLICKHOUSE_PORT"  ,     " 9000"  ))
0 commit comments