Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tagging queries without transactions? #12

Closed
OrKoN opened this issue May 12, 2017 · 6 comments
Closed

Tagging queries without transactions? #12

OrKoN opened this issue May 12, 2017 · 6 comments
Labels

Comments

@OrKoN
Copy link

OrKoN commented May 12, 2017

Hi @vitaly-t

I was wondering if there is a way to tag a query that is not a task or transaction? I would like to provider a context id so that I know what http request has caused the query execution when I log it with pg-monitor. For example:

db.none('UPDATE ...', 'my-http-request-id')

... 


const log = (msg, info) => {
  logger.debug(`${info.event}: ${info.text}`, {
    sql: true,
    event: info.event,
    requestId: info.tag,
  });
  info.display = false;
};

Thanks in advance

@vitaly-t
Copy link
Owner

Only tasks support tagging. You can always use a task even for a single query, it is no overhead in performance.

Alternatively, you can add your own method via event extend, one that would take in a tag and then output it as you like.

@OrKoN
Copy link
Author

OrKoN commented May 12, 2017

@vitaly-t I have tried the log tagged tasks but it seems that tag is not available on the info object as I have expected. Is there another way to intercept with the logging so that I get the tag a standalone attribute?

@vitaly-t
Copy link
Owner

vitaly-t commented May 12, 2017

Event log doesn't contain a separate tag attribute, because it is part of the formatted message - msg property. So if you simply log the msg, the tag will be there.

@vitaly-t
Copy link
Owner

vitaly-t commented May 12, 2017

I've added an initial commit to expose the entire ctx = task/transaction context within the log event: 5dc56d8

Will finish it later, when I get a chance ;)

@OrKoN
Copy link
Author

OrKoN commented May 22, 2017

@vitaly-t thanks

@vitaly-t
Copy link
Owner

vitaly-t commented Jun 7, 2017

@OrKoN Finished and released as v0.8.0.

Now you can do:

const log = (msg, info) => {
    if (info.ctx) {
        console.log('TAG:', info.ctx.tag);
    }
};

@vitaly-t vitaly-t closed this as completed Jun 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants