dd-trace-js
dd-trace-js copied to clipboard
Log query values in pg plugin (#1383)
What does this PR do?
Motivation
Plugin Checklist
- [ ] Unit tests.
- [ ] TypeScript definitions.
- [ ] TypeScript tests.
- [ ] API documentation.
- [ ] CircleCI jobs/workflows.
- [ ] Plugin is exported.
Additional Notes
Codecov Report
Merging #1456 (f6ad967) into master (63dca71) will increase coverage by
0.00%
. The diff coverage is100.00%
.
@@ 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.
@rochdev What solution would you prefer?
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.
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!