liveBook · Manning

Resource tag

As explained in Spring in Action, Sixth Edition

A tag is a named key-value dimension attached to a metric for classification and filtering.

A resource tag is a named key-value dimension attached to a metric. It classifies measurements so you can filter a broad count into a useful subset, such as HTTP requests with status 404 or tacos containing flour tortillas. section 15.2.4 section 15.3.3

Use tags to refine metric queries:

  • Inspect available tag names and values on a metric such as http.server.requests. section 15.2.4
  • Filter with a tag=value request parameter, such as status:404. section 15.2.4
  • Combine tags, such as status:404 and uri:/**, to narrow the measurements further. section 15.2.4
  • Expect available tag values to shrink as filters remove nonmatching measurements. section 15.2.4

Counting tacos by ingredient

A custom metric can use ingredient as the tag name and an ingredient ID as its value. Each time a taco is created, the counter for every ingredient is incremented. Querying tacocloud?tag=ingredient:FLTO then reports the count for flour tortillas instead of the combined count for all ingredients. section 15.3.3

Listing 15.6 TacoMetrics registers metrics around taco ingredients
package tacos.actuator;
 
import java.util.List;
import org.springframework.data.rest.core.event.AbstractRepositoryEventListener;
import org.springframework.stereotype.Component;
import io.micrometer.core.instrument.MeterRegistry;
import tacos.Ingredient;
import tacos.Taco;
 
@Component
public class TacoMetrics extends AbstractRepositoryEventListener<Taco> {
  private MeterRegistry meterRegistry;
 
  public TacoMetrics(MeterRegistry meterRegistry) {
    this.meterRegistry = meterRegistry;
  }
 
  @Override
  protected void onAfterCreate(Taco taco) {
    List<Ingredient> ingredients = taco.getIngredients();
    for (Ingredient ingredient : ingredients) {
      meterRegistry.counter("tacocloud",
          "ingredient", ingredient.getId()).increment();
    }
  }
}

See the complete TacoMetrics implementation, including MeterRegistry injection, repository-event handling, and tagged counter creation. section 15.3.3

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains tag discovery, single and combined filters, and custom counter creation without detailing metric storage internals.
Examples
Demonstrates status and URI filters for HTTP requests and ingredient filters for taco counters.
What it assumes
Assumes familiarity with metrics and HTTP requests while demonstrating tag filtering and custom counter registration.
What you can do after
Apply tags via Actuator queries and register custom tagged counters with MeterRegistry.
How it connects
Connects resource tags with metrics, counters, MeterRegistry, HTTP requests, and repository events.

Also explained in

Compare how 6 books explain resource tag →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.