open-telemetry / opentelemetry-java-instrumentation

OpenTelemetry auto-instrumentation and instrumentation libraries for Java
https://opentelemetry.io
Apache License 2.0
1.96k stars 859 forks source link

Does't compatible with JFinal framework #11465

Open pepeshore opened 5 months ago

pepeshore commented 5 months ago

Describe the bug

JFinal is a Web and ORM framework。 when I add VM option -javaagent:opentelemetry-javaagent.jar, all HTTP requests result in a 500 error.

Steps to reproduce

1.git clone https://github.com/pepeshore/jfinal-demo this is a simple jfinal demo

  1. Open this project with IDEA(may be eclipse works too )
  2. Run jfinal.MyApp#main with VM options VM option -javaagent:opentelemetry-javaagent.jar added
  3. Exec command curl -v http://127.0.0.1:8082/jfinal/hello

Expected behavior

http status code is 200

Actual behavior

http status code is 500

Javaagent or library instrumentation version

2.4

Environment

JDK: openjdk version "1.8.0_322" OpenJDK Runtime Environment (Zulu 8.60.0.21-CA-macos-aarch64) (build 1.8.0_322-b06) OpenJDK 64-Bit Server VM (Zulu 8.60.0.21-CA-macos-aarch64) (build 25.322-b06, mixed mode) OS: mac

Additional context

No response

pepeshore commented 5 months ago

It seems to be that JFinal will put all the attributes of a request into map, and then use FastJson to serialize the map. shown as below image

And in tomcat instrumentation, two key named io.opentelemetry.javaagent.instrumentation.servlet.ServletHelper.AsyncListenerResponse and io.opentelemetry.javaagent.instrumentation.servlet.ServletHelper.Context will be added into a request, which are not serializable, and will throw exceptioon when serialize them. the exception stack is shown below com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.69, class org.apache.catalina.connector.Response, fieldName : io.opentelemetry.javaagent.instrumentation.servlet.ServletHelper.AsyncListenerResponse, write javaBean error, fastjson version 1.2.69, class org.apache.catalina.core.StandardContext, fieldName : context, write javaBean error, fastjson version 1.2.69, class org.apache.catalina.session.StandardManager, fieldName : manager, write javaBean error, fastjson version 1.2.69, class org.apache.catalina.core.StandardEngine, fieldName : engine, Cannot generate an absolute name for this namespace at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:539) at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:149) at com.alibaba.fastjson.serializer.MapSerializer.write(MapSerializer.java:271) at com.alibaba.fastjson.serializer.MapSerializer.write(MapSerializer.java:44) at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:285) at com.alibaba.fastjson.JSON.toJSONString(JSON.java:758) at com.alibaba.fastjson.JSON.toJSONStringWithDateFormat(JSON.java:688) at com.jfinal.json.FastJson.toJson(FastJson.java:44) at com.jfinal.kit.JsonKit.toJson(JsonKit.java:28) at com.jfinal.render.JsonRender.buildJsonText(JsonRender.java:168) at com.jfinal.render.JsonRender.render(JsonRender.java:130) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:106) at hm.platform.handler.SessionIdHandler.handle(SessionIdHandler.java:21) at hm.common.base.ContextPathHandler.handle(ContextPathHandler.java:13) at com.jfinal.ext.handler.UrlSkipHandler.handle(UrlSkipHandler.java:46) at com.jfinal.ext.handler.UrlSkipHandler.handle(UrlSkipHandler.java:46) at com.jfinal.ext.handler.UrlSkipHandler.handle(UrlSkipHandler.java:46) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:86) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:698) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:366) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:639) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:881) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1647) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:750)

laurit commented 5 months ago

We use request attributes to associate some of our own state with the request. You can work around this by excluding these attributes

JsonRender.addExcludedAttrs(
  "io.opentelemetry.javaagent.instrumentation.servlet.ServletHelper.AsyncListenerResponse",
  "io.opentelemetry.javaagent.instrumentation.servlet.ServletHelper.Context",
  "trace_id",
  "span_id");
pepeshore commented 5 months ago

It works. And do we has plan to support jfinal? auto excluded attrs above and get http.route

laurit commented 5 months ago

It works. And do we has plan to support jfinal? auto excluded attrs above and get http.route

We'd welcome a contribution for this

pepeshore commented 5 months ago

ok, you can assign this issue to me

breedx-splk commented 3 months ago

@pepeshore any updates on this? Thanks!

pepeshore commented 1 month ago

@pepeshore any updates on this? Thanks!

not yet, too busy lately