Skip to content

counter/histogram with enabledExemplars=true, the labels() function does not bind the input parameters properly #777

Closed as duplicate
1 of 1 issue completed

Description

@jdmarshall
				const counterInstance = new Counter({
					name: 'counter_exemplar_label_test',
					help: 'help',
					labelNames: ['method', 'code'],
					enableExemplars: true,
				});

				const labels = counterInstance.labels({ method: 'get', code: '200' });

				labels.inc({}); // 1
				labels.inc({
					exemplarLabels: { traceId: 'trace_id_test', spanId: 'span_id_test' },
				});

There's a performance issue here since labels() should be able to validate the label values and then not repeat them. Likely what needs to happen is the two paths need to be unwound or converted into a set of file scoped functions that result in the correct output, sort of like how observe() does. That would both address the issue here and provide an incentive to use the labels() function to reduce overhead per call.

This code is exactly duplicated into Histogram and has the exact same bug.

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added this to the v1 milestone on Jul 13, 2026
  2. changed the title [-]For a counter with enabledExemplars=true, the `labels` function does not work properly[/-] [+]For a counter/histogram with enabledExemplars=true, the `labels` function does not work properly[/+] on Jul 13, 2026
  3. self-assigned this
    on Jul 13, 2026
  4. jdmarshall commented on Jul 13, 2026

    @jdmarshall
    ContributorAuthor

    I believe the right way to solve this is to modify labels() to skip over revalidation of inputs for those that cannot change rather than using bind the way it is at the moment.

    Those changes should also result in the internals of observe() and inc being homogenized so that side-by-side comparison of the files shows the way that histogram exemplars and counter exemplars are identical or different. So that any subsequent additions to this code are easier to reason about.

    For these reasons I'm putting myself as the assignee.

  5. added theissue type on Jul 13, 2026
  6. changed the title [-]For a counter/histogram with enabledExemplars=true, the `labels` function does not work properly[/-] [+]counter/histogram with enabledExemplars=true, the `labels` function does not bind the input parameters properly[/+] on Jul 13, 2026
  7. changed the title [-]counter/histogram with enabledExemplars=true, the `labels` function does not bind the input parameters properly[/-] [+]counter/histogram with enabledExemplars=true, the `labels()` function does not bind the input parameters properly[/+] on Jul 13, 2026
  8. jdmarshall commented on Jul 13, 2026

    @jdmarshall
    ContributorAuthor

    I'm not planning to implement #407, but I might be able to make it less difficult for someone else to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions