Skip to content

static labels on MetericsFactory not added #389

@cubakid

Description

@cubakid

Given the following code, I expect 3 different counters each with a value of 1. However, it appears that a single counter is increased 3 times.

using ConsoleApp1;
using Prometheus;

Console.WriteLine( "Hello, World!" );

Metrics.SuppressDefaultMetrics();

var metricServer = new KestrelMetricServer( port: 1234 );
metricServer.Start();

Metrics.DefaultRegistry.SetStaticLabels( new Dictionary<string, string>
	{
	  // Labels applied to all metrics in the registry.
	  { "DefaultRegistry", "testing" }
	}
);

var c1 = new Class1( "c1" );
var c2 = new Class1( "c2" );
var c3 = new Class1( "c3" );

Console.ReadKey();
using Prometheus;

namespace ConsoleApp1
{
	internal class Class1
	{
		private IMetricFactory MetricFactory { get; set; }

		private Counter c1 { get; set; }

		public Class1( string name )
		{
			// Labels applied to all metrics created via this factory.
			MetricFactory = Metrics.WithLabels( new Dictionary<string, string> { { "testname", name } } );

			c1 = MetricFactory.CreateCounter( "test", "test counter" );

			c1.Inc();
		}
	}
}

results

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions