pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.38k stars 5.86k forks source link

Support distributed tracing between user-application with tidb and other componentes #51144

Open taloric opened 9 months ago

taloric commented 9 months ago

Feature Request

Is your feature request related to a problem? Please describe: When we enabled opentracing both in our application (e.g.: a java web) and tidb, what we finally get is 2 seperated tracing results: one is application tracing and the other is tidb inside tracing.

Describe the feature you'd like: what need to be done first:

  1. enabled opentracing in tidb.
  2. use opentracing/opentelemtry instrumentation in applications

what we expected: A full tracing result cover the application and tidb both. Additionally, it it contains pd-server and tikv would be perfect.

Describe alternatives you've considered:

  1. Need a way to pass some trace infos from app to tidb (like trace-id)
  2. tidb client which request to pd-server and tikv need instrumentation by tracing sdk.
  3. pd-server and tikv need instrumentation by tracing sdk.

Teachability, Documentation, Adoption, Migration Strategy: If this can be done, when the application service cost too much time in some request , we can find out the real cost in the backend service and connect all component in one request. That would be a convenient way for optimize and error-tracking.

By the way, I can only find opentracing supported in tidb-server til now, if there're anything I've missed plz let me know, thanks very much!

Defined2014 commented 9 months ago

We had a demo before based on v4.0.12 which contained a new session variable tidb_trace_id and supported trace in TiKV side. If you have interests about it, you could try this PR.

Also we have a plan to support it later, but still under discussion. I hope you can give us feedback after trying the demo, whether this meets your needs and what should we improve it.

taloric commented 9 months ago

@Defined2014 Tks for the reply! The demo seems awesome, but I noticed that it's only for TiDB <-> TiKV, not related to user applications? Any plan in the future or any way right now to achieve this ?

Defined2014 commented 9 months ago

Application could execute SQL like set tidb_trace_id=xxx to link the TiDB.

taloric commented 8 months ago

@Defined2014 hello, thanks for the hint and I tried re-implement it in current TiDB version here's the pull request: #51539 and I paste my test result in it, any advice for this ?

Defined2014 commented 8 months ago

@Defined2014 hello, thanks for the hint and I tried re-implement it in current TiDB version here's the pull request: #51539 and I paste my test result in it, any advice for this ?

Thanks for your contribution, let me take a look at this PR, and it needs to be approved by the PM.

Frank945946 commented 4 months ago

@songrijie PTAL

StLeoX commented 2 months ago

Maybe variable name session_id is more intuitive?