-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQL92 and CouchDB sanitizers - squash merge from old branch
- Loading branch information
Showing
6 changed files
with
626 additions
and
12 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...on-api/src/main/java/io/opentelemetry/instrumentation/api/db/CouchStatementSanitizer.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.db; | ||
|
||
import static io.opentelemetry.instrumentation.api.db.StatementSanitizationConfig.isStatementSanitizationEnabled; | ||
import static io.opentelemetry.instrumentation.api.internal.SupportabilityMetrics.CounterNames.SQL_STATEMENT_SANITIZER_CACHE_MISS; | ||
|
||
import io.opentelemetry.instrumentation.api.caching.Cache; | ||
import io.opentelemetry.instrumentation.api.internal.SupportabilityMetrics; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* This class is responsible for masking potentially sensitive parameters in SQL (and SQL-like) | ||
* statements and queries. | ||
*/ | ||
public final class CouchStatementSanitizer { | ||
private static final SupportabilityMetrics supportability = SupportabilityMetrics.instance(); | ||
|
||
private static final Cache<String, SqlStatementInfo> sqlToStatementInfoCache = | ||
Cache.builder().setMaximumSize(1000).build(); | ||
|
||
public static SqlStatementInfo sanitize(@Nullable String statement) { | ||
if (!isStatementSanitizationEnabled() || statement == null) { | ||
return SqlStatementInfo.create(statement, null, null); | ||
} | ||
return sqlToStatementInfoCache.computeIfAbsent( | ||
statement, | ||
k -> { | ||
supportability.incrementCounter(SQL_STATEMENT_SANITIZER_CACHE_MISS); | ||
return AutoCouchSanitizer.sanitize(statement); | ||
}); | ||
} | ||
|
||
private CouchStatementSanitizer() {} | ||
} |
Oops, something went wrong.