parent
329e79b801
commit
f0eb73ef12
|
@ -51,7 +51,7 @@ public class TraceProcessor {
|
|||
public interface Rule {
|
||||
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) {
|
||||
|
@ -64,9 +64,9 @@ public class TraceProcessor {
|
|||
}
|
||||
|
||||
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) {
|
||||
rule.processSpan(span, meta, trace);
|
||||
rule.processSpan(span, tags, trace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,14 @@ public class ErrorRule implements TraceProcessor.Rule {
|
|||
|
||||
@Override
|
||||
public void processSpan(
|
||||
final DDSpan span, final Map<String, String> meta, final Collection<DDSpan> trace) {
|
||||
if (meta.containsKey(Tags.ERROR.getKey())) {
|
||||
span.setError(Boolean.parseBoolean(meta.get(Tags.ERROR.getKey())));
|
||||
final DDSpan span, final Map<String, Object> tags, final Collection<DDSpan> trace) {
|
||||
if (tags.containsKey(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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,9 @@ public class SpanTypeRule implements TraceProcessor.Rule {
|
|||
|
||||
@Override
|
||||
public void processSpan(
|
||||
final DDSpan span, final Map<String, String> meta, final Collection<DDSpan> trace) {
|
||||
if (meta.containsKey(DDTags.SPAN_TYPE)) {
|
||||
span.setSpanType(meta.get(DDTags.SPAN_TYPE));
|
||||
final DDSpan span, final Map<String, Object> tags, final Collection<DDSpan> trace) {
|
||||
if (tags.containsKey(DDTags.SPAN_TYPE)) {
|
||||
span.setSpanType(tags.get(DDTags.SPAN_TYPE).toString());
|
||||
span.setTag(DDTags.SPAN_TYPE, (String) null); // Remove the tag
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ public class Status404Rule implements TraceProcessor.Rule {
|
|||
|
||||
@Override
|
||||
public void processSpan(
|
||||
final DDSpan span, final Map<String, String> meta, final Collection<DDSpan> trace) {
|
||||
if (!span.context().isResourceNameSet() && "404".equals(meta.get(Tags.HTTP_STATUS.getKey()))) {
|
||||
final DDSpan span, final Map<String, Object> tags, final Collection<DDSpan> trace) {
|
||||
if (!span.context().isResourceNameSet() && "404".equals(tags.get(Tags.HTTP_STATUS.getKey()))) {
|
||||
span.setResourceName("404");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,11 @@ public class Status5XXRule implements TraceProcessor.Rule {
|
|||
|
||||
@Override
|
||||
public void processSpan(
|
||||
final DDSpan span, final Map<String, String> meta, final Collection<DDSpan> trace) {
|
||||
if (!span.context().getErrorFlag() && meta.containsKey(Tags.HTTP_STATUS.getKey())) {
|
||||
final int responseCode = Integer.parseInt(meta.get(Tags.HTTP_STATUS.getKey()));
|
||||
final DDSpan span, final Map<String, Object> tags, final Collection<DDSpan> trace) {
|
||||
if (!span.context().getErrorFlag() && tags.containsKey(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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,17 +21,17 @@ public class URLAsResourceNameRule implements TraceProcessor.Rule {
|
|||
|
||||
@Override
|
||||
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();
|
||||
if (context.isResourceNameSet()
|
||||
|| meta.get(Tags.HTTP_URL.getKey()) == null
|
||||
|| "404".equals(meta.get(Tags.HTTP_STATUS.getKey()))) {
|
||||
|| tags.get(Tags.HTTP_URL.getKey()) == null
|
||||
|| "404".equals(tags.get(Tags.HTTP_STATUS.getKey()))) {
|
||||
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 resourceName = addMethodIfAvailable(meta, normalizedPath);
|
||||
final String resourceName = addMethodIfAvailable(tags, normalizedPath);
|
||||
|
||||
context.setResourceName(resourceName);
|
||||
}
|
||||
|
@ -87,11 +87,11 @@ public class URLAsResourceNameRule implements TraceProcessor.Rule {
|
|||
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
|
||||
final String verb = meta.get(Tags.HTTP_METHOD.getKey());
|
||||
if (verb != null && !verb.isEmpty()) {
|
||||
path = verb.toUpperCase() + " " + path;
|
||||
final Object verb = meta.get(Tags.HTTP_METHOD.getKey());
|
||||
if (verb != null && !verb.toString().isEmpty()) {
|
||||
path = verb.toString().toUpperCase() + " " + path;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue