dd-trace-js icon indicating copy to clipboard operation
dd-trace-js copied to clipboard

Log query values in pg plugin (#1383)

Open gstamac opened this issue 3 years ago • 3 comments

What does this PR do?

Motivation

Plugin Checklist

Additional Notes

gstamac avatar Jun 29 '21 12:06 gstamac

Codecov Report

Merging #1456 (f6ad967) into master (63dca71) will increase coverage by 0.00%. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1456   +/-   ##
=======================================
  Coverage   94.32%   94.32%           
=======================================
  Files         155      155           
  Lines        6375     6381    +6     
=======================================
+ Hits         6013     6019    +6     
  Misses        362      362           
Impacted Files Coverage Δ
packages/datadog-plugin-pg/src/index.js 94.00% <100.00%> (+0.81%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 63dca71...f6ad967. Read the comment docs.

codecov[bot] avatar Jun 30 '21 09:06 codecov[bot]

@rochdev What solution would you prefer?

gstamac avatar Jul 27 '21 08:07 gstamac

What solution would you prefer?

To be honest, the more I think about this the more I think a span hook would be the way to go here. It's generic so it would then be possible to include some or all query params if needed, but also add other metadata if needed with different requirements. It's also something we want to implement for every plugin anyway, but it's not always obvious what should be passed to the hook so we focused on web frameworks first, but we definitely want them implemented on every database as well.

Assuming the hook receives the query object, the functionality you need could then be implemented using the hook with:

tracer.use('pg', {
  hooks: {
    query: (span, query) => {
      span.setTag('sql.params', query.values)
    }
  }
})

While a bit more work than just a configuration option, it's also much more flexible to add/update the metadata on the span from whatever is available to the hook. It's also more secure in the sense that it's easier to determine what data is sensitive with full access to the query object, or to structure the tag differently so that a facet can be applied in the UI.

rochdev avatar Jul 27 '21 19:07 rochdev

I'm going to close this issue out as it looks like @rochdev was able to provide a workaround.

@gstamac if you still would like this feature to land then feel free to reopen the PR and continue the discussion!

tlhunter avatar Feb 21 '23 23:02 tlhunter