-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add automatic JDBC instrumentation to the OTel Spring starter (#11258)
- Loading branch information
1 parent
7aca36f
commit a9a97c0
Showing
12 changed files
with
618 additions
and
76 deletions.
There are no files selected for viewing
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
12 changes: 0 additions & 12 deletions
12
...ain/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryInjector.java
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
...ry/instrumentation/spring/autoconfigure/instrumentation/jdbc/DataSourcePostProcessor.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,41 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.jdbc; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.jdbc.datasource.JdbcTelemetry; | ||
import javax.sql.DataSource; | ||
import org.springframework.aop.scope.ScopedProxyUtils; | ||
import org.springframework.beans.factory.ObjectProvider; | ||
import org.springframework.beans.factory.config.BeanPostProcessor; | ||
import org.springframework.core.Ordered; | ||
|
||
final class DataSourcePostProcessor implements BeanPostProcessor, Ordered { | ||
|
||
private final ObjectProvider<OpenTelemetry> openTelemetryProvider; | ||
|
||
DataSourcePostProcessor(ObjectProvider<OpenTelemetry> openTelemetryProvider) { | ||
this.openTelemetryProvider = openTelemetryProvider; | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
@Override | ||
public Object postProcessAfterInitialization(Object bean, String beanName) { | ||
// Exclude scoped proxy beans to avoid double wrapping | ||
if (bean instanceof DataSource && !ScopedProxyUtils.isScopedTarget(beanName)) { | ||
DataSource dataSource = (DataSource) bean; | ||
return JdbcTelemetry.create(openTelemetryProvider.getObject()).wrap(dataSource); | ||
} | ||
return bean; | ||
} | ||
|
||
// To be one of the first bean post-processors to be executed | ||
@Override | ||
public int getOrder() { | ||
return Ordered.LOWEST_PRECEDENCE - 20; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ation/spring/autoconfigure/instrumentation/jdbc/JdbcInstrumentationAutoconfiguration.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,36 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.jdbc; | ||
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.SdkEnabled; | ||
import javax.sql.DataSource; | ||
import org.springframework.beans.factory.ObjectProvider; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Conditional; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@ConditionalOnProperty(name = "otel.instrumentation.jdbc.enabled", matchIfMissing = true) | ||
@AutoConfiguration(after = DataSourceAutoConfiguration.class) | ||
@ConditionalOnBean({DataSource.class}) | ||
@Conditional(SdkEnabled.class) | ||
@Configuration(proxyBeanMethods = false) | ||
public class JdbcInstrumentationAutoconfiguration { | ||
|
||
// For error prone | ||
public JdbcInstrumentationAutoconfiguration() {} | ||
|
||
@Bean | ||
// static to avoid "is not eligible for getting processed by all BeanPostProcessors" warning | ||
static DataSourcePostProcessor dataSourcePostProcessor( | ||
ObjectProvider<OpenTelemetry> openTelemetryProvider) { | ||
return new DataSourcePostProcessor(openTelemetryProvider); | ||
} | ||
} |
47 changes: 0 additions & 47 deletions
47
...n/spring/autoconfigure/instrumentation/jdbc/OpenTelemetryJdbcDriverAutoConfiguration.java
This file was deleted.
Oops, something went wrong.
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
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
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
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
Oops, something went wrong.