@Override public Object invoke(MethodInvocation invocation) throws Throwable { if (!"onMessage".equals(invocation.getMethod().getName())) { return invocation.proceed(); } Object[] arguments = invocation.getArguments(); Optional<Object> record = Arrays.stream(arguments) .filter(o -> o instanceof ConsumerRecord).findFirst(); if (!record.isPresent()) { return invocation.proceed(); } if (log.isDebugEnabled()) { log.debug("Wrapping onMessage call"); } Span span = this.kafkaTracing.nextSpan((ConsumerRecord<?, ?>) record.get()) .name("on-message").start(); try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) { return invocation.proceed(); } catch (RuntimeException | Error e) { String message = e.getMessage(); if (message == null) message = e.getClass().getSimpleName(); span.tag("error", message); throw e; } finally { span.finish(); } }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { if (!"onMessage".equals(invocation.getMethod().getName())) { return invocation.proceed(); } Object[] arguments = invocation.getArguments(); Optional<Object> record = Arrays.stream(arguments) .filter(o -> o instanceof ConsumerRecord).findFirst(); if (!record.isPresent()) { return invocation.proceed(); } if (log.isDebugEnabled()) { log.debug("Wrapping onMessage call"); } Span span = this.kafkaTracing.nextSpan((ConsumerRecord<?, ?>) record.get()) .name("on-message").start(); try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) { return invocation.proceed(); } catch (RuntimeException | Error e) { String message = e.getMessage(); if (message == null) message = e.getClass().getSimpleName(); span.tag("error", message); throw e; } finally { span.finish(); } }
.poll(Duration.ofMillis(Long.MAX_VALUE)); for (ConsumerRecord<String, String> record : records) { brave.Span span = kafkaTracing.nextSpan(record).name("print-hello") .start(); span.annotate("starting printing");