All Downloads are FREE. Search and download functionalities are using the official Maven repository.

brave.spring.beans.CurrentTraceContextFactoryBean Maven / Gradle / Ivy

/*
 * Copyright 2013-2020 The OpenZipkin Authors
 *
 * 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 brave.spring.beans;

import brave.propagation.CurrentTraceContext;
import brave.propagation.CurrentTraceContext.ScopeDecorator;
import brave.propagation.CurrentTraceContextCustomizer;
import brave.propagation.ThreadLocalCurrentTraceContext;
import java.util.List;
import org.springframework.beans.factory.FactoryBean;

/** Spring XML config does not support chained builders. This converts accordingly */
public class CurrentTraceContextFactoryBean implements FactoryBean {
  List customizers;
  List scopeDecorators;

  @Override public CurrentTraceContext getObject() {
    CurrentTraceContext.Builder builder = ThreadLocalCurrentTraceContext.newBuilder();
    if (scopeDecorators != null) {
      for (ScopeDecorator scopeDecorator : scopeDecorators) {
        builder.addScopeDecorator(scopeDecorator);
      }
    }
    if (customizers != null) {
      for (CurrentTraceContextCustomizer customizer : customizers) customizer.customize(builder);
    }
    return builder.build();
  }

  @Override public Class getObjectType() {
    return CurrentTraceContext.class;
  }

  @Override public boolean isSingleton() {
    return true;
  }

  public void setScopeDecorators(List scopeDecorators) {
    this.scopeDecorators = scopeDecorators;
  }

  public void setCustomizers(List customizers) {
    this.customizers = customizers;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy