Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes around MeterProviderSdk, resolving pending comments. #2474

Merged
merged 2 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/OpenTelemetry/Metrics/MeterProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ internal MeterProviderSdk(
{
if (!shouldListenTo(instrument))
{
OpenTelemetrySdkEventSource.Log.MetricInstrumentIgnored(instrument.Name, instrument.Meter.Name, "Instrument belongs to a Meter not subscribed by the provider.", "Use AddMeter to add the Meter to the provider.");
return;
}

Expand Down
15 changes: 14 additions & 1 deletion test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,17 @@ public void MeterSourcesWildcardSupportMatchTest(bool hasView)
[Theory]
[InlineData(true)]
[InlineData(false)]
public void MeterSourcesWildcardSupportWithoutAddingMeterToProvider(bool hasView)
public void MeterSourcesWildcardSupportNegativeTestNoMeterAdded(bool hasView)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are no Meters added, then I think the SDK should throw. (This is not yet done, so this test is currently validating the current behavior)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
var meterNames = new[]
{
"AbcCompany.XyzProduct.ComponentA",
"abcCompany.xYzProduct.componentC",
};

using var meter1 = new Meter(meterNames[0]);
using var meter2 = new Meter(meterNames[1]);

var exportedItems = new List<Metric>();
var meterProviderBuilder = Sdk.CreateMeterProviderBuilder()
.AddInMemoryExporter(exportedItems);
Expand All @@ -244,6 +253,10 @@ public void MeterSourcesWildcardSupportWithoutAddingMeterToProvider(bool hasView

using var meterProvider = meterProviderBuilder.Build();
var measurement = new Measurement<int>(100, new("name", "apple"), new("color", "red"));

meter1.CreateObservableGauge("myGauge1", () => measurement);
meter2.CreateObservableGauge("myGauge2", () => measurement);

meterProvider.ForceFlush(MaxTimeToAllowForFlush);
Assert.True(exportedItems.Count == 0);
}
Expand Down