Skip to content

Commit bc4a94d

Browse files
committed
fix test, add doc
1 parent 8c0c767 commit bc4a94d

File tree

7 files changed

+36
-6
lines changed

7 files changed

+36
-6
lines changed

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/internal/InstrumenterContextTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ public Collection<String> getRawQueryTexts(Object request) {
6060
assertThat(spanNameExtractor.extract(null)).isEqualTo("SELECT test");
6161
// verify that sanitized statement was cached, see SqlStatementSanitizerUtil
6262
assertThat(InstrumenterContext.get()).containsKey("sanitized-sql-map");
63-
Map<String, SqlStatementInfo> sanitizedMap =
64-
(Map<String, SqlStatementInfo>) InstrumenterContext.get().get("sanitized-sql-map");
65-
assertThat(sanitizedMap).containsKey(testQuery);
63+
Map<Object, SqlStatementInfo> sanitizedMap =
64+
(Map<Object, SqlStatementInfo>) InstrumenterContext.get().get("sanitized-sql-map");
65+
assertThat(sanitizedMap).hasSize(1);
66+
Object key = sanitizedMap.keySet().iterator().next();
67+
assertThat(key.toString()).contains(testQuery);
6668

6769
// replace cached sanitization result to verify it is used
6870
sanitizedMap.put(
69-
testQuery,
70-
SqlStatementInfo.create("SELECT name2 FROM test2 WHERE id = ?", "SELECT", "test2"));
71+
key, SqlStatementInfo.create("SELECT name2 FROM test2 WHERE id = ?", "SELECT", "test2"));
7172
{
7273
AttributesBuilder builder = Attributes.builder();
7374
attributesExtractor.onStart(builder, Context.root(), null);

instrumentation/jdbc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
| System property | Type | Default | Description |
44
|-------------------------------------------------------------------|---------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
55
| `otel.instrumentation.jdbc.statement-sanitizer.enabled` | Boolean | `true` | Enables the DB statement sanitization. |
6+
| `otel.instrumentation.jdbc.statement-sanitizer.ansi-quotes` | Boolean | `false` | Sets whether the SQL sanitizer should treat double-quoted fragments as string literals or identifiers. By default, double quotes are used for string literals. When the sanitizer is able to detect that the used database does not support double-quoted string literals then this flag will be automatically switched. |
67
| `otel.instrumentation.jdbc.experimental.capture-query-parameters` | Boolean | `false` | Enable the capture of query parameters as span attributes. Enabling this option disables the statement sanitization. <p>WARNING: captured query parameters may contain sensitive information such as passwords, personally identifiable information or protected health info. |
78
| `otel.instrumentation.jdbc.experimental.transaction.enabled` | Boolean | `false` | Enables experimental instrumentation to create spans for COMMIT and ROLLBACK operations. |
89
| `otel.instrumentation.jdbc.experimental.sqlcommenter.enabled` | Boolean | `false` | Enables augmenting queries with a comment containing the tracing information. See [sqlcommenter](https://google.github.io/sqlcommenter/) for more info. WARNING: augmenting queries with tracing context will make query texts unique, which may have adverse impact on database performance. Consult with database experts before enabling. |

instrumentation/r2dbc-1.0/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
| System property | Type | Default | Description |
44
|----------------------------------------------------------------|---------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
55
| `otel.instrumentation.r2dbc.statement-sanitizer.enabled` | Boolean | `true` | Enables the DB statement sanitization. |
6-
| `otel.instrumentation.r2dbc.experimental.sqlcommenter.enabled` | Boolean | `false` | Enables augmenting queries with a comment containing the tracing information. See [sqlcommenter](https://google.github.io/sqlcommenter/) for more info. WARNING: augmenting queries with tracing context will make query texts unique, which may have adverse impact on database performance. Consult with database experts before enabling. |
6+
| `otel.instrumentation.r2dbc.statement-sanitizer.ansi-quotes` | Boolean | `false` | Sets whether the SQL sanitizer should treat double-quoted fragments as string literals or identifiers. By default, double quotes are used for string literals. When the sanitizer is able to detect that the used database does not support double-quoted string literals then this flag will be automatically switched. |
7+
| `otel.instrumentation.r2dbc.experimental.sqlcommenter.enabled` | Boolean | `false` | Enables augmenting queries with a comment containing the tracing information. See [sqlcommenter](https://google.github.io/sqlcommenter/) for more info. WARNING: augmenting queries with tracing context will make query texts unique, which may have adverse impact on database performance. Consult with database experts before enabling. |

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/jdbc/DataSourcePostProcessor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public Object postProcessAfterInitialization(Object bean, String beanName) {
6767
.setStatementSanitizationEnabled(
6868
InstrumentationConfigUtil.isStatementSanitizationEnabled(
6969
config, "otel.instrumentation.jdbc.statement-sanitizer.enabled"))
70+
.setStatementSanitizationAnsiQuotes(InstrumentationConfigUtil.isStatementSanitizationEnabled(
71+
config, "otel.instrumentation.jdbc.statement-sanitizer.ansi-quotes"))
7072
.setCaptureQueryParameters(
7173
config.getBoolean(
7274
"otel.instrumentation.jdbc.experimental.capture-query-parameters", false))

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/r2dbc/R2dbcInstrumentingPostProcessor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public Object postProcessAfterInitialization(Object bean, String beanName) {
3737
InstrumentationConfigUtil.isStatementSanitizationEnabled(
3838
configProvider.getObject(),
3939
"otel.instrumentation.r2dbc.statement-sanitizer.enabled"))
40+
.setStatementSanitizationAnsiQuotes(InstrumentationConfigUtil.isStatementSanitizationEnabled(
41+
configProvider.getObject(), "otel.instrumentation.r2dbc.statement-sanitizer.ansi-quotes"))
4042
.build()
4143
.wrapConnectionFactory(connectionFactory, getConnectionFactoryOptions(connectionFactory));
4244
}

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ public static boolean isStatementSanitizationEnabled(InstrumentationConfig confi
4545
return config.getBoolean(
4646
key, config.getBoolean("otel.instrumentation.common.db-statement-sanitizer.enabled", true));
4747
}
48+
49+
public static boolean isStatementSanitizationAnsiQuotes(InstrumentationConfig config, String key) {
50+
return config.getBoolean(
51+
key, config.getBoolean("otel.instrumentation.common.db-statement-sanitizer.ansi-quotes", false));
52+
}
4853
}

instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@
284284
"description": "Enables the DB statement sanitization.",
285285
"defaultValue": true
286286
},
287+
{
288+
"name": "otel.instrumentation.common.db-statement-sanitizer.ansi-quotes",
289+
"type": "java.lang.Boolean",
290+
"description": "Sets whether the SQL sanitizer should treat double-quoted fragments as string literals or identifiers. By default, double quotes are used for string literals. When the sanitizer is able to detect that the used database does not support double-quoted string literals then this flag will be automatically switched.",
291+
"defaultValue": false
292+
},
287293
{
288294
"name": "otel.instrumentation.common.default-enabled",
289295
"type": "java.lang.Boolean",
@@ -357,6 +363,12 @@
357363
"description": "Enables the DB statement sanitization.",
358364
"defaultValue": true
359365
},
366+
{
367+
"name": "otel.instrumentation.jdbc.statement-sanitizer.ansi-quotes",
368+
"type": "java.lang.Boolean",
369+
"description": "Sets whether the SQL sanitizer should treat double-quoted fragments as string literals or identifiers. By default, double quotes are used for string literals. When the sanitizer is able to detect that the used database does not support double-quoted string literals then this flag will be automatically switched.",
370+
"defaultValue": false
371+
},
360372
{
361373
"name": "otel.instrumentation.jdbc.experimental.capture-query-parameters",
362374
"type": "java.lang.Boolean",
@@ -518,6 +530,12 @@
518530
"description": "Enables the DB statement sanitization.",
519531
"defaultValue": true
520532
},
533+
{
534+
"name": "otel.instrumentation.r2dbc.statement-sanitizer.ansi-quotes",
535+
"type": "java.lang.Boolean",
536+
"description": "Sets whether the SQL sanitizer should treat double-quoted fragments as string literals or identifiers. By default, double quotes are used for string literals. When the sanitizer is able to detect that the used database does not support double-quoted string literals then this flag will be automatically switched.",
537+
"defaultValue": false
538+
},
521539
{
522540
"name": "otel.instrumentation.runtime-telemetry.capture-gc-cause",
523541
"type": "java.lang.Boolean",

0 commit comments

Comments
 (0)