trace - How to replace ZipkinSpanExporter to my Own in spring boot application? - Stack Overflow

I have an application based on spring boot 3.4I have application.properties with lines:management.tra

I have an application based on spring boot 3.4

I have application.properties with lines:

management.tracing.sampling.probability=1
management.zipkin.tracing.export.enabled=false

and dependencies:

// bridges the Micrometer Observation API to OpenTelemetry.
implementation("io.micrometer:micrometer-tracing-bridge-otel")
// reports traces to Zipkin.
implementation("io.opentelemetry:opentelemetry-exporter-zipkin")

I see that following configuration responsible for reporter creation but I want to replace it with my own implementation.

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ ZipkinSpanExporter.class, Span.class })
static class OpenTelemetryConfiguration {

    @Bean
    @ConditionalOnMissingBean(value = Span.class, parameterizedContainer = BytesEncoder.class)
    BytesEncoder<Span> spanBytesEncoder(Encoding encoding) {
        return SpanBytesEncoder.forEncoding(encoding);
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnBean(BytesMessageSender.class)
    @ConditionalOnEnabledTracing("zipkin")
    ZipkinSpanExporter zipkinSpanExporter(BytesMessageSender sender, BytesEncoder<Span> spanBytesEncoder) {
        return ZipkinSpanExporter.builder().setSender(sender).setEncoder(spanBytesEncoder).build();
    }

}

As far I understand reporter is chosen here:

package .springframework.boot.actuate.autoconfigure.tracing;

.....

/**
 * {@link SpringBootCondition} to check whether tracing is enabled.
 *
 * @author Moritz Halbritter
 * @see ConditionalOnEnabledTracing
 */
class OnEnabledTracingCondition extends SpringBootCondition {

    private static final String GLOBAL_PROPERTY = "management.tracing.enabled";

    private static final String EXPORTER_PROPERTY = "management.%s.tracing.export.enabled";

    @Override
    public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
        String tracingExporter = getExporterName(metadata);
        ...
      }
      
      private static String getExporterName(AnnotatedTypeMetadata metadata) {
         Map<String, Object> attributes = 
         metadata.getAnnotationAttributes(ConditionalOnEnabledTracing.class.getName());
         if (attributes == null) {
             return null;
         }
         return (String) attributes.get("value");
      }

I am lost here. In debug I see that tracingExporter is empty string

How can I override it? is it possible to provide configuration via application.properties ?

I have an application based on spring boot 3.4

I have application.properties with lines:

management.tracing.sampling.probability=1
management.zipkin.tracing.export.enabled=false

and dependencies:

// bridges the Micrometer Observation API to OpenTelemetry.
implementation("io.micrometer:micrometer-tracing-bridge-otel")
// reports traces to Zipkin.
implementation("io.opentelemetry:opentelemetry-exporter-zipkin")

I see that following configuration responsible for reporter creation but I want to replace it with my own implementation.

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ ZipkinSpanExporter.class, Span.class })
static class OpenTelemetryConfiguration {

    @Bean
    @ConditionalOnMissingBean(value = Span.class, parameterizedContainer = BytesEncoder.class)
    BytesEncoder<Span> spanBytesEncoder(Encoding encoding) {
        return SpanBytesEncoder.forEncoding(encoding);
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnBean(BytesMessageSender.class)
    @ConditionalOnEnabledTracing("zipkin")
    ZipkinSpanExporter zipkinSpanExporter(BytesMessageSender sender, BytesEncoder<Span> spanBytesEncoder) {
        return ZipkinSpanExporter.builder().setSender(sender).setEncoder(spanBytesEncoder).build();
    }

}

As far I understand reporter is chosen here:

package .springframework.boot.actuate.autoconfigure.tracing;

.....

/**
 * {@link SpringBootCondition} to check whether tracing is enabled.
 *
 * @author Moritz Halbritter
 * @see ConditionalOnEnabledTracing
 */
class OnEnabledTracingCondition extends SpringBootCondition {

    private static final String GLOBAL_PROPERTY = "management.tracing.enabled";

    private static final String EXPORTER_PROPERTY = "management.%s.tracing.export.enabled";

    @Override
    public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
        String tracingExporter = getExporterName(metadata);
        ...
      }
      
      private static String getExporterName(AnnotatedTypeMetadata metadata) {
         Map<String, Object> attributes = 
         metadata.getAnnotationAttributes(ConditionalOnEnabledTracing.class.getName());
         if (attributes == null) {
             return null;
         }
         return (String) attributes.get("value");
      }

I am lost here. In debug I see that tracingExporter is empty string

How can I override it? is it possible to provide configuration via application.properties ?

Share Improve this question asked Mar 6 at 15:16 gstackoverflowgstackoverflow 36.6k138 gold badges419 silver badges785 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It was enough just to register bean:

    @Bean
    fun mySpanExporter(): MySpanExporter {
        return MySpanExporter()
    }

in the class marked with: @Configuration

All other magic was done by springboot

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744966943a4603738.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信