Repository navigation
feat(node): add ClickHouse instrumentation - #26211
adityareddy-dev wants to merge 6 commits into
Conversation
The sanitizer stopped looking for the FORMAT clause once an INSERT reached SELECT, so rows read through input() stayed in db.query.text. FORMAT is now the data clause anywhere at the top level of an INSERT, unless the token before it expects a name, as in SELECT format or FROM format.
|
@JPeer264 can you approve the workflows on the latest push? |
|
@adityareddy-dev done. Btw I'll review that next week as something else came in this week. Also I'm not too familiar with clickhouse, so I have to go a bit deeper into it to give a proper review. |
`bun run` does not inject the diagnostics channels, so the ClickHouse suite gets no spans there. It passes in the `node-suites-bun-build` project, which bundles the scenarios with `@sentry/bun/plugin`.
JPeer264
left a comment
There was a problem hiding this comment.
Thanks a lot for integrating this. It looks pretty good already - I found couple of things that are worth to fix.
| "@aws-sdk/client-sfn": "^3.1161.0", | ||
| "@aws-sdk/client-sns": "^3.1161.0", | ||
| "@aws-sdk/client-sqs": "^3.1161.0", | ||
| "@clickhouse/client": "1.25.0", |
There was a problem hiding this comment.
We should change that to using the latest version, so we know if it is failing:
| "@clickhouse/client": "1.25.0", | |
| "@clickhouse/client": "^1.25.0", |
|
|
||
| const MODULES = [ | ||
| { name: '@clickhouse/client-common', versionRange: '>=1.1.0 <1.23.0', filePath: 'dist/client.js' }, | ||
| { name: '@clickhouse/client', versionRange: '>=1.23.0 <2', filePath: 'dist/common/client.js' }, |
There was a problem hiding this comment.
I've seen that @clickhouse/client-web can also be used in Cloudflare Workers. It makes actually sense to add support for client-web as well. Given that this is true, please add a test inside cloudflare-integration-test for clickhouse on top, to verify it works there too.
There was a problem hiding this comment.
The bundled Worker test passed for query, command, exec and insert. Each produced a span on success and on a handled error.
| @@ -0,0 +1,367 @@ | |||
| let integerLiteralRE: RegExp | undefined; | |||
There was a problem hiding this comment.
Was there any specific reason to move this into it's own file? I would assume it was because of the max-lines linting rule? If so, you can simply ignore that at the top of the file, so it is easier to see the actual change. We'll take care in the future and split this up in refactoring PRs where it is only moved.
| const EXPECTED_SPANS = [ | ||
| { name: 'CREATE TABLE events', status: 'ok', operation: 'CREATE', text: CREATE_TABLE }, | ||
| { name: 'INSERT events', status: 'ok', operation: 'INSERT', text: undefined, collection: 'events' }, | ||
| { name: 'INSERT events', status: 'ok', operation: 'INSERT', text: 'INSERT INTO events' }, |
There was a problem hiding this comment.
Based on the docs of ClickHouse the TABLE is optional and we should also respect that optional addition and should add the following test:
| { name: 'INSERT events', status: 'ok', operation: 'INSERT', text: 'INSERT INTO events' }, | |
| { name: 'INSERT events', status: 'ok', operation: 'INSERT', text: 'INSERT INTO TABLE events' }, |
Based on my testing you can change the regex for INSERT_RE to the following and the test would work:
`^\\s*(?<operation>INSERT|REPLACE)(?:\\s+OR\\s+(?:ROLLBACK|ABORT|FAIL|IGNORE|REPLACE))?\\s+INTO(?:\\s+TABLE)?\\s+(?<table>${TABLE_NAME})`,
| expect(startInactiveSpanSpy).toHaveBeenCalledWith({ | ||
| name: 'SELECT events', | ||
| onlyIfParent: true, | ||
| attributes: expect.objectContaining({ |
There was a problem hiding this comment.
Please remove expect.objectContaining and be explicit on all attributes. If you use an agent you can use the /write-tests skill and update the tests based on it. That is true for other occurrences in this file where attributes: expect.ObjectContaining has been used
| [SENTRY_KIND]: 'client', | ||
| [SENTRY_ORIGIN]: ORIGIN, | ||
| ...getConnectionAttributes(data.self?.connectionParams, params), | ||
| ...(method === 'insert' ? getInsertAttributes(params) : getStatementAttributes(params)), |
There was a problem hiding this comment.
More of a nit. This could be simplified to the following, given that getStatementAttributes is only used here (getStatementAttributes can then also be removed as a whole):
| ...(method === 'insert' ? getInsertAttributes(params) : getStatementAttributes(params)), | |
| ...(method === 'insert' ? getInsertAttributes(params) : getSqlQueryAttributes(typeof params?.query === 'string' ? params.query : undefined, 'clickhouse')),, |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2723867. Configure here.
| for (const span of dbSpans) { | ||
| expect(span.parent_span_id).toBe(segment?.span_id); | ||
| expect(span.trace_id).toBe(segment?.trace_id); | ||
| expect(span.attributes[SENTRY_OP]).toEqual({ type: 'string', value: 'db' }); |
There was a problem hiding this comment.
Test uses raw span op literal
Low Severity
Flagged because the review rules require new integration tests to compare span ops via @sentry/conventions/op constants rather than string literals. This new Cloudflare suite asserts sentry.op as 'db' instead of the DB export, unlike the Node ClickHouse tests in this PR.
Additional Locations (1)
Triggered by learned rule: E2E span ops from @sentry/conventions
Reviewed by Cursor Bugbot for commit 2723867. Configure here.


Why: Add DB spans for
@clickhouse/clientand@clickhouse/client-webthrough Orchestrion, following the maintainer's go-ahead. Rejected calls set span status and still reach the caller without a separate captured error.How to review: Start with the ClickHouse config and integration, then the Node and Cloudflare scenarios. The sanitizer stays in
sql.ts.Unsure about: Clients with an explicit custom tracer can emit additional spans. The integration leaves that option alone.
Closes #15966