Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Sample for a test verifying published metrics in unit tests

Open
#289 2 comments 0 reactions 1 assignee View on GitHub

@tsurdilo is already working on this.

Since May 9, 2022.

Assessment

This issue has not been assessed yet.

Description

enhancement

Temporal should provide a sample for users on how they may check the metrics in unit tests.
I propose to wire MetricsScope with our standard MicrometerClientStatsReporter initialized with SimpleMeterRegistry micrometer.
A little bit like micrometer does in one of their tests:
https://www.programcreek.com/java-api-examples/?code=micrometer-metrics%2Fmicrometer%2Fmicrometer-master%2Fmicrometer-test%2Fsrc%2Fmain%2Fjava%2Fio%2Fmicrometer%2Fcore%2Ftck%2FTimerTest.java

        MeterRegistry registry = new SimpleMeterRegistry();

        try (Timer.ResourceSample sample = Timer.resource(registry, "requests")
                .description("This is an operation")
                .publishPercentileHistogram()) {
            try {
                if (outcome.equals("error")) {
                    throw new IllegalArgumentException("boom");
                }
                sample.tag("outcome", "success");
            } catch (Throwable t) {
                sample.tag("outcome", "error");
            }
        }

        assertThat(registry.get("requests").tag("outcome", outcome).timer().count())
                .isEqualTo(1);
Dominant language
Java
Stars
258
Forks
189
Avg merge
6d 4h
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from temporalio/samples-java

All issues in temporalio/samples-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.