Skip to content

Missing the Agent-Class manifest attribute  #1680

@MelleD

Description

@MelleD

Expected behavior

The manifest is valid. Missing the Agent-Class manifest attribute.

Actual behavior

Missing the Agent-Class manifest attribute

We don't start the agent via program arguments, but directly in the code, e.g. with ByteBuddy or via a JavaVirtual machine.
Unfortunately the agent attribute is missing for this reason the agent can no longer be loaded.

To Reproduce

Steps to reproduce the behavior:

Sample Application

Example

/**
 * Dynamic agent loader
 */
public class ByteBuddyAgentLoader {

   private final Class<?> agentClass;
   private final String tempFileName;

   public ByteBuddyAgentLoader( final Class<?> agentClass ) {
      this( agentClass, "agent.jar" );
   }

   public ByteBuddyAgentLoader( final Class<?> agentClass, final String tempFileName ) {
      this.agentClass = agentClass;
      this.tempFileName = tempFileName;
   }

   public void attachApplicationInsightsApmAgent() {
      final long pid = ProcessHandle.current().pid();
      final File agentJarFile = getAgentJarFile();
      ByteBuddyAgent.attach( agentJarFile, "" + pid );
   }

   private File getAgentJarFile() {
      final URL url = agentClass.getProtectionDomain().getCodeSource().getLocation();
      final File tempFile = new File(
            System.getProperty( "java.io.tmpdir" ) + File.separator + tempFileName );
      try {
         FileUtils.copyURLToFile( url, tempFile );
         return tempFile;
      } catch ( final IOException e ) {
         throw new IllegalStateException( "Agent is not available ", e );
      }
   }
}
@SpringBootApplication
public class Application{

   public static void main( final String[] args ) {
         startWithAgent( args );
   }

   private static void startWithAgent( final String[] args ) {
      final ByteBuddyAgentLoader byteBuddyAgentLoader = new ByteBuddyAgentLoader( OpenTelemetryAgent.class );
      byteBuddyAgentLoader.attachApplicationInsightsApmAgent();
      SpringApplication.run( Application.class, args );
   }
}

If applicable, provide a sample application which reproduces the issue.

System information

Works with version 3.0.2 , but not with 3.0.3 and 3.1.0

Logs

Failed to find Agent-Class manifest attribute from C:\Users\xyz\AppData\Local\Temp\agent.jar
Exception in thread "main" java.lang.IllegalStateException: Could not self-attach to current VM using external process
	at net.bytebuddy.agent.ByteBuddyAgent.installExternal(ByteBuddyAgent.java:675)
	at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:606)
	at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:273)
	at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:238)
	at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:220)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions