Skip to content

Commit

Permalink
SQL92 and CouchDB sanitizers - squash merge from old branch
Browse files Browse the repository at this point in the history
  • Loading branch information
dboreham committed Nov 4, 2021
1 parent 81cb8e6 commit b292fee
Show file tree
Hide file tree
Showing 6 changed files with 626 additions and 12 deletions.
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() {}
}
Loading

0 comments on commit b292fee

Please sign in to comment.