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

How can I get transactionId in springboot application, not in log #7742

Open
ighack opened this issue Mar 16, 2021 · 11 comments
Open

How can I get transactionId in springboot application, not in log #7742

ighack opened this issue Mar 16, 2021 · 11 comments

Comments

@ighack
Copy link

ighack commented Mar 16, 2021

How can I get transactionId in springboot application, like skywalking

import org.apache.skywalking.apm.toolkit.trace.TraceContext;

   @ResponseBody
    @PostMapping("/Hello")
    public FdMessageVO Hello(@RequestBody Map<String,String> param) throws IOException {
        String traceid = TraceContext.traceId();
       // insert into mysql
        return  fdMessageVo;
    }

I want to insert transactionId to mysql

@yjqg6666
Copy link
Contributor

@ighack This PR #6801 might be what you want.

@emeroad
Copy link
Member

emeroad commented Mar 19, 2021

Maybe you need the SDK.

SDK PR is currently under development, but transactionId export feature is not included.
#7654

@yjqg6666
The design pattern of SDK PR seems like a very good idea.
A similar pattern seems to be possible with transactionid export.
What do you think?

@yjqg6666
Copy link
Contributor

yjqg6666 commented Mar 19, 2021

@emeroad If possible, i would prefer to migrate this feature into the official SDK. It wouldn't be hard. IMHO, the official SDK should have minimal dependency to avoid dependency conflicts and no dependency on pinpoint other modules should be recommended.

@yjqg6666
Copy link
Contributor

It would be so much better to get the transaction info from a stable api.

@ljgstudy
Copy link

When will the SDK be released?

@yjqg6666
Copy link
Contributor

yjqg6666 commented Sep 9, 2022

Working on the migration ( move application-interaction module in PR #6801 to agent-sdk). A new PR would be make in a few days later.

@yjqg6666
Copy link
Contributor

@ighack @ljgstudy @emeroad The feature is migrated to the PR #9175 branch. You could try it out.

@aalinyu
Copy link

aalinyu commented Sep 13, 2022

Class.forName is very performance consuming, cache the result maybe better?

@aalinyu
Copy link

aalinyu commented Sep 13, 2022

@yjqg6666 I have a question, why not use a plugin to enhancement the agent sdk to set the txid in, it may be more efficient

yjqg6666 added a commit to yjqg6666/pinpoint that referenced this issue Sep 13, 2022
@yjqg6666
Copy link
Contributor

yjqg6666 commented Sep 13, 2022

Class.forName is very performance consuming, cache the result maybe better?

@aalinyu Class.forName is called only 4 times per a HTTP request. According to this benchmarking, it may be not necessary.

@emeroad
Copy link
Member

emeroad commented Sep 29, 2022

Alternative

Non-invasive implementation that does not require SDK

The current implementation has a problem of high complexity across ClassLoader, ThreadLocal, and SDK.
Here are some ideas for this

  • ServletRequest.getAttribute() approach
public class Sample extends HttpServlet{

	protected void doGet(HttpServletRequest request, HttpServletResponse response) {
	       // This information is injected by the pinpoint interceptor
	        String transactionId = request.getAttribute("PINPOINT_TRANSACTIONID")
		Long spanId = request.getAttribute("PINPOINT_SPANID")
	}

}
  • Pros
    Simple implementation.
    Simple Object Lifecycle, Easy thread propagation. Most frameworks handle propagation of request automatically.
public class HttpServletRequestAdaptor implements RequestAdaptor<HttpServletRequest> {
     @Override
     public void setAttribute(HttpServletRequest request, String name, Object o) {
          request.setAttribute(name, o);
      }
}
  • Cons
    Some modules do not have setAttributes(). (grpc stream, reactive netty request....)
    Solution? : A module without setAttribute() does not implement the feature.

@emeroad emeroad closed this as completed Sep 29, 2022
@emeroad emeroad reopened this Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants