Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ public static class PreviewConfiguration {

public boolean captureLog4jMarker;

public boolean captureJdbcQueryParameters;

// this is to support interoperability with other systems
// intentionally not allowing the removal of w3c propagator since that is key to many Azure
// integrated experiences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ private static void enableInstrumentations(
properties.put(
"otel.instrumentation.log4j-appender.experimental.capture-marker-attribute", "true");
}
if (config.preview.captureJdbcQueryParameters) {
properties.put("otel.instrumentation.jdbc.experimental.capture-query-parameters", "true");
}
if (config.preview.instrumentation.akka.enabled) {
properties.put("otel.instrumentation.akka-actor.enabled", "true");
properties.put("otel.instrumentation.akka-http.enabled", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ private void oracleStatement() throws Exception {
}

private static void executePreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement("select * from abc where xyz = ?");
ps.setString(1, "y");
PreparedStatement ps =
connection.prepareStatement("select * from abc where uvw = ? and xyz = ?");
ps.setString(1, "v");
ps.setString(2, "y");
ResultSet rs = ps.executeQuery();
while (rs.next()) {}
rs.close();
Expand Down Expand Up @@ -332,10 +334,10 @@ private static void testConnection(Connection connection, String sql) throws SQL

private static void setup(Connection connection) throws SQLException {
try (Statement statement = connection.createStatement()) {
statement.execute("create table abc (xyz varchar(10))");
statement.execute("insert into abc (xyz) values ('x')");
statement.execute("insert into abc (xyz) values ('y')");
statement.execute("insert into abc (xyz) values ('z')");
statement.execute("create table abc (uvw varchar(10), xyz varchar(10))");
statement.execute("insert into abc (uvw, xyz) values ('u', 'x')");
statement.execute("insert into abc (uvw, xyz) values ('v', 'y')");
statement.execute("insert into abc (uvw, xyz) values ('w', 'z')");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@

package com.microsoft.applicationinsights.smoketest;

import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.MapEntry.entry;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

@Environment(TOMCAT_8_JAVA_8)
@UseAgent("unmasked_applicationinsights.json")
class JdbcUnmaskedTest {
abstract class AbstractJdbcUnmasked {

@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.applicationinsights.smoketest;

import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.MapEntry.entry;

import org.junit.jupiter.api.Test;

@Environment(TOMCAT_8_JAVA_8)
@UseAgent("capture_params_applicationinsights.json")
class JdbcCaptureParametersTest extends AbstractJdbcUnmasked {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It requires Azure/azure-sdk-for-java#47526 to be passing


@Test
@TargetUri("/hsqldbPreparedStatement")
void hsqldbPreparedStatementCapturesParameters() throws Exception {
Telemetry telemetry = testing.getTelemetry(1);

assertThat(telemetry.rd.getProperties())
.containsExactly(entry("_MS.ProcessedByMetricExtractors", "True"));
assertThat(telemetry.rd.getSuccess()).isTrue();

assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT testdb.abc");
assertThat(telemetry.rdd1.getData()).isEqualTo("select * from abc where uvw = ? and xyz = ?");
assertThat(telemetry.rdd1.getType()).isEqualTo("SQL");
assertThat(telemetry.rdd1.getTarget()).isEqualTo("hsqldb | testdb");
assertThat(telemetry.rdd1.getSuccess()).isTrue();

assertThat(telemetry.rdd1.getProperties())
.containsExactly(entry("db.query.parameter.0", "v"), entry("db.query.parameter.1", "y"));

SmokeTestExtension.assertParentChild(
telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope1, "GET /Jdbc/*");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void hsqldbPreparedStatement() throws Exception {
assertThat(telemetry.rd.getSuccess()).isTrue();

assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT testdb.abc");
assertThat(telemetry.rdd1.getData()).isEqualTo("select * from abc where xyz = ?");
assertThat(telemetry.rdd1.getData()).isEqualTo("select * from abc where uvw = ? and xyz = ?");
assertThat(telemetry.rdd1.getType()).isEqualTo("SQL");
assertThat(telemetry.rdd1.getTarget()).isEqualTo("hsqldb | testdb");
assertThat(telemetry.rdd1.getProperties()).isEmpty();
Expand Down Expand Up @@ -170,7 +170,7 @@ void mysqlPreparedStatement() throws Exception {
assertThat(telemetry.rd.getSuccess()).isTrue();

assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT mysql.abc");
assertThat(telemetry.rdd1.getData()).isEqualTo("select * from abc where xyz = ?");
assertThat(telemetry.rdd1.getData()).isEqualTo("select * from abc where uvw = ? and xyz = ?");
assertThat(telemetry.rdd1.getType()).isEqualTo("mysql");
// not the best test, because this is both the db.name and db.system
assertThat(telemetry.rdd1.getTarget()).matches("dependency[0-9]+ \\| mysql");
Expand Down Expand Up @@ -214,7 +214,7 @@ void postgresPreparedStatement() throws Exception {
assertThat(telemetry.rd.getSuccess()).isTrue();

assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT postgres.abc");
assertThat(telemetry.rdd1.getData()).isEqualTo("select * from abc where xyz = ?");
assertThat(telemetry.rdd1.getData()).isEqualTo("select * from abc where uvw = ? and xyz = ?");
assertThat(telemetry.rdd1.getType()).isEqualTo("postgresql");
// not the best test, because this is both the db.name and db.system
assertThat(telemetry.rdd1.getTarget()).matches("dependency[0-9]+ \\| postgres");
Expand Down Expand Up @@ -256,7 +256,7 @@ void sqlServerPreparedStatement() throws Exception {
assertThat(telemetry.rd.getSuccess()).isTrue();

assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT abc");
assertThat(telemetry.rdd1.getData()).isEqualTo("select * from abc where xyz = ?");
assertThat(telemetry.rdd1.getData()).isEqualTo("select * from abc where uvw = ? and xyz = ?");
assertThat(telemetry.rdd1.getType()).isEqualTo("SQL");
assertThat(telemetry.rdd1.getTarget()).matches("dependency[0-9]+");
assertThat(telemetry.rdd1.getProperties()).isEmpty();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.applicationinsights.smoketest;

import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8;

@UseAgent("unmasked_applicationinsights.json")
@Environment(TOMCAT_8_JAVA_8)
class JdbcUnmaskedWithUnmakingFeatureTest extends AbstractJdbcUnmasked {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"role": {
"name": "testrolename",
"instance": "testroleinstance"
},
"sampling": {
"percentage": 100
},
"preview": {
"captureJdbcQueryParameters": true
}
}
Loading