Skip to content
Merged
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 @@ -18,7 +18,7 @@
public final class JdbcTelemetryBuilder {

private final OpenTelemetry openTelemetry;
private boolean dataSourceInstrumenterEnabled = true;
private boolean dataSourceInstrumenterEnabled = false;
private boolean statementInstrumenterEnabled = true;
private boolean statementSanitizationEnabled = true;
private boolean transactionInstrumenterEnabled = false;
Expand All @@ -34,7 +34,7 @@ public final class JdbcTelemetryBuilder {
this.openTelemetry = openTelemetry;
}

/** Configures whether spans are created for JDBC Connections. Enabled by default. */
/** Configures whether spans are created for JDBC Connections. Disabled by default. */
@CanIgnoreReturnValue
public JdbcTelemetryBuilder setDataSourceInstrumenterEnabled(boolean enabled) {
this.dataSourceInstrumenterEnabled = enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ void buildWithDefaults() throws SQLException {
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent"),
span -> span.hasName("TestDataSource.getConnection"),
span ->
span.hasName("SELECT dbname")
.hasAttribute(equalTo(maybeStable(DB_STATEMENT), "SELECT ?;"))));
Expand Down Expand Up @@ -99,7 +98,6 @@ void error() throws SQLException {
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent"),
span -> span.hasName("TestDataSource.getConnection"),
span ->
span.hasName("SELECT dbname")
.hasAttributesSatisfyingExactly(
Expand Down Expand Up @@ -164,6 +162,7 @@ void buildWithDataSourceInstrumenterDisabled() throws SQLException {
void buildWithStatementInstrumenterDisabled() throws SQLException {
JdbcTelemetry telemetry =
JdbcTelemetry.builder(testing.getOpenTelemetry())
.setDataSourceInstrumenterEnabled(true)
.setStatementInstrumenterEnabled(false)
.build();

Expand All @@ -180,10 +179,10 @@ void buildWithStatementInstrumenterDisabled() throws SQLException {
}

@Test
void buildWithTransactionInstrumenterDisabled() throws SQLException {
void buildWithTransactionInstrumenterEnabled() throws SQLException {
JdbcTelemetry telemetry =
JdbcTelemetry.builder(testing.getOpenTelemetry())
.setTransactionInstrumenterEnabled(false)
.setTransactionInstrumenterEnabled(true)
.build();

DataSource dataSource = telemetry.wrap(new TestDataSource());
Expand All @@ -200,7 +199,8 @@ void buildWithTransactionInstrumenterDisabled() throws SQLException {
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent"),
span -> span.hasName("TestDataSource.getConnection")));
span -> span.hasName("COMMIT"),
span -> span.hasName("ROLLBACK")));
}

@Test
Expand All @@ -219,7 +219,6 @@ void buildWithSanitizationDisabled() throws SQLException {
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent"),
span -> span.hasName("TestDataSource.getConnection"),
span ->
span.hasName("SELECT dbname")
.hasAttribute(equalTo(maybeStable(DB_STATEMENT), "SELECT 1;"))));
Expand Down Expand Up @@ -258,7 +257,6 @@ void batchStatement() throws SQLException {
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent"),
span -> span.hasName("TestDataSource.getConnection"),
span ->
span.hasName(
SemconvStability.emitStableDatabaseSemconv()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ class OpenTelemetryDataSourceTest {
@ParameterizedTest
@MethodSource("getConnectionMethodsArguments")
void shouldEmitGetConnectionSpans(GetConnectionFunction getConnection) throws SQLException {
JdbcTelemetry telemetry = JdbcTelemetry.create(testing.getOpenTelemetry());
JdbcTelemetry telemetry =
JdbcTelemetry.builder(testing.getOpenTelemetry())
.setDataSourceInstrumenterEnabled(true)
.build();
DataSource dataSource = telemetry.wrap(new TestDataSource());

Connection connection = testing.runWithSpan("parent", () -> getConnection.call(dataSource));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ public Object postProcessAfterInitialization(Object bean, String beanName) {
configPropertiesProvider
.getObject()
.getBoolean(
"otel.instrumentation.jdbc.experimental.transaction.enabled", false));
"otel.instrumentation.jdbc.experimental.transaction.enabled", false))
.setDataSourceInstrumenterEnabled(
configPropertiesProvider
.getObject()
.getBoolean(
"otel.instrumentation.jdbc.experimental.datasource.enabled", false));
Experimental.setEnableSqlCommenter(
builder,
configPropertiesProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@
"description": "Enables experimental instrumentation to create spans for COMMIT and ROLLBACK operations.",
"defaultValue": false
},
{
"name": "otel.instrumentation.jdbc.experimental.datasource.enabled",
"type": "java.lang.Boolean",
"description": "Enables experimental instrumentation to create spans for <code>DataSource.getConnection</code> calls.",
"defaultValue": false
},
{
"name": "otel.instrumentation.jdbc.experimental.sqlcommenter.enabled",
"type": "java.lang.Boolean",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ void databaseQuery() {
traceAssert ->
traceAssert.hasSpansSatisfyingExactly(
span -> span.hasName("server"),
span -> span.satisfies(s -> assertThat(s.getName()).endsWith(".getConnection")),
span ->
span.hasKind(SpanKind.CLIENT)
.hasAttribute(
Expand Down
Loading