brave.propagation.ExtraFieldPropagation Java Examples

The following examples show how to use brave.propagation.ExtraFieldPropagation. 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: ZipkinTraceFactory.java    From pampas with Apache License 2.0 6 votes vote down vote up
@Override
public Tracer getTracer() {
    Sender sender = OkHttpSender.create("http://192.168.20.131:9411/api/v2/spans");

    Reporter spanReporter = AsyncReporter.create(sender);
    // If you want to support baggage, indicate the fields you'd like to
    // whitelist, in this case "country-code" and "user-id". On the wire,
    // they will be prefixed like "baggage-country-code"
    Propagation.Factory propagationFactory = ExtraFieldPropagation.newFactoryBuilder(B3Propagation.FACTORY)
            .addPrefixedFields("baggage-", Arrays.asList("country-code", "user-id"))
            .build();
    Tracing braveTracing = Tracing.newBuilder()
            .localServiceName("gateway")
            .propagationFactory(propagationFactory)
            .spanReporter(spanReporter)
            .build();
    Tracer tracer = BraveTracer.create(braveTracing);

    return tracer;
}
 
Example #2
Source File: ExtraFieldPropagationFactoryBeanTest.java    From brave with Apache License 2.0 6 votes vote down vote up
@Test public void customizers() {
  context = new XmlBeans(""
    + "<bean id=\"propagationFactory\" class=\"brave.spring.beans.ExtraFieldPropagationFactoryBean\">\n"
    + "  <property name=\"customizers\">\n"
    + "    <list>\n"
    + "      <util:constant static-field=\"" + getClass().getName() + ".CUSTOMIZER_ONE\"/>\n"
    + "      <util:constant static-field=\"" + getClass().getName() + ".CUSTOMIZER_TWO\"/>\n"
    + "    </list>\n"
    + "  </property>"
    + "</bean>"
  );

  context.getBean("propagationFactory", Propagation.Factory.class);

  verify(CUSTOMIZER_ONE).customize(any(ExtraFieldPropagation.FactoryBuilder.class));
  verify(CUSTOMIZER_TWO).customize(any(ExtraFieldPropagation.FactoryBuilder.class));
}
 
Example #3
Source File: ImplementationsJFRTest.java    From java-jfr-tracer with Apache License 2.0 5 votes vote down vote up
@Test
public void brave() throws IOException {

	Factory propagationFactory = ExtraFieldPropagation.newFactoryBuilder(B3Propagation.FACTORY)
			.addPrefixedFields("baggage-", Arrays.asList("country-code", "user-id")).build();

	Tracing braveTracing = Tracing.newBuilder().localServiceName("my-service")
			.propagationFactory(propagationFactory).build();
	innerTest(BraveTracer.create(braveTracing));
}
 
Example #4
Source File: ImplementationsJFRTest.java    From java-jfr-tracer with Apache License 2.0 5 votes vote down vote up
@Test
public void brave() throws IOException {

	Factory propagationFactory = ExtraFieldPropagation.newFactoryBuilder(B3Propagation.FACTORY)
			.addPrefixedFields("baggage-", Arrays.asList("country-code", "user-id")).build();

	Tracing braveTracing = Tracing.newBuilder().localServiceName("my-service")
			.propagationFactory(propagationFactory).build();
	innerTest(BraveTracer.create(braveTracing));
}
 
Example #5
Source File: ZipkinConfig.java    From j360-boot-app-all with Apache License 2.0 5 votes vote down vote up
/** Controls aspects of tracing such as the service name that shows up in the UI */
@Bean
Tracing tracing() {
    return Tracing.newBuilder()
            .localServiceName("j360-miniprogram")
            .propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, "web"))
            .build();
}
 
Example #6
Source File: TracingConfiguration.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
/** Controls aspects of tracing such as the service name that shows up in the UI */
@Bean Tracing tracing(@Value("${spring.application.name}") String serviceName) {
  return Tracing.newBuilder()
      .localServiceName(serviceName)
      .propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, "user-name"))
      .currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
          .addScopeDecorator(MDCScopeDecorator.create()) // puts trace IDs into logs
          .build()
      )
      .spanReporter(spanReporter()).build();
}
 
Example #7
Source File: TracingConfiguration.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
/** Controls aspects of tracing such as the service name that shows up in the UI */
@Bean
Tracing tracing(@Value("${zipkin.service:brave-webmvc-example}") String serviceName) {
    return Tracing.newBuilder()
        .localServiceName(serviceName)
        .propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, "user-name"))
        .currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
            .addScopeDecorator(ThreadContextScopeDecorator.create()) // puts trace IDs into logs
            .build()
        )
        .spanReporter(spanReporter()).build();
}
 
Example #8
Source File: ZipkinTracer.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Override
public Tracer getTracer(String serviceName) {
    String hostname = configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_HOST) != null ?
            configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_HOST)
            : TracingConstants.ZIPKIN_DEFAULT_HOST;

    int port = configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_PORT) != null ?
            Integer.parseInt(configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_PORT))
            : TracingConstants.ZIPKIN_DEFAULT_PORT;

    boolean tracerLogEnabled =
            Boolean.parseBoolean(configuration.getFirstProperty(TracingConstants.CONFIG_TRACER_LOG_ENABLED) != null ?
            configuration.getFirstProperty(TracingConstants.CONFIG_TRACER_LOG_ENABLED)
            : TracingConstants.DEFAULT_TRACER_LOG_ENABLED);

    OkHttpSender sender = OkHttpSender.create("http://" + hostname + ":" + port + TracingConstants.ZIPKIN_API_CONTEXT);
    Tracer tracer = BraveTracer.create(Tracing.newBuilder()
            .localServiceName(serviceName)
            .spanReporter(AsyncReporter.builder(sender).build())
            .propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, TracingConstants.REQUEST_ID))
            .build());

    if (tracerLogEnabled) {
        Reporter reporter = new TracingReporter(LogFactory.getLog(TracingConstants.TRACER));
        Tracer tracerR = new TracerR(tracer, reporter, new ThreadLocalScopeManager());
        GlobalTracer.register(tracerR);
        return tracerR;
    } else {
        GlobalTracer.register(tracer);
        return tracer;
    }
}
 
Example #9
Source File: BaggagePropagationTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Test public void allKeyNames_extraFieldPropagation() {
  ExtraFieldPropagation.Factory factory =
    ExtraFieldPropagation.newFactory(B3SinglePropagation.FACTORY, "user-id", "session-id");

  assertThat(BaggagePropagation.allKeyNames(factory.get()))
    .containsExactly("b3", "user-id", "session-id");
}
 
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();
}