Java Code Examples for brave.propagation.Propagation#Factory

The following examples show how to use brave.propagation.Propagation#Factory . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestServer.java    From brave with Apache License 2.0 6 votes vote down vote up
TestServer(Propagation.Factory propagationFactory, ApplicationConfig application) {
  extractor = propagationFactory.get().extractor(Map::get);
  linkLocalIp = Platform.get().linkLocalIp();
  if (linkLocalIp != null) {
    // avoid dubbo's logic which might pick docker ip
    System.setProperty(CommonConstants.DUBBO_IP_TO_BIND, linkLocalIp);
    System.setProperty(Constants.DUBBO_IP_TO_REGISTRY, linkLocalIp);
  }
  service = new ServiceConfig<>();
  service.setApplication(application);
  service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
  service.setProtocol(new ProtocolConfig("dubbo", PickUnusedPort.get()));
  service.setInterface(GreeterService.class);
  service.setRef((method, parameterTypes, args) -> {
    requestQueue.add(extractor.extract(RpcContext.getContext().getAttachments()));
    return args[0];
  });
}
 
Example 2
Source File: TestServer.java    From brave with Apache License 2.0 6 votes vote down vote up
TestServer(Propagation.Factory propagationFactory) {
  extractor = propagationFactory.get().extractor(Map::get);
  linkLocalIp = Platform.get().linkLocalIp();
  if (linkLocalIp != null) {
    // avoid dubbo's logic which might pick docker ip
    System.setProperty(Constants.DUBBO_IP_TO_BIND, linkLocalIp);
    System.setProperty(Constants.DUBBO_IP_TO_REGISTRY, linkLocalIp);
  }
  service = new ServiceConfig<>();
  service.setApplication(new ApplicationConfig("bean-provider"));
  service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
  service.setProtocol(new ProtocolConfig("dubbo", PickUnusedPort.get()));
  service.setInterface(GreeterService.class);
  service.setRef((method, parameterTypes, args) -> {
    requestQueue.add(extractor.extract(RpcContext.getContext().getAttachments()));
    return args[0];
  });
}
 
Example 3
Source File: Tracer.java    From brave with Apache License 2.0 6 votes vote down vote up
Tracer(
  Clock clock,
  Propagation.Factory propagationFactory,
  SpanHandler spanHandler,
  PendingSpans pendingSpans,
  Sampler sampler,
  CurrentTraceContext currentTraceContext,
  boolean traceId128Bit,
  boolean supportsJoin,
  boolean alwaysSampleLocal,
  AtomicBoolean noop
) {
  this.clock = clock;
  this.propagationFactory = propagationFactory;
  this.spanHandler = spanHandler;
  this.pendingSpans = pendingSpans;
  this.sampler = sampler;
  this.currentTraceContext = currentTraceContext;
  this.traceId128Bit = traceId128Bit;
  this.supportsJoin = supportsJoin;
  this.alwaysSampleLocal = alwaysSampleLocal;
  this.noop = noop;
}
 
Example 4
Source File: TraceAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean
// NOTE: stable bean name as might be used outside sleuth
Tracing tracing(@LocalServiceName String serviceName, Propagation.Factory factory,
		CurrentTraceContext currentTraceContext, Sampler sampler,
		SleuthProperties sleuthProperties, @Nullable List<SpanHandler> spanHandlers,
		@Nullable List<TracingCustomizer> tracingCustomizers) {
	Tracing.Builder builder = Tracing.newBuilder().sampler(sampler)
			.localServiceName(StringUtils.isEmpty(serviceName) ? DEFAULT_SERVICE_NAME
					: serviceName)
			.propagationFactory(factory).currentTraceContext(currentTraceContext)
			.traceId128Bit(sleuthProperties.isTraceId128())
			.supportsJoin(sleuthProperties.isSupportsJoin());
	if (spanHandlers != null) {
		for (SpanHandler spanHandlerFactory : spanHandlers) {
			builder.addSpanHandler(spanHandlerFactory);
		}
	}
	if (tracingCustomizers != null) {
		for (TracingCustomizer customizer : tracingCustomizers) {
			customizer.customize(builder);
		}
	}

	return builder.build();
}
 
Example 5
Source File: BaggagePropagationFactoryBean.java    From brave with Apache License 2.0 5 votes vote down vote up
@Override public Propagation.Factory getObject() {
  BaggagePropagation.FactoryBuilder builder =
    BaggagePropagation.newFactoryBuilder(propagationFactory);
  if (configs != null) {
    builder.clear();
    for (BaggagePropagationConfig config : configs) {
      builder.add(config);
    }
  }
  if (customizers != null) {
    for (BaggagePropagationCustomizer customizer : customizers) customizer.customize(builder);
  }
  return builder.build();
}
 
Example 6
Source File: BaggagePropagationTest.java    From brave with Apache License 2.0 5 votes vote down vote up
/** Less overhead and distraction for the edge case of correlation-only. */
@Test public void extract_baggage_onlyOneExtraWhenNothingRemote() {
  Propagation.Factory factory = newFactoryBuilder(B3Propagation.FACTORY)
      .add(SingleBaggageField.local(vcapRequestId))
      .add(SingleBaggageField.local(amznTraceId)).build();
  extractor = factory.get().extractor(Map::get);

  TraceContextOrSamplingFlags extracted = extractor.extract(request);
  assertThat(extracted.extra())
      .hasSize(1)
      .noneMatch(Extra.class::isInstance);
}
 
