graphile / crystal

🔮 Graphile's Crystal Monorepo; home to Grafast, PostGraphile, pg-introspection, pg-sql2 and much more!
https://graphile.org/
Other
12.63k stars 572 forks source link

set pg client application_name parameter for pg_stat_activity and CSV log entries #499

Closed rngadam closed 6 years ago

rngadam commented 7 years ago

When using postgresql logging, application_name is useful to differentiate where the query originates from (interactive clients (pgadmin) or applications).

For Postgraphql, at the moment, application_name is set to an empty string ''

As per https://github.com/brianc/node-postgres/wiki/Client

string application_name:
default value: process.env.PGAPPNAME
name displayed in the pg_stat_activity view and included in CSV log entries

This seems to require a single change in postgraphql/cli.js:

var pgConfig = Object.assign({application_name: 'postgraphql'},

better yet would be to add additional information (graphql vs graphiql)

jmealo commented 7 years ago

:+1: I typically use the application_name GUC to identify the "web app user" executing a query and/or the request id/correlation id if "end-to-end" logging is present (by issuing a SET call prior to each query, which is required for security/RLS anyway).

benjie commented 6 years ago

This is possible (and easy to achieve) via pgSettings; I'm going to close this for now.

https://www.graphile.org/postgraphile/usage-library/#pgsettings-function