Metrics { public static String addTagsToMetricName(String name, Map<String, String> tags) { if (tags == null || tags.size() == 0) { return name; } StringBuilder sb = new StringBuilder(); sb.append(name); SortedMap<String, String> sortedTags = new TreeMap<String, String>(tags); for (Map.Entry<String, String> entry: sortedTags.entrySet()) { sb.append("."); sb.append(entry.getKey()); sb.append("="); sb.append(entry.getValue()); } return sb.toString(); } Metrics(MetricsFactory factory);  Metrics(MetricsFactory factory, String metricsPrefix); static String addTagsToMetricName(String name, Map<String, String> tags); @Metric(
        name = "traces",
        tags = {
              @Tag(key = "state", value = "started"),
              @Tag(key = "sampled", value = "y"),
        }
  )
  // Number of traces started by this tracer as sampled
  public Counter traceStartedSampled; @Metric(
        name = "traces",
        tags = {
              @Tag(key = "state", value = "started"),
              @Tag(key = "sampled", value = "n"),
        }
  )
  // Number of traces started by this tracer as not sampled
  public Counter traceStartedNotSampled; @Metric(
        name = "traces",
        tags = {
              @Tag(key = "state", value = "joined"),
              @Tag(key = "sampled", value = "y"),
        }
  )
  // Number of externally started sampled traces this tracer joined
  public Counter tracesJoinedSampled; @Metric(
        name = "traces",
        tags = {
              @Tag(key = "state", value = "joined"),
              @Tag(key = "sampled", value = "n"),
        }
  )
  // Number of externally started not-sampled traces this tracer joined
  public Counter tracesJoinedNotSampled; @Metric(name = "started_spans", tags = @Tag(key = "sampled", value = "y"))
  // Number of sampled spans started by this tracer
  public Counter spansStartedSampled; @Metric(name = "started_spans", tags = @Tag(key = "sampled", value = "n"))
  // Number of unsampled spans started by this tracer
  public Counter spansStartedNotSampled; @Metric(name = "finished_spans")
  // Number of spans finished by this tracer
  public Counter spansFinished; @Metric(name = "span_context_decoding_errors")
  // Number of errors decoding tracing context
  public Counter decodingErrors; @Metric(name = "reporter_spans", tags = @Tag(key = "result", value = "ok"))
  // Number of spans successfully reported
  public Counter reporterSuccess; @Metric(name = "reporter_spans", tags = @Tag(key = "result", value = "err"))
  // Number of spans not reported due to a Sender failure
  public Counter reporterFailure; @Metric(name = "reporter_spans", tags = @Tag(key = "result", value = "dropped"))
  // Number of spans dropped due to internal queue overflow
  public Counter reporterDropped; @Metric(name = "reporter_queue_length")
  // Current number of spans in the reporter queue
  public Gauge reporterQueueLength; @Metric(name = "sampler_queries", tags = @Tag(key = "result", value = "ok"))
  // Number of times the Sampler succeeded to retrieve sampling strategy
  public Counter samplerRetrieved; @Metric(name = "sampler_queries", tags = @Tag(key = "result", value = "err"))
  // Number of times the Sampler failed to retrieve sampling strategy
  public Counter samplerQueryFailure; @Metric(name = "sampler_updates", tags = @Tag(key = "result", value = "ok"))
  // Number of times the Sampler succeeded to retrieve and update sampling strategy
  public Counter samplerUpdated; @Metric(name = "sampler_updates", tags = @Tag(key = "result", value = "err"))
  // Number of times the Sampler failed to update sampling strategy
  public Counter samplerParsingFailure; @Metric(name = "baggage_updates", tags = @Tag(key = "result", value = "ok"))
  // Number of times baggage was successfully written or updated on spans.
  public Counter baggageUpdateSuccess; @Metric(name = "baggage_updates", tags = @Tag(key = "result", value = "err"))
  // Number of times baggage failed to write or update on spans
  public Counter baggageUpdateFailure; @Metric(name = "baggage_truncations")
  // Number of times baggage was truncated as per baggage restrictions
  public Counter baggageTruncate; @Metric(name = "baggage_restrictions_updates", tags = @Tag(key = "result", value = "ok"))
  // Number of times baggage restrictions were successfully updated.
  public Counter baggageRestrictionsUpdateSuccess; @Metric(name = "baggage_restrictions_updates", tags = @Tag(key = "result", value = "err"))
  // Number of times baggage restrictions failed to update.
  public Counter baggageRestrictionsUpdateFailure; }
@Test public void testAddTagsToMetricName() { Map<String, String> tags = new HashMap<>(); tags.put("foo", "bar"); assertEquals("thecounter.foo=bar", Metrics.addTagsToMetricName("thecounter", tags)); assertEquals("jaeger_tracer_thecounter.foo=bar", Metrics.addTagsToMetricName("jaeger_tracer_thecounter", tags)); }