Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SpanFactory autoconfiguration mechanism. #2354

Merged
merged 5 commits into from Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -60,7 +60,8 @@ public SpanFactory spanFactory() {
@Bean
public HandlerEnhancerDefinition tracingHandlerEnhancerDefinition(SpanFactory spanFactory,
TracingProperties properties) {
return TracingHandlerEnhancerDefinition.builder().spanFactory(spanFactory)
return TracingHandlerEnhancerDefinition.builder()
.spanFactory(spanFactory)
.showEventSourcingHandlers(properties.isShowEventSourcingHandlers())
.build();
}
Expand Down
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2010-2022. Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.axonframework.springboot.autoconfig;

import org.axonframework.springboot.TracingProperties;
import org.axonframework.tracing.SpanAttributesProvider;
import org.axonframework.tracing.SpanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
* Responsible for configuring all registed {@link SpanAttributesProvider} beans to the active {@link SpanFactory}
smcvb marked this conversation as resolved.
Show resolved Hide resolved
* implementation. This allows the easier to more easily configure any {@code SpanFactories}.
*
* @author Mitchell Herrijgers
* @see AxonTracingAutoConfiguration
* @since 4.6.0
*/
@Configuration
@AutoConfigureAfter({AxonTracingAutoConfiguration.class})
@EnableConfigurationProperties(TracingProperties.class)
public class AxonTracingSpanAttributeProviderAutoConfiguration {

@Autowired
public void configureSpanAttributeProviders(SpanFactory spanFactory,
List<SpanAttributesProvider> spanAttributesProviders) {
spanAttributesProviders.forEach(spanFactory::registerSpanAttributeProvider);
}
}
Expand Up @@ -16,7 +16,6 @@

package org.axonframework.springboot.autoconfig;

import org.axonframework.tracing.SpanAttributesProvider;
import org.axonframework.tracing.SpanFactory;
import org.axonframework.tracing.opentelemetry.OpenTelemetrySpanFactory;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
Expand All @@ -25,8 +24,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
* Automatically configured the {@link OpenTelemetrySpanFactory} as the method of providing tracing in Axon Framework.
* For this to take effect, the {@code axon-tracing-opentelemetry} dependency must be on the classpath.
Expand All @@ -41,9 +38,8 @@ public class OpenTelemetryAutoConfiguration {

@Bean
@ConditionalOnMissingBean(SpanFactory.class)
public SpanFactory spanFactory(List<SpanAttributesProvider> attributesProviders) {
public SpanFactory spanFactory() {
return OpenTelemetrySpanFactory.builder()
.addSpanAttributeProviders(attributesProviders)
.build();
}
}