Repository navigation
Conversation
|
JVM timing with and without sanitizationPer query, in microseconds (µs). Measured on
Machine: Apple M4 Pro (14 cores, 48 GB), macOS 27.2.1, Temurin OpenJDK 17.0.13. Not idle: load average 4.7–5.5 during the runs (Gradle daemon and desktop apps). How often: 2 runs of 3 rounds each. Per round and statement: 6,000 measured calls per variant after 3,000 warm-up calls (100-parameter Setup:
Reading:
|
PR risk: mediumFor commit Main concerns: data sent to Sentry, reach, dependencies customers inherit. Rules that block low also fired:
This label is a hint for reviewers, not an approval. |
📲 Install BuildsAndroid
|
|
|
||
| private volatile @Nullable DatabaseUtils.DatabaseDetails cachedDatabaseDetails = null; | ||
| /** | ||
| * p6spy shares one listener across all datasources of the JVM, so details are cached per |
There was a problem hiding this comment.
h Can we avoid storing URLs by using ConnectionInformation.connectionId instead?
There was a problem hiding this comment.
Agreed that we shouldn't keep URLs around. Removed the cache instead of going with connectionId because:
connectionId comes from a static counter in ConnectionInformation's constructor, and p6spy creates a new ConnectionInformation for every getConnection() (P6DataSource) and every driver connect (P6SpyDriver). When p6spy wraps a pool (the datasource-decorator setup), every checkout gets a new id. An id-keyed cache would miss on the first statement of each checkout. To stay bounded it would also need eviction in onAfterConnectionClose, plus handling for leaked connections and subclasses that don't call super. Which seemed to error prone.
So the listener now parses the URL once per span, when the span starts, and keeps nothing. Measured on the JVM (M4 Pro, JDK 21): 0.1–0.45 µs and 0.3–1.1 KB per statement, with URI-style URLs (PostgreSQL, MySQL, Oracle //) at the high end. The cache lookups it replaces cost about 10 ns. That's small next to a database round trip. Details are still resolved per connection URL, so the dialect stays correct across datasources. databaseDetailsLock stays, unused, for binary compatibility.
Fixed in 8d38bda.
WDYT?
… URL The details cache was keyed by the full connection URL, which can contain credentials, and kept up to 64 URLs for the life of the process. Parse the URL once per span instead and set db.system and db.name when the span starts. This retains no URL and removes the cache, its cap and the insertion lock path. One parse costs 0.1-0.45 us on the JVM. The protected databaseDetailsLock stays for binary compatibility. Refs #6019
PR Stack (SQL Sanitizing)
📜 Description
Wires the SQL query analyzer from #6795 into
sentry-jdbc.SentryJdbcEventListeneranalyzes each statement inonBeforeAnyExecute, in the dialect of its connection's database system. The span description is the sanitized text (at most 32 KiB). The span also getsdb.query.text,db.query.summaryanddb.stored_procedure.namewhen present, anddb.system.nameanddb.namespacenext to the existingdb.systemanddb.name. If the analysis fails, the span keeps no query text at all, never the raw statement.auto.db.jdbcis an ignored span origin (the default in the OpenTelemetry agent and agentless-spring modes), the listener no longer reads the statement or the URL. The span would have been a no-op.DatabaseUtils: file-based database names (SQLite, H2, HSQLDB, Derby) are cut at;,?and#, so connection properties such as?password=…or?key=…no longer end up indb.name. URLs without a database path (jdbc:postgresql://host:5432/) give nodb.nameinstead of an empty one.sentry-test-support:hasSpanWithOpAndDescriptiontakes an optional map of span data that some span with that op and description must carry.💡 Motivation and Context
JDBC spans carry the raw SQL statement today, including literal values from statements that don't use bind parameters.
💚 How did you test it?
./gradlew :sentry-jdbc:check: 58 tests, 0 failures. The listener tests check wiring only: span fields equalSqlQueryAnalyzer's output for the URL's database system, so a grammar sync never needs re-baselining. The per-URL test uses a statement whose output differs between MySQL and PostgreSQL. Each new test was checked against a mutation of the listener (raw SQL as fallback description, missing null-URL guard, empty details past the cache bound, a wrapped raw statement in span data).sentry-spring-boot,sentry-spring-boot-jakartaandsentry-spring-boot-4integrationTest,sentry-spring-boot-4integrationTestOtlpnow assertdb.query.summaryanddb.system.nameon thedb.queryspan (expected values from the analyzer); they fail against the previous listener. The threeintegrationTestOtelNoAgentsuites pass as well (ignored-origin path). The OpenTelemetry agent suites and the Spring Boot version matrix are left to CI.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
[SQL Sanitizing 3]), with on-device timing.jdbc:tc:,jdbc:aws-wrapper:,jdbc:otel:,jdbc:log4jdbc:) to report the inner database system. Not needed for sanitization: an unknown system gets the stricter dialect.#skip-changelog