@@ -67,11 +67,9 @@ class JDBCDataSourceProvider : IDataSourceProvider {
6767
6868 // Add trace attributes for observability
6969 val currentSpan = Span .current()
70- val redactedUrl = redactConnectionString(resolvedUrl)
7170
7271 currentSpan.setAllAttributes(
7372 io.opentelemetry.api.common.Attributes .builder()
74- .put(" datasource.connection.redacted" , redactedUrl)
7573 .put(" datasource.cache.hit" , isCacheHit)
7674 .put(" datasource.cache.size" , dataSources.size.toLong())
7775 .put(" datasource.cache.max_size" , cacheConfig.resolveMaxSize().toLong())
@@ -102,30 +100,6 @@ class JDBCDataSourceProvider : IDataSourceProvider {
102100 return cachedDataSource.dataSource
103101 }
104102
105- private fun redactConnectionString (jdbcUrl : String ): String {
106- return try {
107- // Common patterns to redact in JDBC URLs
108- var redacted = jdbcUrl
109-
110- // Redact password parameter: password=value -> password=***
111- redacted = redacted.replace(Regex (" password=([^&;]+)" , RegexOption .IGNORE_CASE ), " password=***" )
112-
113- // Redact user credentials in URL format: user:password@host -> user:***@host
114- redacted = redacted.replace(Regex (" ://([^:]+):([^@]+)@" ), " ://$1:***@" )
115-
116- // Redact other sensitive parameters
117- redacted = redacted.replace(Regex (" pwd=([^&;]+)" , RegexOption .IGNORE_CASE ), " pwd=***" )
118- redacted = redacted.replace(Regex (" secret=([^&;]+)" , RegexOption .IGNORE_CASE ), " secret=***" )
119- redacted = redacted.replace(Regex (" token=([^&;]+)" , RegexOption .IGNORE_CASE ), " token=***" )
120- redacted = redacted.replace(Regex (" key=([^&;]+)" , RegexOption .IGNORE_CASE ), " key=***" )
121-
122- redacted
123- } catch (e: Exception ) {
124- // If redaction fails, return a safe fallback
125- " jdbc://***redacted***"
126- }
127- }
128-
129103 private fun startCleanupTask () {
130104 val executor = java.util.concurrent.Executors .newSingleThreadScheduledExecutor { r ->
131105 Thread (r, " DataSourceCacheCleanup" ).apply {
@@ -162,12 +136,6 @@ class JDBCDataSourceProvider : IDataSourceProvider {
162136
163137 expiredKeys.forEach { key ->
164138 dataSources.remove(key)?.let { cachedDataSource ->
165- val redactedUrl = redactConnectionString(key.jdbcUrl)
166- currentSpan.addEvent(" datasource.cache.expired_connection_removed" ,
167- io.opentelemetry.api.common.Attributes .of(
168- io.opentelemetry.api.common.AttributeKey .stringKey(" connection.redacted" ), redactedUrl
169- )
170- )
171139 closeDataSourceSafely(cachedDataSource.dataSource, key)
172140 }
173141 }
@@ -191,10 +159,8 @@ class JDBCDataSourceProvider : IDataSourceProvider {
191159
192160 sortedEntries.take(entriesToRemove).forEach { (key, cachedDataSource) ->
193161 dataSources.remove(key)
194- val redactedUrl = redactConnectionString(key.jdbcUrl)
195162 currentSpan.addEvent(" datasource.cache.oldest_connection_evicted" ,
196163 io.opentelemetry.api.common.Attributes .of(
197- io.opentelemetry.api.common.AttributeKey .stringKey(" connection.redacted" ), redactedUrl,
198164 io.opentelemetry.api.common.AttributeKey .longKey(" last_access_time" ), cachedDataSource.lastAccessTime
199165 )
200166 )
@@ -208,12 +174,10 @@ class JDBCDataSourceProvider : IDataSourceProvider {
208174 dataSource.close()
209175 }
210176 } catch (e: Exception ) {
211- val redactedUrl = redactConnectionString(key.jdbcUrl)
212177 // Add error to current span if available
213178 Span .current().recordException(e)
214179 Span .current().addEvent(" datasource.close.error" ,
215180 io.opentelemetry.api.common.Attributes .of(
216- io.opentelemetry.api.common.AttributeKey .stringKey(" connection.redacted" ), redactedUrl,
217181 io.opentelemetry.api.common.AttributeKey .stringKey(" error.message" ), e.message ? : " Unknown error"
218182 )
219183 )
0 commit comments