question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clarification needed on AgentBuilder.Transformer.ForAdvice::include()

See original GitHub issue

I’m trying to capture a call coming in through a servlet engine. Here’s my code:

    
    
    @Advice.OnMethodEnter
    public static void enter(final @Advice.AllArguments Object[] args) {
       GenericIngressHandler.enter(args[0], "getHeader");
    }

    @Advice.OnMethodExit
    public static void exit() {
        GenericIngressHandler.exit();
    }

    public static AgentBuilder buildAgent(AgentBuilder b) {
        return b.type(named("javax.servlet.http.HttpServlet"))
                .transform(
                        new AgentBuilder.Transformer.ForAdvice()
                            .include(ServletIngressHandler.class.getClassLoader())
                            .advice(new Matchers.WildcardMethodMatcher(
                        "service(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)"),
                                ServletIngressHandler.class.getName()));
        
    }
}

It fails when it’s trying to load the GenericIngressHandler when executed through the Open Liberty appserver. It seems that it has some custom classloader that doesn’t see my code.

So I added include(ServletIngressHandler.class.getClassLoader()) to the definition of the transformer thinking that it would somehow insert the classloader of my package into the mix. However, it still can’t see the class. Maybe I’m using include() wrong? Some clarification in the documentation would be great!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
raphwcommented, Dec 18, 2019

Any code referenced in your advice classes must be available to the class loader that is executing the advice. The include method only assures that Byte Buddy can see class files provided by class loaders while inlining the advice.

Normally, you add classes that you need to be universally visible to the bootstrap class loader. The Instrumentation interface provides a method for that.

0reactions
raphwcommented, Dec 19, 2019

Good to hear, checked your doc and this approach should also allow you avoid - Xbootclassloader.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Clarification on include a classloader - java - Stack Overflow
I am trying to create an Advice for sun.nio.ch.NioSocketImpl, which is in Platform classloader, using ForAdvice#include to be able to use my own ......
Read more >
AgentBuilder.Transformer (Byte Buddy (without ... - Javadoc.io
A transformer allows to apply modifications to a DynamicType . Such a modification is then applied to any instrumented type that was matched...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found