How to instrument jetty plugin from maven with open telemetry?

I am experimenting with adding open-telemetry to my Java projects.

I have a project where I have an API based on swagger-ui as a jersey-based servlet.

I normally run this using the jetty-maven plugin as a war:

 <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>${jetty-maven-plugin.version}</version> <configuration> <webApp> <war>${project.build.directory}/main-api.war</war> </webApp> <scan>1</scan> <contextHandlers> <contextHandler implementation="org.eclipse.jetty.server.handler.ContextHandler"> <contextPath>/swagger-ui</contextPath> <resourceBase>${project.build.directory}/${project.build.finalName}/swagger-ui </resourceBase> <handler implementation="org.eclipse.jetty.server.handler.ResourceHandler"/> </contextHandler> </contextHandlers> </configuration> </plugin>

How can I add the opentelemetry-java-instrumentation as java-agent to this proces?

1 Answer

Try something like this:

<project> ... <properties> <opentelemetry.version>1.24.0</opentelemetry.version> </properties> <build> <plugins> <plugin> <artifactId>maven-dependency-plugin</artifactId> <version>3.5.0</version> <executions> <execution> <id>download-opentelemetry-javaagent</id> <phase>process-resources</phase> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>io.opentelemetry.javaagent</groupId> <artifactId>opentelemetry-javaagent</artifactId> <version>${opentelemetry.version}</version> <destFileName>opentelemetry-javaagent.jar</destFileName> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> ... <configuration> ... <jvmArgs> <jvmArg>-javaagent:${project.build.directory}/opentelemetry-javaagent.jar</jvmArg> </jvmArgs> </configuration> </plugin> </plugins> </build>
</project>

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like