I have maven Java Spring Application. I’m trying to implement otel java agent instrumentation to set span with custom attributes.
I have mentioned the below JVM args in Tomcat configuration
-javaagent:C:opentelemetry-javaagent.jar
-Dotel.javaagent.extensions=C:UsersThiru.m2repositorycomsemonitoringagent-extension24.03.00-SNAPSHOTagent-extension-24.03.00-SNAPSHOT.jar
-Dotel.service.name=se.main
-Dotel.traces.exporter=zipkin
-Dotel.logs.exporter=none
-Dotel.metrics.exporter=none
-Dotel.instrumentation.spring-scheduling.enabled=false
-Dotel.javaagent.debug=true
I have another library trace-core-1.22.4.jar
this library contains code to populate the ThreadLocal attributes. It is populated with attributes successfully (ThreadLocalTraceManager.java
).
In agent-extension-24.03.00-SNAPSHOT.jar
i have added otel agent instrumentation code, which contains 2 files
HttpUrlConnectionAgentExtensionModule.java
HttpUrlConnectionAgentExtension.java
Inside agent-extension-24.03.00-SNAPSHOT.jar
i want to set Span attributes from ThreadLocalTraceManager
.
I have added as dependency to trace-core and created fat jar, the library is present in the jar, but i’m getting java.lang.NoClassDefFoundError
[otel.javaagent 2024-06-07 16:24:36:318 +0530] [http-nio-8090-exec-1_7dd5fcd9-eb3d-4994-8144-c73ad0c360f3-TargetGroupB] DEBUG io.opentelemetry.javaagent.bootstrap.ExceptionLogger - Failed to handle exception in instrumentation for sun.net.www.protocol.http.HttpURLConnection
java.lang.NoClassDefFoundError: com/ssse/trace/impl/ThreadLocalTraceManager
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1299)
at org.apache.cxf.transport.http.URLConnectionHTTPConduit$URLConnectionWrappedOutputStream.setupWrappedStream(URLConnectionHTTPConduit.java:174)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleHeadersTrustCaching(HTTPConduit.java:1302)
Anyone guide me how to achieve this?