Weld (CDI) classes are also traced

When using Java 8 + Payara (Micro) 5.191, I noticed that spans are automatically created for interceptor classes from Weld:

image

They appear when debugging too:

image

It would be cool if they could be ignored. Unfortunately they are generated classes and have the same package name as the classes that I want to trace.

Also, is it possible that the APM agent causes "this" to not be viewable in the debugger?

image

Kibana version:
7.0.0
Elasticsearch version:
7.0.0
APM Server version:
7.0.0

APM Agent language and version:
java latest
Browser version:
n/a
Original install method (e.g. download page, yum, deb, from source, etc.) and version:
docker
Fresh install or upgraded from other version?
fresh

Hi and welcome to the forum :slight_smile:

There is a way to ignore specific classes, but it requires you to identify the class name patterns of what you want to include/exclude anyway, so you might as well use the trace_methods config option with more specific/narrowed-down patterns and not a very general root package. Note that limiting the number of classes/methods being traced is highly recommended in any case, as it may increase overhead significantly without necessarily providing a lot more value. If you can find the narrowest-informative context for tracing, you would get the best value of this. Typically, this feature is best used for tracing specific methods.

What changed in debugging? The stack in the screenshot doesn't seem to be related to the agent.

Not sure, I will need the full context for that. What is the exact breakpoint related to this screenshot? If it's a static method, or a constructor, for example, this would not be available. Does it behave differently on the same breakpoint with and without the agent?

Thanks,
Eyal.

@maxant which version are you using? Also, please send your trace_methods configuration and any other tracing-related configuration you are using.
Thanks.

I do the CDI tracing over an interceptor with custom spans.

   @AroundInvoke
public Object call(InvocationContext context) throws Throwable {
    // TODO:  Enable over System property
    Method method = context.getMethod();
    String className = context.getMethod().getDeclaringClass().getCanonicalName();
    String methodName = method.getName();


    boolean isInTransaction = ElasticApmUtils.isInTransaction();
    final Transaction transaction = ElasticApmUtils.apmTransactionCdiContext(className, methodName);

    log.debug(className + "#" + methodName + " isInTransaction " + isInTransaction);
   // TODO vuru 29.04.2019: Make abstraction
    if (isInTransaction) {
        boolean errorOccured = false;
        final Span span = transaction
                .startSpan("Cdi-Nested", className, methodName)
                .setName(className + "#" + methodName);
        try (Scope scope = span.activate()){
            final Object proceed = context.proceed();
            return proceed;
        } catch (Exception e) {
            span.captureException(e);
            errorOccured = true;
            throw e;
        } finally {
            span.end();
            if(errorOccured ){
                transaction.setResult("Failed");
            } else {
                transaction.setResult("Ok");
            }
        }
    } else {
        boolean errorOccured = false;
        try (Scope scope = transaction.activate()) {
            final Object proceed = context.proceed();
            return proceed;
        } catch (Exception e) {
            transaction.captureException(e);
            errorOccured = true;
            throw e;
        } finally {
            transaction.end();
            if(errorOccured ){
                transaction.setResult("Failed");
            } else {
                transaction.setResult("Ok");
            }
        }
    }
}

You can use this as a prototype and filter out what ever you want

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.