brave.kafka.clients.KafkaTracing Java Examples
The following examples show how to use
brave.kafka.clients.KafkaTracing.
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: ITKafkaStreamsTracing.java From brave with Apache License 2.0 | 5 votes |
Consumer<String, String> createTracingConsumer(String... topics) { if (topics.length == 0) { topics = new String[] {testName.getMethodName()}; } KafkaConsumer<String, String> consumer = kafka.helper().createStringConsumer(); List<TopicPartition> assignments = new ArrayList<>(); for (String topic : topics) { assignments.add(new TopicPartition(topic, 0)); } consumer.assign(assignments); return KafkaTracing.create(tracing).consumer(consumer); }
Example #2
Source File: HelloConsumer.java From talk-kafka-zipkin with MIT License | 5 votes |
public static void main(String[] args) { final var config = ConfigFactory.load(); /* START TRACING INSTRUMENTATION */ final var sender = URLConnectionSender.newBuilder() .endpoint(config.getString("zipkin.endpoint")).build(); final var reporter = AsyncReporter.builder(sender).build(); final var tracing = Tracing.newBuilder().localServiceName("hello-consumer") .sampler(Sampler.ALWAYS_SAMPLE).spanReporter(reporter).build(); final var kafkaTracing = KafkaTracing.newBuilder(tracing) .remoteServiceName("kafka").build(); /* END TRACING INSTRUMENTATION */ final var consumerConfigs = new Properties(); consumerConfigs.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, config.getString("kafka.bootstrap-servers")); consumerConfigs.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); consumerConfigs.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); consumerConfigs.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "hello-consumer"); consumerConfigs.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, OffsetResetStrategy.EARLIEST.name().toLowerCase()); final var kafkaConsumer = new KafkaConsumer<String, String>(consumerConfigs); final var tracingConsumer = kafkaTracing.consumer(kafkaConsumer); tracingConsumer.subscribe(Collections.singletonList("hello")); while (!Thread.interrupted()) { var records = tracingConsumer.poll(Duration.ofMillis(Long.MAX_VALUE)); for (var record : records) { brave.Span span = kafkaTracing.nextSpan(record).name("print-hello") .start(); span.annotate("starting printing"); out.println(String.format("Record: %s", record)); span.annotate("printing finished"); span.finish(); } } }
Example #3
Source File: TraceMessagingAutoConfiguration.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean KafkaTracing kafkaTracing(MessagingTracing messagingTracing, SleuthMessagingProperties properties) { return KafkaTracing.newBuilder(messagingTracing) .remoteServiceName( properties.getMessaging().getKafka().getRemoteServiceName()) .build(); }
Example #4
Source File: TraceMessagingAutoConfiguration1664Tests.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
MySleuthKafka1664Aspect(KafkaTracing kafkaTracing, Tracer tracer) { super(kafkaTracing, tracer); }
Example #5
Source File: TracingKafkaClientSupplier.java From brave with Apache License 2.0 | 4 votes |
TracingKafkaClientSupplier(KafkaTracing kafkaTracing) { this.kafkaTracing = kafkaTracing; }
Example #6
Source File: KafkaStreamsTracing.java From brave with Apache License 2.0 | 4 votes |
Builder(KafkaTracing kafkaTracing) { if (kafkaTracing == null) throw new NullPointerException("kafkaTracing == null"); this.kafkaTracing = kafkaTracing; }
Example #7
Source File: KafkaStreamsTracing.java From brave with Apache License 2.0 | 4 votes |
/** @since 5.10 */ public static Builder newBuilder(MessagingTracing messagingTracing) { return new Builder(KafkaTracing.create(messagingTracing)); }
Example #8
Source File: KafkaStreamsTracing.java From brave with Apache License 2.0 | 4 votes |
/** @since 5.10 */ public static Builder newBuilder(Tracing tracing) { return new Builder(KafkaTracing.create(tracing)); }
Example #9
Source File: KafkaStreamsTracing.java From brave with Apache License 2.0 | 4 votes |
/** @since 5.9 */ public static KafkaStreamsTracing create(KafkaTracing kafkaTracing) { return new Builder(kafkaTracing).build(); }
Example #10
Source File: KafkaStreamsTracing.java From brave with Apache License 2.0 | 4 votes |
/** @since 5.10 */ public static KafkaStreamsTracing create(MessagingTracing messagingTracing) { return new Builder(KafkaTracing.create(messagingTracing)).build(); }
Example #11
Source File: KafkaStreamsTracing.java From brave with Apache License 2.0 | 4 votes |
public static KafkaStreamsTracing create(Tracing tracing) { return create(KafkaTracing.create(tracing)); }
Example #12
Source File: TraceMessagingAutoConfigurationTests.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
MySleuthKafkaAspect(KafkaTracing kafkaTracing, Tracer tracer) { super(kafkaTracing, tracer); }
Example #13
Source File: TraceMessagingAutoConfigurationTests.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
@Bean SleuthKafkaAspect sleuthKafkaAspect(KafkaTracing kafkaTracing, Tracer tracer) { return new MySleuthKafkaAspect(kafkaTracing, tracer); }
Example #14
Source File: TraceMessagingAutoConfiguration1664Tests.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
@Bean SleuthKafkaAspect sleuthKafkaAspect(KafkaTracing kafkaTracing, Tracer tracer) { return new MySleuthKafka1664Aspect(kafkaTracing, tracer); }
Example #15
Source File: TraceMessagingAutoConfiguration.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
MessageListenerMethodInterceptor(KafkaTracing kafkaTracing, Tracer tracer) { this.kafkaTracing = kafkaTracing; this.tracer = tracer; }
Example #16
Source File: TraceMessagingAutoConfiguration.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
SleuthKafkaAspect(KafkaTracing kafkaTracing, Tracer tracer) { this.kafkaTracing = kafkaTracing; this.tracer = tracer; this.recordMessageConverter = ReflectionUtils.findField( MessagingMessageListenerAdapter.class, "recordMessageConverter"); }
Example #17
Source File: TraceMessagingAutoConfiguration.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
@Bean // for tests @ConditionalOnMissingBean SleuthKafkaAspect sleuthKafkaAspect(KafkaTracing kafkaTracing, Tracer tracer) { return new SleuthKafkaAspect(kafkaTracing, tracer); }
Example #18
Source File: TwitterConsoleConsumer.java From talk-kafka-zipkin with MIT License | 4 votes |
public static void main(String[] args) { final var config = ConfigFactory.load(); final var kafkaBootstrapServers = config.getString("kafka.bootstrap-servers"); final var schemaRegistryUrl = config.getString("schema-registry.url"); /* START TRACING INSTRUMENTATION */ final var sender = URLConnectionSender.newBuilder() .endpoint(config.getString("zipkin.endpoint")).build(); final var reporter = AsyncReporter.builder(sender).build(); final var tracing = Tracing.newBuilder() .localServiceName("twitter-console-consumer") .sampler(Sampler.ALWAYS_SAMPLE).spanReporter(reporter).build(); final var kafkaTracing = KafkaTracing.newBuilder(tracing) .remoteServiceName("kafka").build(); /* END TRACING INSTRUMENTATION */ final var consumerConfigs = new Properties(); consumerConfigs.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaBootstrapServers); consumerConfigs.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); consumerConfigs.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, SpecificAvroDeserializer.class.getName()); consumerConfigs.put(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, schemaRegistryUrl); consumerConfigs.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "twitter-console"); final var kafkaConsumer = new KafkaConsumer<String, Tweet>(consumerConfigs); final var tracingConsumer = kafkaTracing.consumer(kafkaConsumer); tracingConsumer.subscribe( Collections.singletonList(config.getString("topics.input-tweets"))); while (!Thread.interrupted()) { final var records = tracingConsumer.poll(Duration.ofMillis(Long.MAX_VALUE)); for (var record : records) { var span = kafkaTracing.nextSpan(record).name("print-hello").start(); try (var ignored = tracing.tracer().withSpanInScope(span)) { span.annotate("starting printing"); out.println(String.format("Record: %s", record)); span.annotate("printing finished"); } catch (RuntimeException | Error e) { span.error(e); throw e; } finally { span.finish(); } } } }
Example #19
Source File: BraveKafkaProducerTracingInstrumentation.java From micronaut-kafka with Apache License 2.0 | 2 votes |
/** * Default constructor. * @param kafkaTracing The kafka tracing */ public BraveKafkaProducerTracingInstrumentation(KafkaTracing kafkaTracing) { this.kafkaTracing = kafkaTracing; }
Example #20
Source File: BraveKafkaConsumerTracingInstrumentation.java From micronaut-kafka with Apache License 2.0 | 2 votes |
/** * Default constructor. * @param kafkaTracing The kafka tracing */ public BraveKafkaConsumerTracingInstrumentation(KafkaTracing kafkaTracing) { this.kafkaTracing = kafkaTracing; }
Example #21
Source File: BraveKafkaTracingFactory.java From micronaut-kafka with Apache License 2.0 | 2 votes |
/** * Creates a default {@link KafkaTracing} using {@link MessagingTracing} or {@link Tracing}. * * @param tracing The {@link Tracing} * @param messagingTracing The {@link MessagingTracing} if exists * @return a new instance of {@link KafkaTracing} */ @Requires(missingBeans = KafkaTracing.class) @Singleton KafkaTracing kafkaTracing(Tracing tracing, @Nullable MessagingTracing messagingTracing) { return messagingTracing == null ? KafkaTracing.create(tracing) : KafkaTracing.create(messagingTracing); }