You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is really just a result of a few hours trying to grasp this library's internals and finding a hacky way to get the query statement, along with start and end span markers. I'd love some recommendations @porsager if you have better thoughts on how to hook into this library. So far it works, but I wouldn't put it anywhere close to production without some more testing.
I'm thinking the following to cover various use cases:
options.stats: true or sql.stats() gives you the following properties on the query result
result.duration// the complete duration of the queryresult.waiting// the time the query waited to be sentresult.execution// the actual execution time (query sent to pg until response)
Now that's fine for hooking up or logging if required, but for the opentelemetry case, I'm thinking an option like this:
I'm thinking the following to cover various use cases:
options.stats: true or sql.stats() gives you the following properties on the query result
result.duration// the complete duration of the queryresult.waiting// the time the query waited to be sentresult.execution// the actual execution time (query sent to pg until response)
Now that's fine for hooking up or logging if required, but for the opentelemetry case, I'm thinking an option like this:
My approach for manual instrumentation would be to wrap the sql function returned by postgres() in another function that first calls tracer.startSpan(), then awaits the original sql function, and then calls span.end() with optional error handling.
Activity
porsager commentedon Aug 14, 2022
Hi @JerrySievert .. Thank you for the kind words..
I think it's a great idea to add some hooks so this can be achieved. I'll give some thoughts to how that could be achieved best.
JerrySievert commentedon Aug 14, 2022
fantastic! I look forward to seeing the addition, thanks for considering it.
tomsanbear commentedon Sep 27, 2022
Hey @JerrySievert @porsager
I ended up taking a stab at instrumenting this library over here:
https://github.com/tomsanbear/opentelemetry-instrumentation-postgres
This is really just a result of a few hours trying to grasp this library's internals and finding a hacky way to get the query statement, along with start and end span markers. I'd love some recommendations @porsager if you have better thoughts on how to hook into this library. So far it works, but I wouldn't put it anywhere close to production without some more testing.
JerrySievert commentedon Oct 6, 2022
@tomsanbear that's awesome, but is there some trick to getting it to work?
and then in my instrumentations when instantiating the sdk:
is there something else I need to do?
younanjo commentedon Mar 2, 2023
@porsager checking to see if there is any updates on supporting OpenTelemetry?
porsager commentedon Jun 25, 2023
I'm thinking the following to cover various use cases:
options.stats: true or sql.stats() gives you the following properties on the query result
Now that's fine for hooking up or logging if required, but for the opentelemetry case, I'm thinking an option like this:
I've got a branch with that setup here if you want to test it out https://github.com/porsager/postgres/tree/query-stats .. Let me know what you think:
clouedoc commentedon Jun 30, 2023
What might be interesting would be to also provide hooks for different lifecycle events of the query;
i.e., for instance, there might be a high "time to connect to postgres" compared to "time of query execution"
porsager commentedon Jul 1, 2023
That's exactly what the above is? 😉
clouedoc commentedon Jul 1, 2023
Oh, haha, yes, sorry about that; I didn't pay enough attention 🤦♂️
Thanks for your library, by the way!
gustavolzangelo commentedon Aug 11, 2023
@porsager this is perfect! I think these 3 stats are exactly what is needed. Is there any plan to implement this feature?
hastebrot commentedon Aug 14, 2023
My approach for manual instrumentation would be to wrap the
sql
function returned bypostgres()
in another function that first callstracer.startSpan()
, then awaits the originalsql
function, and then callsspan.end()
with optional error handling.Then the trace exporter would receive
startTimeUnixNano
andendTimeUnixNano
(as defined in otlp-transformer/src/trace/types.ts).24 remaining items