Skip to content

Cannot restart metrics #4384

@vidommet

Description

@vidommet

Bug Report

List of all OpenTelemetry NuGet
packages
and version that you are
using (e.g. OpenTelemetry 1.0.2):

<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.4.0" />

Runtime version (e.g. net462, net48, netcoreapp3.1, net6.0 etc. You can
find this information from the *.csproj file):

net6.0

Symptom

Once a meter has been disposed, a new meter with the same name doesn't work anymore.

What is the expected behavior?

The new meter with the same name should produce metrics as expected

What is the actual behavior?

Once the first meter has been disposed, no new metrics will be reported for the same meter.

Reproduce

var MyMeterInner = new Meter("MyCompany.MyProduct.MyLibrary.Inner", "1.0");
using var meterProvider = Sdk.CreateMeterProviderBuilder()
    .AddMeter("MyCompany.MyProduct.*")
    .AddConsoleExporter((a, b) => b.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 1000)
    .Build();

MyMeterInner.CreateObservableGauge("testb", () => new Measurement<int>(new System.Random().Next(), new[] { new KeyValuePair<string, object?>("A", "a") }));

await Task.Delay(5000);
MyMeterInner.Dispose();
Console.WriteLine("Disposed");
// We will see Metrics until here

MyMeterInner = new("MyCompany.MyProduct.MyLibrary.Inner", "1.0");
MyMeterInner.CreateObservableGauge("testb", () => new Measurement<int>(new System.Random().Next(), new[] { new KeyValuePair<string, object?>("A", "a") }));

// No metrics here at all
await Task.Delay(5000);

Steps to repro

  1. Create a listener for a meter namespace and ConsoleExporter. 
  2. Create a meter and an observableguage
  3. Console Exporter works as expected
  4. Dispose the meter
  5. Console Exporter stops output
  6. Create a new meter with the same name as the original meter
  7. Create a new observableguage on the new meter
  8. Nothing in the console!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleIssues and pull requests which have been flagged for closing due to inactivitybugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions