Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

链路 tag 新增 Response Body 信息 #73

Open
lrwh opened this issue Feb 29, 2024 · 4 comments
Open

链路 tag 新增 Response Body 信息 #73

lrwh opened this issue Feb 29, 2024 · 4 comments
Assignees

Comments

@lrwh
Copy link
Collaborator

lrwh commented Feb 29, 2024

response body 即请求响应体,java 一般都是通过流的方式进行获取的,有一定的风险性。body也比较复杂,目前需要支持context-type:json的body。并需要通过开关控制,key 为response_body

@lrwh lrwh self-assigned this Feb 29, 2024
lrwh pushed a commit that referenced this issue Mar 6, 2024
@lrwh
Copy link
Collaborator Author

lrwh commented Mar 6, 2024

开启参数:-Ddd.trace.response.body.enabled=true,默认为false.
由于获取 response body 对response造成破坏,所以 response body 的编码调整默认为utf-8,如需调整,则使用-Ddd.trace.response.body.encoding=utf-8

lrwh added a commit that referenced this issue Mar 6, 2024
链路 tag 新增 Response Body 信息 #73
@songlonqi-java
Copy link
Collaborator

观测云官方文档:https://docs.guance.com/integrations/ddtrace-ext-changelog/

关闭issue

@lrwh
Copy link
Collaborator Author

lrwh commented Sep 11, 2024

开启 Response Body 信息获取后,会导致在某些情况下服务 OOM,比如当response返回的是文件信息(流)时,会发生oom,需要寻找替代方法

@lrwh lrwh reopened this Sep 11, 2024
@songlonqi-java
Copy link
Collaborator

遇到的问题:

  1. getOutputStream 和 getwrite 不可以同时在一个请求中调用。
  2. 增加过滤器之后,数据会存在过滤器中,需要写回到客户端

代码分析:

// doFilter 之前可以处理请求
 ResponseWrapper wrapper = new ResponseWrapper(httpServletResponse);
 filterChain.doFilter(request, wrapper);
// doFilter 之后可以处理相应

由于wrapper拦截了服务响应和客户端之间的流传输,这里需要写回去,但是不知道服务端在写的时候用的是哪个方法。

按照 v1.30.6-guance tag里面的代码 如果遇到下载文件 浏览器收不到任何响应。

可能的解决办法:在wrapper中就判断该相应是json还是别的contentType,做出区分,同时 在服务端调用getOutputStream和 getwrite 标记。这样在filter中就可以知道是不是json数据,也知道哪个方法在调用。再将数据写回去。

songlonqi-java added a commit that referenced this issue Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants