Skip to content

added parameter bind logging #309

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

Closed
wants to merge 1 commit into from

Conversation

62mkv
Copy link

@62mkv 62mkv commented Jul 30, 2020

closes #278

Make sure that:

  • You have read the contribution guidelines.
  • You have created a feature request first to discuss your contribution intent. Please reference the feature request ticket number in the pull request.
  • You use the code formatters provided here and have them applied to your changes. Don't submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.

Not sure what tests should I provide along with this?

Issue description

#278

New Public APIs

none

Additional context

Query Parameter values are now visible in the logs

@62mkv 62mkv force-pushed the gh-278-add-parameter-logging branch from 46a4317 to 7b3b311 Compare July 30, 2020 15:06
@mp911de
Copy link
Collaborator

mp911de commented Jul 31, 2020

Thanks for submitting a pull request. Care to attach a snippet as comment how the logs would look like?

I'm considering to slightly tweak the logging behavior. Since we have already a query logger, we might want to keep the actual SQL and the parameters somewhat close together so one can reason about the query and its parameters.

Let's see how the log output would look like before we continue here.

@mp911de mp911de added the type: enhancement A general enhancement label Jul 31, 2020
@mp911de mp911de added this to the 0.8.5.RELEASE milestone Jul 31, 2020
@62mkv
Copy link
Author

62mkv commented Aug 11, 2020

Hi. This is how the output looks like for me:

Started
2020-08-11 17:04:06.741 DEBUG 8288 --- [  restartedMain] io.r2dbc.postgresql.PARAM                : Parameter 0 value bound: %a%
2020-08-11 17:04:06.744 DEBUG 8288 --- [  restartedMain] io.r2dbc.postgresql.PARAM                : Parameter 1 value bound: 1
2020-08-11 17:04:06.744 DEBUG 8288 --- [  restartedMain] io.r2dbc.postgresql.PARAM                : Parameter 2 value bound: 2020-01-01
2020-08-11 17:04:06.773 DEBUG 8288 --- [actor-tcp-nio-1] io.r2dbc.postgresql.QUERY                : Executing query: SELECT TEMPDATA.id, TEMPDATA.textdata, TEMPDATA.tzdata FROM TEMPDATA WHERE TEMPDATA.textdata LIKE $1 AND (TEMPDATA.id > $2) AND (TEMPDATA.tzdata > $3)
Finished

I'm considering to slightly tweak the logging behavior. Since we have already a query logger, we might want to keep the actual SQL and the parameters somewhat close together so one can reason about the query and its parameters.

Could you please provide a little bit more details, on how you see it accomplished?

Thanks!

@62mkv
Copy link
Author

62mkv commented Aug 11, 2020

where I see a problem with the above (apart from off-by-one numbering) is what might happen in mass-parallel scenarios. So arguably, if we could put some unique query execution id into both QUERY and PARAM logger output so user could correlate those together, would be great. However at the moment I have no idea how to achieve this..

@Squiry
Copy link
Collaborator

Squiry commented Aug 11, 2020

I believe we need some connection id in log, in every log, not only bindings, that would help a lot.

@ttddyy
Copy link
Contributor

ttddyy commented Aug 11, 2020

FYI, If you want to log bindings and query all together(also connection id), r2dbc-proxy provides such capability.
Here is sample log.
(It is multilined for display purpose but actual logging is single line, and configurable to own format)

@mp911de
Copy link
Collaborator

mp911de commented Aug 14, 2020

The log output looks good already. I second @Squiry's view, that we need to add context. Single-process logs are easy to understand, but in production environments we get way more log output than that.

In the SQL Server driver, we've introduced ConnectionContext that is a factory for log messages holding the connection/channel Id for easier tracing. We could do here the same.

I'll be off for around two weeks, I can have a look afterward. Alternatively, feel free to check out the SQL server driver and introduce the contextual log message factory.

@Squiry
Copy link
Collaborator

Squiry commented Aug 18, 2020

We have a processId that can be used as a connection id provided by backend, but we have it only after connection succeed.

@mp911de
Copy link
Collaborator

mp911de commented Oct 15, 2020

I filed #339 to capture more context so we can correlate bind calls to the actual connection.

mp911de pushed a commit that referenced this pull request Oct 15, 2020
mp911de added a commit that referenced this pull request Oct 15, 2020
Adopt to ConnectionContext. Tweak log message wording. Defer Objects.toString(…) until actual logging happens.

[#278][#309]
mp911de pushed a commit that referenced this pull request Oct 15, 2020
mp911de added a commit that referenced this pull request Oct 15, 2020
Adopt to ConnectionContext. Tweak log message wording. Defer Objects.toString(…) until actual logging happens.

[#278][#309]
@mp911de mp911de added this to the 0.8.6.RELEASE milestone Oct 15, 2020
@mp911de
Copy link
Collaborator

mp911de commented Oct 15, 2020

Thank you for your contribution. That's merged, polished, and backported now.

@mp911de mp911de closed this Oct 15, 2020
@62mkv
Copy link
Author

62mkv commented Oct 15, 2020

Thanks @mp911de !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add capability to log query parameters (bindings) values
4 participants