public static void addAnnotations(TraceKeys traceKeys, Message<?> message, Span span) { for (String name : traceKeys.getMessage().getHeaders()) { if (message.getHeaders().containsKey(name)) { String key = traceKeys.getMessage().getPrefix() + name.toLowerCase(); Object value = message.getHeaders().get(name); if (value == null) { value = "null"; } span.tag(key, value.toString()); // TODO: better way to serialize? } } addPayloadAnnotations(traceKeys, message.getPayload(), span); }
static void addPayloadAnnotations(TraceKeys traceKeys, Object payload, Span span) { if (payload != null) { span.tag( traceKeys.getMessage().getPayload().getType(), payload.getClass().getCanonicalName()); if (payload instanceof String) { span.tag( traceKeys.getMessage().getPayload().getSize(), String.valueOf(((String) payload).length())); } else if (payload instanceof byte[]) { span.tag( traceKeys.getMessage().getPayload().getSize(), String.valueOf(((byte[]) payload).length)); } } }