All Products
Search
Document Center

Microservices Engine:Query the canary tag of requests by using OpenTelemetry SDK for Java

Last Updated:Aug 15, 2024

The underlying logic of the end-to-end canary release feature provided by Microservices Engine (MSE) is to use Application Real-Time Monitoring Service (ARMS) to perform pass-through of traffic tags. This topic describes how to obtain the current canary tag of requests from the context.

Add dependencies

Add dependencies related to OpenTelemetry to the pom.xml file.

<dependencies>
    <dependency>
    <groupId>io.opentelemetry</groupId>
    <artifactId>opentelemetry-api</artifactId>
    </dependency>
    <dependency>
    <groupId>io.opentelemetry</groupId>
    <artifactId>opentelemetry-sdk-trace</artifactId>
    </dependency>
    <dependency>
    <groupId>io.opentelemetry</groupId>
    <artifactId>opentelemetry-sdk</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-bom</artifactId>
      <version>1.23.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

Use code

Use the following code:

String tagValue = Baggage.current().getEntryValue("__microservice_tag__");
Note
  • The tagValue is in the JSON format. Example: [{"name":"gray","tag":"gray","priority":-1}]. In this example, name is gray. This indicates that the current context belongs to the requests that have the gray tag.

  • To implement this feature, you must make sure that the version of the MSE agent is 4.0 or later.