Skip to content

DefaultMeterFactory does not pass MeterOptions future properties to Meter constructor #97941

@KalleOlaviNiemitalo

Description

@KalleOlaviNiemitalo

Description

If more properties are added to System.Diagnostics.Metrics.MeterOptions in the future, then Microsoft.Extensions.Diagnostics.Metrics.DefaultMeterFactory should pass them too to the System.Diagnostics.Metrics.Meter constructor. However, the DefaultMeterFactory implementation in .NET 8.0.1 passes only those properties that it knows about: Name, Version, Tags, and a fixed Scope.

This was noted in #86740 (comment), and the implementation was then changed, but the change did not fix it. The code in .NET 8.0.1 is:

object? scope = options.Scope;
options.Scope = this;
FactoryMeter m = new FactoryMeter(options.Name, options.Version, options.Tags, scope: this);
options.Scope = scope;

It changes and restores MeterOptions.Scope but does not pass the MeterOptions reference to the FactoryMeter constructor. Thus:

  • Nothing reads the temporary value from MeterOptions.Scope, i.e. the assignments are pointless.
  • If a future version of .NET has extra properties in MeterOptions, then DefaultMeterFactory won't pass them to FactoryMeter, and FactoryMeter won't pass them to Meter, which will instead use default values.

Reproduction Steps

Cannot be reproduced before more properties are added to MeterOptions.

Expected behavior

DefaultMeterFactory should pass through the MeterOptions reference all the way to Meter.

Actual behavior

DefaultMeterFactory passes through only the known properties of MeterOptions to Meter.

Regression?

Not a regression.

Known Workarounds

Register a custom IMeterFactory implementation in the dependency injection container.

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions