Annotation 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
> ctx.log().whenAvailable(RequestLogProperty.NAME).thenAccept(log -> {
> assert log.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) {
> ctx.log().whenAvailable(RequestLogProperty.NAME).thenAccept(log -> {
> assert log.serviceName().equals("my-service");
> });
> }
> // Override the default service name by the method annotation
> @ServiceName("my-post-service")
> @Post("/")
> public String post(ServiceRequestContext ctx) {
> ctx.log().whenAvailable(RequestLogProperty.NAME).thenAccept(log -> {
> assert log.serviceName().equals("my-post-service");
> });
> }
> }
-
Required Element Summary
-
Element Details
-
value
String valueA service name for the annotated service.
-