Apply SQL_BODY_MAX_LENGTH to ClickHouse JDBC plugin span tags#807
Merged
wu-sheng merged 2 commits intoapache:mainfrom Apr 30, 2026
Merged
Apply SQL_BODY_MAX_LENGTH to ClickHouse JDBC plugin span tags#807wu-sheng merged 2 commits intoapache:mainfrom
wu-sheng merged 2 commits intoapache:mainfrom
Conversation
ClickHouseStatementTracingWrapper (clickhouse-0.3.1-plugin) and ClickHousePrepareStatementTracing (clickhouse-0.3.2.x-plugin) wrote the raw SQL straight into the DB_STATEMENT span tag. Other JDBC plugins (mysql-*, postgresql-*, h2, mssql, etc.) route the same tag through SqlBodyUtil#limitSqlBodySize, which truncates the value to JDBCPluginConfig.Plugin.JDBC.SQL_BODY_MAX_LENGTH and appends "...". Without that helper the ClickHouse plugins ignore the user configuration and emit unbounded SQL bodies. Apply SqlBodyUtil#limitSqlBodySize in both interceptors so the tag respects the configured maximum length (and the negative-value sentinel that disables truncation). Add ClickHouseStatementTracingWrapperTest and ClickHousePrepareStatementTracingTest with three cases each (short sql passthrough, truncation at the configured limit, negative limit disables truncation), each restoring the configured limit in tearDown. Update CHANGES.md.
There was a problem hiding this comment.
Pull request overview
This PR ensures the ClickHouse JDBC plugins honor the global plugin.jdbc.sql_body_max_length behavior by routing db.statement tagging through SqlBodyUtil.limitSqlBodySize, aligning ClickHouse with the rest of the JDBC plugin family.
Changes:
- Apply
SqlBodyUtil.limitSqlBodySize(sql)when settingTags.DB_STATEMENTin both ClickHouse interceptors. - Add unit tests for short SQL passthrough, long SQL truncation, and negative-limit (no truncation) semantics in both plugin versions.
- Add a release-note entry describing the fix.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| apm-sniffer/apm-sdk-plugin/clickhouse-0.3.2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/clickhouse/v32/ClickHousePrepareStatementTracing.java | Truncates db.statement via SqlBodyUtil before tagging the span. |
| apm-sniffer/apm-sdk-plugin/clickhouse-0.3.1-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/clickhouse/ClickHouseStatementTracingWrapper.java | Truncates db.statement via SqlBodyUtil before tagging the span. |
| apm-sniffer/apm-sdk-plugin/clickhouse-0.3.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/clickhouse/ClickHousePrepareStatementTracingTest.java | Adds truncation/disable-truncation tests for the 0.3.2.x wrapper. |
| apm-sniffer/apm-sdk-plugin/clickhouse-0.3.1-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/clickhouse/ClickHouseStatementTracingWrapperTest.java | Adds truncation/disable-truncation tests for the 0.3.1 wrapper. |
| CHANGES.md | Documents the bug fix in release notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
wu-sheng
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ClickHouseStatementTracingWrapper(inclickhouse-0.3.1-plugin) andClickHousePrepareStatementTracing(inclickhouse-0.3.2.x-plugin) record the SQL string directly into theDB_STATEMENTspan tag:Every other JDBC plugin in
apm-sdk-plugin/routes the same tag throughSqlBodyUtil#limitSqlBodySize, which truncates the value toJDBCPluginConfig.Plugin.JDBC.SQL_BODY_MAX_LENGTHand appends.... As a result, an operator who lowersSQL_BODY_MAX_LENGTHto control trace payload size still sees the full unbounded SQL emitted by the ClickHouse plugins.Root Cause
The two ClickHouse interceptors miss the
SqlBodyUtil#limitSqlBodySizecall that the rest of the JDBC plugin family uses. The configuration option exists and works for every other JDBC dialect; only ClickHouse does not honour it.Fix
Wrap the SQL with
SqlBodyUtil#limitSqlBodySizein both interceptors.SqlBodyUtilalready handles the negative-limit sentinel that disables truncation, so behaviour is unchanged for users who left the default in place but rely on the disable-truncation override.Add a CHANGES.md entry under "Bug Fixes".
Tests Added
ClickHouseStatementTracingWrapper.oftruncates when SQL exceeds the configured limitClickHouseStatementTracingWrapperTest#longSqlIsTruncatedToConfiguredLimit— sets the limit to 16, asserts the recorded tag is the first 16 characters plus...ClickHouseStatementTracingWrapperTest#shortSqlIsRecordedAsIs— sets the limit to 2048, asserts the recorded tag equals the original SQLClickHouseStatementTracingWrapperTest#negativeLimitDisablesTruncation— sets the limit to -1 with a 3KB SQL, asserts the full SQL is recordedClickHousePrepareStatementTracing.ofClickHousePrepareStatementTracingTest#shortSqlIsRecordedAsIs,#longSqlIsTruncatedToConfiguredLimit,#negativeLimitDisablesTruncationmvn -pl apm-sniffer/apm-sdk-plugin/clickhouse-0.3.1-plugin,apm-sniffer/apm-sdk-plugin/clickhouse-0.3.2.x-plugin -am test— all 31 tests in clickhouse-0.3.2.x-plugin and 6 tests in clickhouse-0.3.1-plugin pass locally.Each test restores
JDBCPluginConfig.Plugin.JDBC.SQL_BODY_MAX_LENGTHin@Afterto keep test ordering safe.Impact
plugin.jdbc.sql_body_max_lengthwill now see the same truncation behaviour for ClickHouse spans that they already get for MySQL / PostgreSQL / H2 / SQL Server / ...