Include customized identifier in TiDB logfiles
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
When we troubleshoot issues, sometimes we need an easy way to connect user sessions with log entries in TiDB. This is quite useful when customers want to track the operations or messages produced by particular application transactions.
Here we can introduce a variable to inject customized identifier into TiDB logfile.
```
set tidb_session_identifer='trans#12345';
```
Extra column `[SESSID=]` can be inserted for the entries generated by this particular session. For example
```
[2023/04/06 14:03:42.891 +08:00] [WARN] [gc_worker.go:1130] ["[gc worker] distributed mode will be used"] ["invalid gc mode"=]
[2023/04/06 14:03:42.911 +08:00] [INFO] [gc_worker.go:1794] ["[gc worker] sent safe point to PD"] [uuid=61d547ce9c00006] ["safe point"=440601234064015360]
[2023/04/06 14:03:51.346 +08:00] [INFO] [set.go:161] [SESSID=trans#12345] ["set global var"] [conn=4132488064717029791] [name=tidb_general_log] [val=1]
[2023/04/06 14:03:56.792 +08:00] [INFO] [session.go:3839] [SESSID=trans#12345] [GENERAL_LOG] [conn=4132488064717029791] [user=root@127.0.0.1] [schemaVersion=56] [txnStartTS=0] [forUpdateTS=0] [isReadConsistency=false] [currentDB=bookshop] [isPessimistic=false] [sessionTxnMode=PESSIMISTIC] [sql="select /* this is comment */ * from authors where gender=1"]
[2023/04/06 14:07:02.303 +08:00] [INFO] [domain.go:2500] ["refreshServerIDTTL succeed"] [serverID=1879238] ["lease id"=223187551ec203bb]
[2023/04/06 14:07:19.949 +08:00] [INFO] [session.go:3839] [SESSID=trans#12345] [GENERAL_LOG] [conn=4132488064717029791] [user=root@127.0.0.1] [schemaVersion=56] [txnStartTS=0] [forUpdateTS=0] [isReadConsistency=false] [currentDB=bookshop] [isPessimistic=false] [sessionTxnMode=PESSIMISTIC] [sql="set global tidb_slow_log_threshold=1"]
```
Contributor guide
Assessment
This issue has not been assessed yet.