View Javadoc
1   package dev.sympho.modular_commands.execute;
2   
3   import org.checkerframework.dataflow.qual.Pure;
4   import org.checkerframework.dataflow.qual.SideEffectFree;
5   
6   import dev.sympho.modular_commands.api.command.context.CommandContext;
7   import reactor.core.publisher.Mono;
8   
9   /**
10   * A command context that is instrumented for use with metrics and tracing tooling.
11   *
12   * @version 1.0
13   * @since 1.0
14   * @apiNote If also implementing {@link LazyContext}, this API should be available before any 
15   *          methods are called.
16   */
17  public interface InstrumentedContext extends CommandContext {
18  
19      /**
20       * Retrieves the ID of the invoked command.
21       *
22       * @return The command ID.
23       */
24      @Pure
25      String getCommandId();
26  
27      /**
28       * Determines the value for the {@link Metrics.Tag.Type type tag}.
29       *
30       * @return The tag.
31       */
32      @Pure
33      Metrics.Tag.Type tagType();
34  
35      /**
36       * Adds the common instrumentation tags for this context to a Mono.
37       *
38       * @param <T> The mono value type.
39       * @param mono The mono to add tags to.
40       * @return The mono with tags added.
41       */
42      @SideEffectFree
43      default <T> Mono<T> addTags( final Mono<T> mono ) {
44  
45          return mono
46                  .transform( tagType()::apply )
47                  .transform( Metrics.Tag.CommandId.from( getCommandId() )::apply );
48  
49      }
50      
51  }