Skip to content

Commit

Permalink
Refactor Spring starter's instrumentation auto configuration classes (#…
Browse files Browse the repository at this point in the history
…8950)

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
  • Loading branch information
Mateusz Rzeszutek and trask committed Jul 21, 2023
1 parent d17876e commit fd8e361
Show file tree
Hide file tree
Showing 47 changed files with 544 additions and 835 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class AnnotationInstrumentationModule extends InstrumentationModule {

public AnnotationInstrumentationModule() {
super("opentelemetry-instrumentation-annotations");
super("opentelemetry-instrumentation-annotations", "annotations");
}

@Override
Expand Down
20 changes: 10 additions & 10 deletions instrumentation/spring/spring-boot-autoconfigure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,16 @@ If an exporter is present in the classpath during runtime and a spring bean of t

##### Enabling/Disabling Features

| Feature | Property | Default Value | ConditionalOnClass |
| ---------------- | ----------------------------------- | ------------- | ---------------------- |
| spring-web | otel.springboot.httpclients.enabled | `true` | RestTemplate |
| spring-webmvc | otel.springboot.httpclients.enabled | `true` | OncePerRequestFilter |
| spring-webflux | otel.springboot.httpclients.enabled | `true` | WebClient |
| @WithSpan | otel.springboot.aspects.enabled | `true` | WithSpan, Aspect |
| Otlp Exporter | otel.exporter.otlp.enabled | `true` | OtlpGrpcSpanExporter |
| Jaeger Exporter | otel.exporter.jaeger.enabled | `true` | JaegerGrpcSpanExporter |
| Zipkin Exporter | otel.exporter.zipkin.enabled | `true` | ZipkinSpanExporter |
| Logging Exporter | otel.exporter.logging.enabled | `true` | LoggingSpanExporter |
| Feature | Property | Default Value | ConditionalOnClass |
|------------------|---------------------------------------------|---------------|------------------------|
| spring-web | otel.instrumentation.spring-webmvc.enabled | `true` | RestTemplate |
| spring-webmvc | otel.instrumentation.spring-web.enabled | `true` | OncePerRequestFilter |
| spring-webflux | otel.instrumentation.spring-webflux.enabled | `true` | WebClient |
| @WithSpan | otel.instrumentation.annotations.enabled | `true` | WithSpan, Aspect |
| Otlp Exporter | otel.exporter.otlp.enabled | `true` | OtlpGrpcSpanExporter |
| Jaeger Exporter | otel.exporter.jaeger.enabled | `true` | JaegerGrpcSpanExporter |
| Zipkin Exporter | otel.exporter.zipkin.enabled | `true` | ZipkinSpanExporter |
| Logging Exporter | otel.exporter.logging.enabled | `true` | LoggingSpanExporter |

<!-- Slf4j Log Correlation otel.springboot.loggers.slf4j.enabled true org.slf4j.MDC -->

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.spring.autoconfigure.aspects;
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;

/** Configures {@link WithSpanAspect} to trace bean methods annotated with {@link WithSpan}. */
@Configuration
@EnableConfigurationProperties(TraceAspectProperties.class)
@ConditionalOnProperty(prefix = "otel.springboot.aspects", name = "enabled", matchIfMissing = true)
@ConditionalOnBean(OpenTelemetry.class)
@ConditionalOnClass(Aspect.class)
public class TraceAspectAutoConfiguration {
@ConditionalOnProperty(name = "otel.instrumentation.annotations.enabled", matchIfMissing = true)
@Configuration
public class InstrumentationAnnotationsAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public ParameterNameDiscoverer parameterNameDiscoverer() {
ParameterNameDiscoverer parameterNameDiscoverer() {
return new DefaultParameterNameDiscoverer();
}

@Bean
@ConditionalOnClass(WithSpan.class)
public InstrumentationWithSpanAspect instrumentationWithSpanAspect(
InstrumentationWithSpanAspect otelInstrumentationWithSpanAspect(
OpenTelemetry openTelemetry, ParameterNameDiscoverer parameterNameDiscoverer) {
return new InstrumentationWithSpanAspect(openTelemetry, parameterNameDiscoverer);
}

@Bean
@SuppressWarnings("deprecation") // instrumenting deprecated class for backwards compatibility
@ConditionalOnClass(io.opentelemetry.extension.annotations.WithSpan.class)
public SdkExtensionWithSpanAspect sdkExtensionWithSpanAspect(
SdkExtensionWithSpanAspect otelSdkExtensionWithSpanAspect(
OpenTelemetry openTelemetry, ParameterNameDiscoverer parameterNameDiscoverer) {
return new SdkExtensionWithSpanAspect(openTelemetry, parameterNameDiscoverer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.spring.autoconfigure.aspects;
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations;

import io.opentelemetry.api.OpenTelemetry;
import org.aspectj.lang.ProceedingJoinPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.spring.autoconfigure.aspects;
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations;

import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.annotations.WithSpan;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.spring.autoconfigure.aspects;
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations;

import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesGetter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.spring.autoconfigure.aspects;
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations;

import io.opentelemetry.api.OpenTelemetry;
import org.aspectj.lang.ProceedingJoinPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.spring.autoconfigure.aspects;
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Span;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.spring.autoconfigure.aspects;
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations;

import io.opentelemetry.instrumentation.annotations.SpanAttribute;
import io.opentelemetry.instrumentation.api.annotation.support.ParameterAttributeNamesExtractor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.spring.autoconfigure.kafka;
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.kafka;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.spring.kafka.v2_7.SpringKafkaTelemetry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.spring.autoconfigure.kafka;
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.kafka;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.kafkaclients.v2_6.KafkaTelemetry;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.kafka.DefaultKafkaProducerFactoryCustomizer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.core.KafkaTemplate;

@Configuration
@EnableConfigurationProperties(KafkaInstrumentationProperties.class)
@ConditionalOnProperty(name = "otel.springboot.kafka.enabled", matchIfMissing = true)
@ConditionalOnBean(OpenTelemetry.class)
@ConditionalOnClass({KafkaTemplate.class, ConcurrentKafkaListenerContainerFactory.class})
@ConditionalOnProperty(name = "otel.instrumentation.kafka.enabled", matchIfMissing = true)
@Configuration
public class KafkaInstrumentationAutoConfiguration {

@Bean
public DefaultKafkaProducerFactoryCustomizer producerInstrumentation(
DefaultKafkaProducerFactoryCustomizer otelKafkaProducerFactoryCustomizer(
OpenTelemetry openTelemetry) {
KafkaTelemetry kafkaTelemetry = KafkaTelemetry.create(openTelemetry);
return producerFactory -> producerFactory.addPostProcessor(kafkaTelemetry::wrap);
}

@Bean
public ConcurrentKafkaListenerContainerFactoryPostProcessor
concurrentKafkaListenerContainerFactoryPostProcessor(OpenTelemetry openTelemetry) {
ConcurrentKafkaListenerContainerFactoryPostProcessor
otelKafkaListenerContainerFactoryBeanPostProcessor(OpenTelemetry openTelemetry) {
return new ConcurrentKafkaListenerContainerFactoryPostProcessor(openTelemetry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.spring.autoconfigure.logging;
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.logging;

import io.opentelemetry.api.OpenTelemetry;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
Expand All @@ -14,19 +14,16 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@ConditionalOnBean(OpenTelemetry.class)
@Configuration
@SuppressWarnings("OtelPrivateConstructorForUtilityClass")
@ConditionalOnBean(OpenTelemetry.class)
public class OpenTelemetryAppenderAutoConfiguration {

@Configuration
@ConditionalOnClass(org.apache.logging.log4j.core.LoggerContext.class)
@ConditionalOnProperty(
prefix = "otel.springboot.log4j-appender",
name = "enabled",
name = "otel.instrumentation.log4j-appender.enabled",
matchIfMissing = true)
@ConditionalOnClass({
io.opentelemetry.instrumentation.log4j.appender.v2_17.OpenTelemetryAppender.class
})
@Configuration
static class Log4jAppenderConfig {

@Bean
Expand All @@ -39,14 +36,11 @@ ApplicationListener<ApplicationReadyEvent> log4jOtelAppenderInitializer(
}
}

@Configuration
@ConditionalOnClass(ch.qos.logback.classic.LoggerContext.class)
@ConditionalOnProperty(
prefix = "otel.springboot.logback-appender",
name = "enabled",
name = "otel.instrumentation.logback-appender.enabled",
matchIfMissing = true)
@ConditionalOnClass({
io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender.class
})
@Configuration
static class LogbackAppenderConfig {

@Bean
Expand Down
Loading

0 comments on commit fd8e361

Please sign in to comment.