TracingHelper { public static void logError(final Span span, final Throwable error) { if (span != null) { logError(span, getErrorLogItems(error)); } } private  TracingHelper(); static void setDeviceTags(final Span span, final String tenantId, final String deviceId); static void setDeviceTags(final Span span, final String tenantId, final String deviceId, final String authId); static void logError(final Span span, final Throwable error); static Map<String, Object> getErrorLogItems(final Throwable error); static void logError(final Span span, final String message); static void logError(final Span span, final String message, final Throwable error); static void logError(final Span span, final Map<String, ?> items); static void injectSpanContext(final Tracer tracer, final SpanContext spanContext, final JsonObject jsonObject); static SpanContext extractSpanContext(final Tracer tracer, final JsonObject jsonObject); static void injectSpanContext(final Tracer tracer, final SpanContext spanContext, final Message message); static SpanContext extractSpanContext(final Tracer tracer, final Message message); static void injectSpanContext(final Tracer tracer, final SpanContext spanContext, final DeliveryOptions deliveryOptions); static SpanContext extractSpanContext(final Tracer tracer, final MultiMap headers); static void injectSpanContext(final Tracer tracer, final SpanContext spanContext,
            final BiConsumer<String, String> keyValueConsumer); static SpanContext extractSpanContext(final Tracer tracer,
            final Supplier<Iterator<Map.Entry<String, String>>> keyValueIteratorSupplier); static Tracer.SpanBuilder buildChildSpan(final Tracer tracer, final SpanContext spanContext,
            final String operationName, final String component); static Tracer.SpanBuilder buildServerChildSpan(final Tracer tracer, final SpanContext spanContext,
            final String operationName, final String component); static Tracer.SpanBuilder buildFollowsFromSpan(final Tracer tracer, final SpanContext spanContext,
            final String operationName); static Tracer.SpanBuilder buildSpan(final Tracer tracer, final SpanContext spanContext,
            final String operationName, final String referenceType); static void setTraceSamplingPriority(final Span span, final int samplingPriority); static void adoptSamplingPriorityFromContext(final SpanContext spanContext, final Tracer.SpanBuilder spanBuilder); static final BooleanTag TAG_AUTHENTICATED; static final StringTag TAG_AUTH_ID; static final BooleanTag TAG_CACHE_HIT; static final StringTag TAG_CLIENT_ID; static final StringTag TAG_CORRELATION_ID; static final StringTag TAG_CREDENTIALS_TYPE; static final IntTag TAG_CREDIT; static final StringTag TAG_DEVICE_ID; static final StringTag TAG_GATEWAY_ID; static final StringTag TAG_MESSAGE_ID; static final StringTag TAG_PEER_CONTAINER; static final StringTag TAG_QOS; static final StringTag TAG_REMOTE_STATE; static final StringTag TAG_TENANT_ID; static final BooleanTag TAG_TLS; }
@SuppressWarnings("unchecked") @Test public void testLogErrorWithMessage() { final Span span = mock(Span.class); final String errorMessage = "my error message"; TracingHelper.logError(span, errorMessage); final ArgumentCaptor<Map<String, ?>> itemsCaptor = ArgumentCaptor.forClass(Map.class); verify(span).log(itemsCaptor.capture()); final Map<?, ?> capturedItemsMap = itemsCaptor.getValue(); assertThat(capturedItemsMap).isNotNull(); assertThat(capturedItemsMap).hasSize(2); assertThat(capturedItemsMap.get(Fields.MESSAGE)).isEqualTo(errorMessage); assertThat(capturedItemsMap.get(Fields.EVENT)).isEqualTo(Tags.ERROR.getKey()); }
@SuppressWarnings("unchecked") @Test public void testLogErrorWithSingletonMap() { final Span span = mock(Span.class); final String errorMessage = "my error message"; TracingHelper.logError(span, Collections.singletonMap(Fields.MESSAGE, errorMessage)); final ArgumentCaptor<Map<String, ?>> itemsCaptor = ArgumentCaptor.forClass(Map.class); verify(span).log(itemsCaptor.capture()); final Map<?, ?> capturedItemsMap = itemsCaptor.getValue(); assertThat(capturedItemsMap).isNotNull(); assertThat(capturedItemsMap).hasSize(2); assertThat(capturedItemsMap.get(Fields.MESSAGE)).isEqualTo(errorMessage); assertThat(capturedItemsMap.get(Fields.EVENT)).isEqualTo(Tags.ERROR.getKey()); }
@SuppressWarnings("unchecked") @Test public void testLogErrorWithException() { final Span span = mock(Span.class); final Exception exception = new Exception("my error message"); TracingHelper.logError(span, exception); final ArgumentCaptor<Map<String, ?>> itemsCaptor = ArgumentCaptor.forClass(Map.class); verify(span).log(itemsCaptor.capture()); final Map<?, ?> capturedItemsMap = itemsCaptor.getValue(); assertThat(capturedItemsMap).isNotNull(); assertThat(capturedItemsMap).hasSize(2); assertThat(capturedItemsMap.get(Fields.ERROR_OBJECT)).isEqualTo(exception); assertThat(capturedItemsMap.get(Fields.EVENT)).isEqualTo(Tags.ERROR.getKey()); }