示例#1
0
        public void Setup()
        {
            this.meter = new Meter(Utils.GetCurrentMethodName());

            var exportedItems = new List <Metric>();
            var reader        = new PeriodicExportingMetricReader(new InMemoryExporter <Metric>(exportedItems), 1000);

            reader.PreferredAggregationTemporality = this.AggregationTemporality;
            this.provider = Sdk.CreateMeterProviderBuilder()
                            .AddMeter(this.meter.Name) // All instruments from this meter are enabled.
                            .AddReader(reader)
                            .Build();

            this.counter = this.meter.CreateCounter <long>("counter");
        }
    internal static PeriodicExportingMetricReader CreatePeriodicExportingMetricReader(
        BaseExporter <Metric> exporter,
        MetricReaderOptions options,
        int defaultExportIntervalMilliseconds,
        int defaultExportTimeoutMilliseconds)
    {
        var exportInterval =
            options.PeriodicExportingMetricReaderOptions?.ExportIntervalMilliseconds
            ?? defaultExportIntervalMilliseconds;

        var exportTimeout =
            options.PeriodicExportingMetricReaderOptions?.ExportTimeoutMilliseconds
            ?? defaultExportTimeoutMilliseconds;

        var metricReader = new PeriodicExportingMetricReader(exporter, exportInterval, exportTimeout)
        {
            TemporalityPreference = options.TemporalityPreference,
        };

        return(metricReader);
    }