Use tags instead of meta

which includes baggage.
This commit is contained in:
Tyler Benson 2020-03-19 17:48:45 -07:00
parent 329e79b801
commit f0eb73ef12
6 changed files with 30 additions and 23 deletions

View File

@ -51,7 +51,7 @@ public class TraceProcessor {
public interface Rule { public interface Rule {
String[] aliases(); String[] aliases();
void processSpan(DDSpan span, Map<String, String> meta, Collection<DDSpan> trace); void processSpan(DDSpan span, Map<String, Object> tags, Collection<DDSpan> trace);
} }
public List<DDSpan> onTraceComplete(final List<DDSpan> trace) { public List<DDSpan> onTraceComplete(final List<DDSpan> trace) {
@ -64,9 +64,9 @@ public class TraceProcessor {
} }
private void applyRules(final Collection<DDSpan> trace, final DDSpan span) { private void applyRules(final Collection<DDSpan> trace, final DDSpan span) {
final Map<String, String> meta = span.getMeta(); final Map<String, Object> tags = span.getTags();
for (final Rule rule : rules) { for (final Rule rule : rules) {
rule.processSpan(span, meta, trace); rule.processSpan(span, tags, trace);
} }
} }
} }

View File

@ -15,9 +15,14 @@ public class ErrorRule implements TraceProcessor.Rule {
@Override @Override
public void processSpan( public void processSpan(
final DDSpan span, final Map<String, String> meta, final Collection<DDSpan> trace) { final DDSpan span, final Map<String, Object> tags, final Collection<DDSpan> trace) {
if (meta.containsKey(Tags.ERROR.getKey())) { if (tags.containsKey(Tags.ERROR.getKey())) {
span.setError(Boolean.parseBoolean(meta.get(Tags.ERROR.getKey()))); final Object value = tags.get(Tags.ERROR.getKey());
if (value instanceof Boolean) {
span.setError((Boolean) value);
} else {
span.setError(Boolean.parseBoolean(value.toString()));
}
span.setTag(Tags.ERROR, null); // Remove the tag span.setTag(Tags.ERROR, null); // Remove the tag
} }
} }

View File

@ -15,9 +15,9 @@ public class SpanTypeRule implements TraceProcessor.Rule {
@Override @Override
public void processSpan( public void processSpan(
final DDSpan span, final Map<String, String> meta, final Collection<DDSpan> trace) { final DDSpan span, final Map<String, Object> tags, final Collection<DDSpan> trace) {
if (meta.containsKey(DDTags.SPAN_TYPE)) { if (tags.containsKey(DDTags.SPAN_TYPE)) {
span.setSpanType(meta.get(DDTags.SPAN_TYPE)); span.setSpanType(tags.get(DDTags.SPAN_TYPE).toString());
span.setTag(DDTags.SPAN_TYPE, (String) null); // Remove the tag span.setTag(DDTags.SPAN_TYPE, (String) null); // Remove the tag
} }
} }

View File

@ -15,8 +15,8 @@ public class Status404Rule implements TraceProcessor.Rule {
@Override @Override
public void processSpan( public void processSpan(
final DDSpan span, final Map<String, String> meta, final Collection<DDSpan> trace) { final DDSpan span, final Map<String, Object> tags, final Collection<DDSpan> trace) {
if (!span.context().isResourceNameSet() && "404".equals(meta.get(Tags.HTTP_STATUS.getKey()))) { if (!span.context().isResourceNameSet() && "404".equals(tags.get(Tags.HTTP_STATUS.getKey()))) {
span.setResourceName("404"); span.setResourceName("404");
} }
} }

View File

@ -15,9 +15,11 @@ public class Status5XXRule implements TraceProcessor.Rule {
@Override @Override
public void processSpan( public void processSpan(
final DDSpan span, final Map<String, String> meta, final Collection<DDSpan> trace) { final DDSpan span, final Map<String, Object> tags, final Collection<DDSpan> trace) {
if (!span.context().getErrorFlag() && meta.containsKey(Tags.HTTP_STATUS.getKey())) { if (!span.context().getErrorFlag() && tags.containsKey(Tags.HTTP_STATUS.getKey())) {
final int responseCode = Integer.parseInt(meta.get(Tags.HTTP_STATUS.getKey())); final Object value = tags.get(Tags.HTTP_STATUS.getKey());
final int responseCode =
value instanceof Integer ? (int) value : Integer.parseInt(value.toString());
span.setError(500 <= responseCode && responseCode < 600); span.setError(500 <= responseCode && responseCode < 600);
} }
} }

View File

@ -21,17 +21,17 @@ public class URLAsResourceNameRule implements TraceProcessor.Rule {
@Override @Override
public void processSpan( public void processSpan(
final DDSpan span, final Map<String, String> meta, final Collection<DDSpan> trace) { final DDSpan span, final Map<String, Object> tags, final Collection<DDSpan> trace) {
final DDSpanContext context = span.context(); final DDSpanContext context = span.context();
if (context.isResourceNameSet() if (context.isResourceNameSet()
|| meta.get(Tags.HTTP_URL.getKey()) == null || tags.get(Tags.HTTP_URL.getKey()) == null
|| "404".equals(meta.get(Tags.HTTP_STATUS.getKey()))) { || "404".equals(tags.get(Tags.HTTP_STATUS.getKey()))) {
return; return;
} }
final String rawPath = rawPathFromUrlString(meta.get(Tags.HTTP_URL.getKey()).trim()); final String rawPath = rawPathFromUrlString(tags.get(Tags.HTTP_URL.getKey()).toString().trim());
final String normalizedPath = normalizePath(rawPath); final String normalizedPath = normalizePath(rawPath);
final String resourceName = addMethodIfAvailable(meta, normalizedPath); final String resourceName = addMethodIfAvailable(tags, normalizedPath);
context.setResourceName(resourceName); context.setResourceName(resourceName);
} }
@ -87,11 +87,11 @@ public class URLAsResourceNameRule implements TraceProcessor.Rule {
return PATH_MIXED_ALPHANUMERICS.matcher(path).replaceAll("?"); return PATH_MIXED_ALPHANUMERICS.matcher(path).replaceAll("?");
} }
private String addMethodIfAvailable(final Map<String, String> meta, String path) { private String addMethodIfAvailable(final Map<String, Object> meta, String path) {
// if the verb (GET, POST ...) is present, add it // if the verb (GET, POST ...) is present, add it
final String verb = meta.get(Tags.HTTP_METHOD.getKey()); final Object verb = meta.get(Tags.HTTP_METHOD.getKey());
if (verb != null && !verb.isEmpty()) { if (verb != null && !verb.toString().isEmpty()) {
path = verb.toUpperCase() + " " + path; path = verb.toString().toUpperCase() + " " + path;
} }
return path; return path;
} }