You can use Application Real-Time Monitoring Service (ARMS) SDKs to dynamically obtain the TraceId and its properties in the service code.
An application monitoring job is created in the ARMS console, and the ARMS agent has been installed and started in the Java program for monitoring. For more information about how to install the ARMS agent for Java applications, see Install the ARMS agent for Java applications.
Arms-sdk-1.7.1.jar is introduced to the program.
<dependency> <groupId>com.alibaba.arms.apm</groupId> <artifactId>arms-sdk</artifactId> <version>1.7.1</version> </dependency>Note If you cannot retrieve the pom.xml file, download arms-sdk-1.7.1.jar.
Retrieve TraceId and RpcId
After the preceding prerequisites are met, run the following code to retrieve the TraceId and RpcId:
Span span = Tracer.builder().getSpan(); String traceId = span.getTraceId(); String rpcId = span.getRpcId();
Pass through the service baggage
To pass through a service baggage, write procedures for adding and retrieving the service baggage into the code.
Add a service baggage to the service code.
Map<String, String> baggage = new HashMap<String, String>(); baggage.put("key-01", "value-01"); baggage.put("key-02", "value-02"); baggage.put("key-03", "value-03"); Span span = Tracer.builder().getSpan(); span.withBaggage(baggage);
Retrieve the service baggage from the service code.
Span span = Tracer.builder().getSpan(); Map<String, String> baggage = span.baggageItems();