Example 7
Source File: BaggagePropagationTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Test public void allKeyNames_baggagePropagation_noRemote() {
  Propagation.Factory factory = BaggagePropagation.newFactoryBuilder(B3SinglePropagation.FACTORY)
      .add(SingleBaggageField.local(BaggageField.create("redacted"))) // local shouldn't return
      .add(SingleBaggageField.local(BaggageField.create("user-id")))
      .add(SingleBaggageField.local(BaggageField.create("session-id"))).build();

  assertThat(BaggagePropagation.allKeyNames(factory.get()))
      .containsExactly("b3");
}
 
Example 8
Source File: CustomTraceIdPropagation.java    From brave with Apache License 2.0 5 votes vote down vote up
/**
 * @param delegate some configuration of {@link B3Propagation#newFactoryBuilder()}
 * @param customTraceIdName something not "b3"
 */
public static Propagation.Factory create(Propagation.Factory delegate, String customTraceIdName) {
  if (delegate == null) throw new NullPointerException("delegate == null");
  if (customTraceIdName == null) throw new NullPointerException("customTraceIdName == null");
  if (!delegate.create(KeyFactory.STRING).keys().contains("b3")) {
    throw new IllegalArgumentException("delegate must implement B3 propagation");
  }
  return new CustomTraceIdPropagation(delegate, customTraceIdName);
}
 
Example 9
Source File: CustomTraceIdPropagation.java    From brave with Apache License 2.0 5 votes vote down vote up
CustomTraceIdPropagation(Propagation.Factory factory, String customTraceIdName) {
  this.factory = factory;
  this.delegate = factory.get();
  this.customTraceIdName = customTraceIdName;
  //this.b3Key = keyFactory.create("b3", "X-B3-TraceId");
  List<String> allKeys = new ArrayList<>(delegate.keys());
  allKeys.add(customTraceIdName);
  this.allKeys = Collections.unmodifiableList(allKeys);
}
 
Example 10
Source File: ExtraFieldPropagationFactoryBean.java    From brave with Apache License 2.0 5 votes vote down vote up
@Override public Propagation.Factory getObject() {
  logger.warn("The factory '" + getClass().getName() + "' will be removed in a future release.\n"
      + "Use '" + BaggagePropagationFactoryBean.class.getName() + "' instead");
  ExtraFieldPropagation.FactoryBuilder builder =
      ExtraFieldPropagation.newFactoryBuilder(propagationFactory);
  if (fields != null) {
    for (String field : fields) builder.addField(field);
  }
  if (customizers != null) {
    for (ExtraFieldCustomizer customizer : customizers) customizer.customize(builder);
  }
  return builder.build();
}
 
Example 11
Source File: StackdriverTracePropagation.java    From zipkin-gcp with Apache License 2.0 4 votes vote down vote up
Factory(Propagation.Factory primary) {
  this.primary = primary;
}
 
Example 12
Source File: ReactorNettyHttpClientSpringBootTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
Propagation.Factory propagationFactory() {
	return B3SinglePropagation.FACTORY;
}
 
Example 13
Source File: ExtraFieldPropagationFactoryBean.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public Class<? extends Propagation.Factory> getObjectType() {
  return Propagation.Factory.class;
}
 
Example 14
Source File: TracingConfiguration.java    From brave-webmvc-example with MIT License 4 votes vote down vote up
/** Configures propagation for {@link #USER_NAME}, using the remote header "user_name" */
@Bean Propagation.Factory propagationFactory() {
  return BaggagePropagation.newFactoryBuilder(B3Propagation.FACTORY)
      .add(SingleBaggageField.newBuilder(USER_NAME).addKeyName("user_name").build())
      .build();
}
 
Example 15
Source File: TracingFactoryBean.java    From brave with Apache License 2.0 4 votes vote down vote up
public void setPropagationFactory(Propagation.Factory propagationFactory) {
  this.propagationFactory = propagationFactory;
}
 
Example 16
Source File: StackdriverSenderFactory.java    From micronaut-gcp with Apache License 2.0 4 votes vote down vote up
/**
 * The {@link StackdriverTracePropagation#FACTORY} as a bean.
 * @return The bean.
 */
@Singleton
@Requires(beans = StackdriverSender.class)
protected Propagation.Factory stackdriverPropagation() {
    return StackdriverTracePropagation.FACTORY;
}
 
Example 17
Source File: StackdriverTracePropagation.java    From zipkin-gcp with Apache License 2.0 4 votes vote down vote up
/**
 * @param primary typically constructed by {@link B3Propagation#newFactoryBuilder()}
 */
public static Propagation.Factory newFactory(Propagation.Factory primary) {
  if (primary == null) throw new NullPointerException("primary == null");
  return new Factory(primary);
}
 
Example 18
Source File: Tracing.java    From brave with Apache License 2.0 4 votes vote down vote up
/** @deprecated Since 5.12 use {@link #propagation()} as non-string keys are unsupported. */
@Deprecated public abstract Propagation.Factory propagationFactory();
 
Example 19
Source File: Tracing.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public Propagation.Factory propagationFactory() {
  return propagationFactory;
}
 
Example 20
Source File: ExtraFieldPropagationFactoryBean.java    From brave with Apache License 2.0 4 votes vote down vote up
public void setPropagationFactory(Propagation.Factory propagationFactory) {
  this.propagationFactory = propagationFactory;
}