Search in sources :

Example 1 with ScopeDecorator

use of brave.propagation.CurrentTraceContext.ScopeDecorator in project brave by openzipkin.

the class CorrelationScopeDecoratorFactoryBeanTest method configs.

@Test
public void configs() {
    context = new XmlBeans("" + "<util:constant id=\"traceId\" static-field=\"brave.baggage.BaggageFields.TRACE_ID\"/>\n" + "<bean id=\"correlationDecorator\" class=\"brave.spring.beans.CorrelationScopeDecoratorFactoryBean\">\n" + "  <property name=\"builder\">\n" + "    <bean class=\"brave.context.log4j12.MDCScopeDecorator\" factory-method=\"newBuilder\"/>\n" + "  </property>\n" + "  <property name=\"configs\">\n" + "    <list>\n" + "      <bean class=\"brave.spring.beans.SingleCorrelationFieldFactoryBean\">\n" + "        <property name=\"baggageField\" ref=\"traceId\"/>\n" + "        <property name=\"name\" value=\"X-B3-TraceId\"/>\n" + "      </bean>\n" + "    </list>\n" + "  </property>\n" + "</bean>");
    ScopeDecorator decorator = context.getBean("correlationDecorator", ScopeDecorator.class);
    assertThat(decorator).extracting("field").usingRecursiveComparison().isEqualTo(SingleCorrelationField.newBuilder(TRACE_ID).name("X-B3-TraceId").build());
}
Also used : CorrelationScopeDecorator(brave.baggage.CorrelationScopeDecorator) ScopeDecorator(brave.propagation.CurrentTraceContext.ScopeDecorator) Test(org.junit.Test)

Example 2 with ScopeDecorator

use of brave.propagation.CurrentTraceContext.ScopeDecorator in project brave by openzipkin.

the class CorrelationScopeDecoratorTest method decoratesNoop_unconfiguredFields.

/**
 * When a context is in an unexpected state, save off fields and revert.
 */
@Test
public void decoratesNoop_unconfiguredFields() {
    for (ScopeDecorator decorator : asList(withBaggageFieldsDecorator, onlyScopeDecorator)) {
        map.put(FIELD.name(), "romeo");
        map.put(FIELD_2.name(), "FO");
        map.put(LOCAL_FIELD.name(), "abcd");
        try (Scope scope = decorator.decorateScope(context, Scope.NOOP)) {
            assertThat(scope).isNotSameAs(Scope.NOOP);
        }
    }
    map.clear();
}
Also used : Scope(brave.propagation.CurrentTraceContext.Scope) ScopeDecorator(brave.propagation.CurrentTraceContext.ScopeDecorator) Test(org.junit.Test)

Example 3 with ScopeDecorator

use of brave.propagation.CurrentTraceContext.ScopeDecorator in project brave by openzipkin.

the class CurrentTraceContextTest method ignoresNoopScopeDecorator.

@Test
public void ignoresNoopScopeDecorator() {
    ScopeDecorator one = (context, scope) -> scope;
    CurrentTraceContext shouldHaveOnlyOne = newBuilder().addScopeDecorator(ScopeDecorator.NOOP).addScopeDecorator(one).build();
    assertThat(shouldHaveOnlyOne).extracting("scopeDecorators").asInstanceOf(InstanceOfAssertFactories.ARRAY).doesNotContain(ScopeDecorator.NOOP);
}
Also used : SingleBaggageField(brave.baggage.BaggagePropagationConfig.SingleBaggageField) ClassLoaders.newInstance(brave.test.util.ClassLoaders.newInstance) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Callable(java.util.concurrent.Callable) CurrentTraceContext(brave.propagation.CurrentTraceContext) Nullable(brave.internal.Nullable) Supplier(java.util.function.Supplier) B3Propagation(brave.propagation.B3Propagation) ScopeDecorator(brave.propagation.CurrentTraceContext.ScopeDecorator) Propagation(brave.propagation.Propagation) ExecutorService(java.util.concurrent.ExecutorService) SingleCorrelationField(brave.baggage.CorrelationScopeConfig.SingleCorrelationField) ClassLoaders(brave.test.util.ClassLoaders) ClassLoaders.assertRunIsUnloadableWithSupplier(brave.test.util.ClassLoaders.assertRunIsUnloadableWithSupplier) Test(org.junit.Test) TraceContext(brave.propagation.TraceContext) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) BaggagePropagation(brave.baggage.BaggagePropagation) BaggageField(brave.baggage.BaggageField) Scope(brave.propagation.CurrentTraceContext.Scope) Assertions.failBecauseExceptionWasNotThrown(org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown) ScopeDecorator(brave.propagation.CurrentTraceContext.ScopeDecorator) CurrentTraceContext(brave.propagation.CurrentTraceContext) Test(org.junit.Test)

Aggregations

ScopeDecorator (brave.propagation.CurrentTraceContext.ScopeDecorator)3 Test (org.junit.Test)3 Scope (brave.propagation.CurrentTraceContext.Scope)2 BaggageField (brave.baggage.BaggageField)1 BaggagePropagation (brave.baggage.BaggagePropagation)1 SingleBaggageField (brave.baggage.BaggagePropagationConfig.SingleBaggageField)1 SingleCorrelationField (brave.baggage.CorrelationScopeConfig.SingleCorrelationField)1 CorrelationScopeDecorator (brave.baggage.CorrelationScopeDecorator)1 Nullable (brave.internal.Nullable)1 B3Propagation (brave.propagation.B3Propagation)1 CurrentTraceContext (brave.propagation.CurrentTraceContext)1 Propagation (brave.propagation.Propagation)1 TraceContext (brave.propagation.TraceContext)1 ClassLoaders (brave.test.util.ClassLoaders)1 ClassLoaders.assertRunIsUnloadableWithSupplier (brave.test.util.ClassLoaders.assertRunIsUnloadableWithSupplier)1 ClassLoaders.newInstance (brave.test.util.ClassLoaders.newInstance)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1