-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Closed
Labels
Description
Feature Request
Add a new system variable tidb_session_alias to print some custom trace info in log. After setting this var by:
> set @@tidb_session_alias='custom_session1'The log entries in the session will include a session_alias field:
[2023/08/14 17:48:50.766 +08:00] [WARN] [session.go:2255] ["compile SQL failed"] [conn=2097154] [session_alias=custom_session1] [error="[schema:1146]Table 'test.tnoexist' doesn't exist"] [SQL="select * from tnoexist"]
[2023/08/14 17:48:50.766 +08:00] [INFO] [conn.go:1096] ["command dispatched failed"] [conn=2097154] [session_alias=custom_session1] [connInfo="id:2097154, addr:127.0.0.1:61498 status:10, collation:utf8_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="select * from tnoexist"] [txn_mode=PESSIMISTIC] [timestamp=0] [err="[schema:1146]Table 'test.tnoexist' doesn't exist"]
Classifying logs with some custom dimensions (connection, statement, or business) will be helpful. The value of @@tidb_session_alias should also be propagated across nodes such as TiKV. For the above example, if the TiKV coprocessor execution is slow, a log with session_alias field will be logged like:
[2022/06/14 16:22:15.516 +08:00] [INFO] [tracker.rs:255] [slow-query] [connection_id=4132488064717029791] [session_alias=custom_session1] [perf_stats.internal_delete_skipped_count=0] [perf_stats.internal_key_skipped_count=0] [perf_stats.block_read_byte=48736] [perf_stats.block_read_count=2] [perf_stats.block_cache_hit_count=21] [scan.range.first="Some(start: 7480000000000002485F72800000008FEC1E34 end: 7480000000000002485F72800000008FEC1E35)"] [scan.ranges=2] [scan.total=2] [scan.processed=2] [scan.is_desc=false] [tag=select] [table_id=584] [txn_start_ts=433899413354053884] [total_suspend_time=0ns] [total_process_time=77ms] [handler_build_time=0ns] [wait_time.snapshot=0ns] [wait_time.schedule=2.101s] [wait_time=2.101s] [total_lifetime=2.178s] [remote_host=ipv4:192.168.1.20:54728] [region_id=1335237651]
connection id and session alias entry should be added to some kind of logs:
- tidb logs: *: Add system variable
tidb_session_aliasto log a custom fieldsession_aliasin session log #46072 - general/slow logs: *: add session alias field in slowlog, general log and extension framework #46273
- add statement tracing in TiKV coprocessor slow log #46673
- logs in
CoprocessorDAGHandlershould include tracing fields #46505 - add
connandsession_aliasentry in ddl worker log #46441 - add
session_aliasfield in audit logs #46502 - add
SESSION_ALIAScolumn in processlist table and expensive query log #46889 - variable: always truncate
tidb_session_aliaswhen it is not a valid value #46707
Reactions are currently unavailable