Annotation Interface EventTag


Field or method level annotation that marks a field or method providing the Tag for the Event. The member name will be used as the Tag.key() by default, except for Map values without an explicit key (see below).

For both fields and methods, the value is obtained by calling toString() on the field value or method return value. If the value (returned from toString() is null), no tag will be created. This means in the following example if a class contains the orderId field as below the created Tag will have key "orderId" and the value "Order:123".

 @EventTag OrderId orderId = new OrderId("123")

 record OrderId(String id) {
     @Override
     public String toString() {
         return "Order" + ":" + id;
     }
 }
 

Special handling is provided for Iterable and Map:

  • For Iterable values:
    • A separate tag is created for each non-null element in the iterable.
    • All tags use the same key (from annotation or member name).
    • The tag value is obtained by calling toString() on each element.
    • Example: @EventTag List<Integer> numbers = List.of(1, 2) creates tags: Tag("numbers", "1") and Tag("numbers", "2")
  • For Map values:
    • If no key is provided in the annotation:
      • Map keys are used as tag keys (member name is ignored).
      • Map values are used as tag values.
      • Example: @EventTag Map<String,String> map = Map.of("k1", "v1", "k2", "v2") creates tags: Tag("k1", "v1") and Tag("k2", "v2")
    • If a key is provided in the annotation:
      • The provided key is used for all tags (map keys are ignored)
      • A tag is created for each non-null value in the map
      • Example: @EventTag(key="custom") Map<String,String> map = Map.of("k1", "v1", "k2", "v2") creates tags: Tag("custom", "v1") and Tag("custom", "v2")

If placed on a method, that method must contain no parameters and returns non-void value.

This annotation is repeatable, allowing multiple tags to be created from the same field or method.

Since:
5.0.0
Author:
Mateusz Nowak
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The key of the Tag which will be assigned to the Event.
  • Element Details

    • key

      String key
      The key of the Tag which will be assigned to the Event. Optional. If left empty:
      • For Map values: map keys will be used as tag keys.
      • For all other values: the member name will be used (with "get" stripped for getter methods).
      Returns:
      The tag key.
      Default:
      ""