Annotation Type ServiceName


@Retention(RUNTIME)
@Target({TYPE,METHOD})
public @interface ServiceName
Annotation for service name that is often used as a meter tag or distributed trace's span name. By default, an annotated service uses its class name as its service name. You can override it by annotating a class or method with ServiceName like the following:

 > public class MyService {
 >     @Get("/")
 >     public String get(ServiceRequestContext ctx) {
 >         // The default service name
 >         assert ctx.log().ensureAvailable(RequestLogProperty.NAME)
 >                   .serviceName().equals(MyService.class.getName());
 >     }
 > }

 > // Override the default service name by the class annotation
 > @ServiceName("my-service")
 > public class MyService {
 >     @Get("/")
 >     public String get(ServiceRequestContext ctx) {
 >         assert ctx.log().ensureAvailable(RequestLogProperty.NAME)
 >                   .serviceName().equals("my-service");
 >     }

 >     // Override the default service name by the method annotation
 >     @ServiceName("my-post-service")
 >     @Post("/")
 >     public String post(ServiceRequestContext ctx) {
 >         assert ctx.log().ensureAvailable(RequestLogProperty.NAME)
 >                   .serviceName().equals("my-post-service");
 >     }
 > }
 
  • Required Element Summary

    Required Elements 
    Modifier and Type Required Element Description
    String value
    A service name for the annotated service.
  • Element Details

    • value

      String value
      A service name for the annotated service.