Skip to content

peetzen/dropwizard-metrics-tagging

Repository files navigation

Tagging support for Dropwizard Metrics

CircleCI Maven Central License

The Metrics project from Dropwizard does not natively support tags in version v4.x. However, tags can be encoded as part of the metric name. This library offers a MetricName class for creating metric names and converting tagged metric names to the legacy format.

Documentation

This library adds support for creating metric names with tags.

The MetricName class is based on the code for Dropwizard metrics (v5.x) and adds methods for converting to the legacy metric name format. In addition, it contains support for dealing with tags from the MetricTaggingContext ThreadLocal context.

Getting started

The artifacts including source and binaries are available on the central Maven repositories.

For maven:

<dependency>
  <groupId>de.peetzen.dropwizard.metrics</groupId>
  <artifactId>metrics-tagging</artifactId>
  <version>1.0.1</version>
</dependency>

For gradle:

implementation group: 'de.peetzen.dropwizard.metrics', name: 'metrics-tagging', version: '1.0.1'

Fully compatible with Dropwizard Metrics version v4.x.

Usage

Create a metric name with a single explicit tag.

    String name = MetricName.build("my","metric").tagged("tenant", "tenant-id").toLegacyFormat();
    assert name.equals("my.metric[tenant:tenant-id]");

Create a metric name with a single tag fetched from the MetricTaggingContext context.

    MetricName metricName = MetricName.build("my","metric");
    MetricTaggingContext.put("tenant", "tenant-id")

    String name = metricName.taggedUsingContext().toLegacyFormat();
    assert name.equals("my.metric[tenant:tenant-id]");

About

Support for Dropwizard metric names with encoded tags

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages