Interceptor keeps sending errors even setting them to false.
Tracer Version(s)
1.48.1
Java Version(s)
11.0.26
JVM Vendor
Oracle JDK
Bug Report
I would like to ignore certain exceptions thrown by my application so they do not appear in 'Error Tracking'. Despite setting the Span error to false in TraceInterceptor, it continues to send them as errors to Datadog.
My class looks like this right now:
public class CustomTraceInterceptor implements TraceInterceptor {
@Override
public Collection<? extends MutableSpan> onTraceComplete(Collection<? extends MutableSpan> collection) {
for (MutableSpan span : collection) {
if (span.getTag("http.route").toString().contains("health-check")) {
continue;
}
Throwable throwable = (Throwable) span.getTag("error.type");
if (throwable instanceof NotFoundException) {
span.setError(false);
span.setTag(DDTags.ERROR_MSG, "");
span.setTag(DDTags.ERROR_TYPE, "");
span.setTag(DDTags.ERROR_STACK, "");
span.setTag("error.object", "");
}
}
return collection;
}
@Override
public int priority() {
return 0;
}
}
Obs: the issue is not related to the if condition, I tried to intercept every exception and it still sending it as errors.
Expected Behavior
Exceptions set to false should not appear in Datadog Error Tracking.
Reproduction Code
No response
I believe getTag("error.type") returns a String not a Throwable instance. It should contain the name of the exception type. So the cast to Throwable there is likely raising a ClassCastException and exiting before if the statement.
I've tried removing the if statement before to see if thats the problem, and the code looked like this:
public class CustomTraceInterceptor implements TraceInterceptor {
@Override
public Collection<? extends MutableSpan> onTraceComplete(Collection<? extends MutableSpan> collection) {
for (MutableSpan span : collection) {
if (span.getTag("http.route").toString().contains("health-check")) {
continue;
}
span.setError(false);
span.setTag(DDTags.ERROR_MSG, "");
span.setTag(DDTags.ERROR_TYPE, "");
span.setTag(DDTags.ERROR_STACK, "");
span.setTag("error.object", "");
}
return collection;
}
@Override
public int priority() {
return 0;
}
}
However, it still kept sending errors.
Hi @ArtuoS, TraceInterceptor#priority() needs to return a value that is not used by other interceptors. Can you try setting your priority to something like 100? You can find the priorities of standard interceptors here
Hi @ArtuoS,
TraceInterceptor#priority()needs to return a value that is not used by other interceptors. Can you try setting your priority to something like 100? You can find the priorities of standard interceptors here
Hey, I tried some priority values:
@Override
public int priority() {
return Integer.MAX_VALUE - 546;
}
Even though, it didn't work.
@ArtuoS Did you solved the issue?
I want to do something similar.
I´ve got a working solution but now for some reason the metrics are no longer sent to datadog
I´ve got a working solution but now for some reason the metrics are no longer sent to datadog
Can you share your working solution? I'll be really thankful.
@ArtuoS Sorry for the late response. I did as shown here:
https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/java/dd-api/#extending-tracers
@ArtuoS Sorry for the late response. I did as shown here:
https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/java/dd-api/#extending-tracers
Thank you, I'll give it a try.
Hey, is there an official or working solution to achieve this? (@ArtuoS )