Skip to content

feat(node): add ClickHouse instrumentation - #26211

Open
adityareddy-dev wants to merge 6 commits into
getsentry:developfrom
adityareddy-dev:feat/node-clickhouse-instrumentation
Open

adityareddy-dev wants to merge 6 commits into
getsentry:developfrom
adityareddy-dev:feat/node-clickhouse-instrumentation

Conversation

@adityareddy-dev

@adityareddy-dev adityareddy-dev commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Why: Add DB spans for @clickhouse/client and @clickhouse/client-web through 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

@github-actions github-actions Bot added the external PR from an external contributor label Nov 9, 2026
@adityareddy-dev adityareddy-dev changed the title feat(node): add ClickHouse instrumentation (AR-139) feat(node): add ClickHouse instrumentation Nov 9, 2026
@adityareddy-dev
adityareddy-dev marked this pull request as ready for review November 9, 2026 19:10
@adityareddy-dev
adityareddy-dev requested review from a team as code owners November 9, 2026 19:10
@adityareddy-dev
adityareddy-dev requested review from JPeer264, andreiborza, nicohrubec and s1gr1d and removed request for a team November 9, 2026 19:10
@adityareddy-dev
adityareddy-dev requested review from Lms24 and msonnb and removed request for a team November 9, 2026 19:10

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

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.
@adityareddy-dev
adityareddy-dev requested a review from a team November 13, 2026 11:31
@adityareddy-dev

Copy link
Copy Markdown
Contributor Author

@JPeer264 can you approve the workflows on the latest push?

@JPeer264

Copy link
Copy Markdown
Member

@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 JPeer264 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change that to using the latest version, so we know if it is failing:

Suggested change
"@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' },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the docs of ClickHouse the TABLE is optional and we should also respect that optional addition and should add the following test:

Suggested change
{ 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({

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Suggested change
...(method === 'insert' ? getInsertAttributes(params) : getStatementAttributes(params)),
...(method === 'insert' ? getInsertAttributes(params) : getSqlQueryAttributes(typeof params?.query === 'string' ? params.query : undefined, 'clickhouse')),,

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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' });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Triggered by learned rule: E2E span ops from @sentry/conventions

Reviewed by Cursor Bugbot for commit 2723867. Configure here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clickhouse instrumentation (@clickhouse/client)

2 participants