Hi all
Just saw this thread.
I cooked up a PoC distributed tracing support in Pg years ago as part of the 2ndQuadrant BDR project.
I used GUCs to set the `opentelemtery_trace_id` and `opentelemetry_span_id`. These can be sent as protocol-level messages by the client driver if the client driver has native trace integration enabled, in which case the user doesn't need to see or care. And for other drivers, the application can use `SET` or `SET LOCAL` to assign them.
This approach avoids the need to rewrite SQL or give special meaning to SQL comments.
Within the server IIRC I used the existing postgres resource owner and memory context stacks to maintain some internal nested traces.
My implementation used the C++ opentelemetry client library to emit traces, so it was never going to be able to land in core. But IIRC the current BDR/PGD folks are now using an OpenTelemetry sidecar process instead. I think they send it UDP packets to emit metrics and events. Petr or Markus might be able to tell you more about how they're doing that.
I'd love to see OpenTelemetry integration in Pg.