I’m not seeing my Telemetry Metrics exported to the Console

I’m writing some proof-of-concept code, a prototype to get familiar with exporting metrics using the Open Telemetry libraries. I must have omitted one detail, because I see the initialization of my MeterProvider emitted to the console, but then I don’t see any metrics which I am accumulating.

I’m using this sample as a guide: https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/examples/Console/TestMetrics.cs

Here is my initialization code:

    public static MeterProvider GetMeterProvider(string service, string version, string meterName, bool consoleExporter, bool OtlpExporter)
    {
        MeterProviderBuilder mpb = Sdk.CreateMeterProviderBuilder()
            .ConfigureResource(r => r.AddService(service, null, version))
            .AddMeter(meterName); // All instruments from this meter are enabled.

        if (consoleExporter)
        {
            mpb.AddConsoleExporter((exporterOptions, metricReaderOptions) =>
            {
                exporterOptions.Targets = ConsoleExporterOutputTargets.Console;

                metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 1000;
                metricReaderOptions.TemporalityPreference = MetricReaderTemporalityPreference.Delta;
            });
        }

        if (OtlpExporter)
        {
           <...snipped...>
        }

        return mpb.Build();
    }

Here’s the function call. The return value, a MeterProvider, is assigned to a class member variable, to persist for the duration of the class instance. (In the code below, the prefix m_ designates a class member variable.)

m_meterProvider = TelemetryUtils.GetMeterProvider(c_Service, c_Version, "Prototype", true, false);

And here’s what I see:

After creating the MeterProvider, I create

        m_meter = new Meter("Telemetry", "8.1");
        m_counter = m_meter.CreateCounter<int>("counter", "things", "A count of things");
        m_histogram = m_meter.CreateHistogram<int>("histogram");

I think that this might be my issue. I’m creating a Meter but I don’t see how this is associated with the MeterProvider? In the sample code there is a statement:

   using var provider = providerBuilder.Build();

but I’m not sure what the function of this statement. In my code, the MeterProvider, which is the output of MeterProviderBuilder.Build() is the functional return of GetMeterProvider(); this is assigned to the class member variable m_meterProvider which persists for the duration of the class. Anyway, moving on…

Here are the measurement collection statements which execute inside of my processing loop. I even threw a ForceFlush statement in there. But no joy. I don’t see anything emitted to the console. What am I missing? Thanks for your advice!

        var observableCounter = m_meter.CreateObservableGauge("gauge", () =>
        {
            return new List<Measurement<int>>()
                {
                new Measurement<int>(
                    9999999,
                    new KeyValuePair<string, object>("tag1", "value1")),
                };
        });

        m_histogram?.Record(Counter);

        m_histogram?.Record(
            Counter * 100,
            new KeyValuePair<string, object>("tag1", "value1"));

        m_counter?.Add(Counter);

        m_counter?.Add(
            Counter * 100,
            new KeyValuePair<string, object>("tag2", "value2"));

        m_meterProvider.ForceFlush();

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật