public inbox for [email protected]  
help / color / mirror / Atom feed
Tracing in PostgreSQL with Extended Query Protocol
3+ messages / 2 participants
[nested] [flat]

* Tracing in PostgreSQL with Extended Query Protocol
@ 2025-02-17 22:52 Hugo Sousa <[email protected]>
  2025-02-18 04:45 ` Re: Tracing in PostgreSQL with Extended Query Protocol Tom Lane <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Hugo Sousa @ 2025-02-17 22:52 UTC (permalink / raw)
  To: pgsql-novice

Hi,

I'm working on improving observability at my workplace and looking to add tracing at the database level. We use an observability provider that connects to our PostgreSQL instance and can extract traces from SQLCommenter-compliant comments.

However, we make heavy use of the extended query protocol, and from my understanding, SQL comments don’t work in that context. Given this, I was wondering:

  *   Is there a way to attach tracing information when using the extended query protocol?
  *   Are there any best practices or tools that can help with this?
  *   Is there a plan to add more observability to Postgresql, alined maybe with the OpenTelemetry Project?

Any advice or pointers would be greatly appreciated!

Thanks in advance,


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Tracing in PostgreSQL with Extended Query Protocol
  2025-02-17 22:52 Tracing in PostgreSQL with Extended Query Protocol Hugo Sousa <[email protected]>
@ 2025-02-18 04:45 ` Tom Lane <[email protected]>
  2025-02-18 10:04   ` Re: Tracing in PostgreSQL with Extended Query Protocol Hugo Sousa <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2025-02-18 04:45 UTC (permalink / raw)
  To: Hugo Sousa <[email protected]>; +Cc: pgsql-novice

Hugo Sousa <[email protected]> writes:
> However, we make heavy use of the extended query protocol, and from
> my understanding, SQL comments don’t work in that context.

Why do you think that?

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Tracing in PostgreSQL with Extended Query Protocol
  2025-02-17 22:52 Tracing in PostgreSQL with Extended Query Protocol Hugo Sousa <[email protected]>
  2025-02-18 04:45 ` Re: Tracing in PostgreSQL with Extended Query Protocol Tom Lane <[email protected]>
@ 2025-02-18 10:04   ` Hugo Sousa <[email protected]>
  0 siblings, 0 replies; 3+ messages in thread

From: Hugo Sousa @ 2025-02-18 10:04 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: pgsql-novice

From my understanding when we use the Extended Query Protocol we are parsing a query only once and then we bind them to specific parameter values to them execute aka prepared statements. To use a standard like SQLCommenter, for my purpose we would need to pass specific trace values for every execution of the query as every query execution is correlated to a different trace (a static comment should work).

Most documentation and examples I can find validate that it’s not possible to pass tracing data if the underlying sql command is done using a prepared statement.
To validate this I tried creating a prepared statement that would allow a dynamic trace id in a comment:
PREPARE example_statement AS /* trace=$1::text */ SELECT * FROM users WHERE id=$2;
But I got the following error "ERROR:  could not determine data type of parameter $1" and other variations of the prepared statement ended in similar problems.

We wouldn’t want to lose the performance benefits and the added security of using prepared statements, but this ability to trace all the way to the database layer and reverse would be very beneficial to us (and I hope to more people). I just want to know is this possible, if yes can I help in any way to add this capability?


> On 18 Feb 2025, at 04:45, Tom Lane <[email protected]> wrote:
> 
> Hugo Sousa <[email protected]> writes:
>> However, we make heavy use of the extended query protocol, and from
>> my understanding, SQL comments don’t work in that context.
> 
> Why do you think that?
> 
> 			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2025-02-18 10:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-02-17 22:52 Tracing in PostgreSQL with Extended Query Protocol Hugo Sousa <[email protected]>
2025-02-18 04:45 ` Tom Lane <[email protected]>
2025-02-18 10:04   ` Hugo Sousa <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox