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

Add a new system variable tidb_session_alias to print some custom trace info in log #46071

Closed
8 tasks done
lcwangchao opened this issue Aug 14, 2023 · 0 comments · Fixed by #46072
Closed
8 tasks done

Comments

@lcwangchao
Copy link
Collaborator

lcwangchao commented Aug 14, 2023

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:

@lcwangchao lcwangchao added type/feature-request Categorizes issue or PR as related to a new feature. sig/sql-infra SIG: SQL Infra type/new-feature and removed type/feature-request Categorizes issue or PR as related to a new feature. labels Aug 14, 2023
ti-chi-bot bot pushed a commit that referenced this issue Aug 18, 2023
ti-chi-bot bot pushed a commit that referenced this issue Aug 29, 2023
ti-chi-bot bot pushed a commit that referenced this issue Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant