joe-elliott / tempo-springboot-example

23 stars 13 forks source link

download javaagent with maven #8

Open flecno opened 3 years ago

flecno commented 3 years ago

Nice blog post!

To auto-instrument the application, I simply need to reference a jar file I downloaded from the OTel repo. I spent some time trying to figure out how to pull the necessary libraries through maven, but did not have luck.

I have used the maven-download-plugin to fetch a custom build via http with this config:

<plugins>
    <plugin>
        <groupId>com.googlecode.maven-download-plugin</groupId>
        <artifactId>download-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
            <execution>
                <id>download-open-telemetry-agent</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>wget</goal>
                </goals>
                <configuration>
                    <url>
    https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.5.3/opentelemetry-javaagent-all.jar
                    </url>
  <sha256>xxx</sha256>
                    <outputDirectory>${opentelemetry.agent.location}</outputDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>
joe-elliott commented 3 years ago

Nice! If I find some time I will give this a shot.

marcellodesales commented 3 years ago

I tried adding it and it failed... I think this approach can break easily:

Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.1.0/plexus-utils-3.1.0.jar (262 kB at 82 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-compress/1.20/commons-compress-1.20.jar (632 kB at 191 kB/s)
#7 219.4 [INFO] Downloading: https://storage.googleapis.com/devtmp-666/opentelemetry-javaagent-all.jar
#7 219.4 [INFO] 133/133
#7 219.4 [INFO] downloaded 133
#7 219.5 [WARNING] Could not get content
#7 219.5 org.apache.maven.plugin.MojoFailureException: Not same digest as expected: expected <c4c635fdb54b4acf057a3a5b7088ab86bd4d52fee959e69daa186dea10f29d84> was <881aa5538ac02efb941f6cbef4e784f5e4a4a0c70611cc6b7e7e461f21c65f97>
#7 219.5     at com.googlecode.download.maven.plugin.internal.SignatureUtils.verifySignature (SignatureUtils.java:35)
#7 219.5     at com.googlecode.download.maven.plugin.internal.signature.Signatures.validate (Signatures.java:70)
#7 219.5     at com.googlecode.download.maven.plugin.internal.WGet.execute (WGet.java:398)
#7 219.5     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
#7 219.5     at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
#7 219.5     at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
#7 219.5     at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
#7 219.5     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
#7 219.5     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
#7 219.5     at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
#7 219.5     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
#7 219.5     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
#7 219.5     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
#7 219.5     at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
#7 219.5     at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
#7 219.5     at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
#7 219.5     at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
#7 219.5     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
#7 219.5     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
#7 219.5     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
#7 219.5     at java.lang.reflect.Method.invoke (Method.java:566)
#7 219.5     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
#7 219.5     at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
#7 219.5     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
#7 219.5     at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
#7 219.5 [WARNING] Retrying (1 more)
#7 219.7 [INFO] Downloading: https://storage.googleapis.com/devtmp-666/opentelemetry-javaagent-all.jar
#7 219.7 [INFO] 133/133
#7 219.7 [INFO] downloaded 133
#7 219.7 [WARNING] Could not get content
#7 219.7 org.apache.maven.plugin.MojoFailureException: Not same digest as expected: expected <c4c635fdb54b4acf057a3a5b7088ab86bd4d52fee959e69daa186dea10f29d84> was <881aa5538ac02efb941f6cbef4e784f5e4a4a0c70611cc6b7e7e461f21c65f97>
#7 219.7     at com.googlecode.download.maven.plugin.internal.SignatureUtils.verifySignature (SignatureUtils.java:35)
#7 219.7     at com.googlecode.download.maven.plugin.internal.signature.Signatures.validate (Signatures.java:70)
#7 219.7     at com.googlecode.download.maven.plugin.internal.WGet.execute (WGet.java:398)
#7 219.7     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
#7 219.7     at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
#7 219.7     at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
#7 219.7     at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
#7 219.7     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
#7 219.7     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
#7 219.7     at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
#7 219.7     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
#7 219.7     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
#7 219.7     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
#7 219.7     at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
#7 219.7     at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
#7 219.7     at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
#7 219.7     at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
#7 219.7     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
#7 219.7     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
#7 219.7     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
#7 219.7     at java.lang.reflect.Method.invoke (Method.java:566)
#7 219.7     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
#7 219.7     at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
#7 219.8     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
#7 219.8     at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
#7 219.8 [INFO] ------------------------------------------------------------------------
#7 219.8 [INFO] BUILD FAILURE
#7 219.8 [INFO] ------------------------------------------------------------------------
#7 219.8 [INFO] Total time:  03:36 min
#7 219.8 [INFO] Finished at: 2021-08-24T01:21:14Z
#7 219.8 [INFO] ------------------------------------------------------------------------
#7 219.8 [ERROR] Failed to execute goal com.googlecode.maven-download-plugin:download-maven-plugin:1.6.0:wget (download-open-telemetry-agent) on project TianMiao: IO Error: Could not get content -> [Help 1]
#7 219.8 [ERROR]
#7 219.8 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
#7 219.8 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
#7 219.8 [ERROR]
#7 219.8 [ERROR] For more information about the errors and possible solutions, please read the following articles:
#7 219.8 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
------
executor failed running [/bin/sh -c mvn clean install -Dmaven.test.skip=true]: exit code: 1
ERROR: Service 'tomcat' failed to build : Build failed
flecno commented 3 years ago

Oh sorry @marcellodesales. I used one of my internal GCS buckets in the example. You should use the Github releases from here https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases

marcellodesales commented 3 years ago

@flecno Thank you.. I will use my approach of building a Docker image with it and mounting it as an InitContainer and transfer to any Java application needed... That way, others don't need to embed the agent in their application directly.